Coverage for modules/box__default/auth/tests/factories.py: 100%

# Coverage for modules/box__default/auth/tests/factories.py : 100%

## 24 statements

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1"""Factories to help in tests."""

2 from factory import Sequence

3 from factory.alchemy import SQLAlchemyModelFactory

4 from init import db

5 from modules.box__default.auth.models import Role

6 from modules.box__default.auth.models import User

7 from sqlalchemy.orm import scoped_session

8

9

10 class BaseFactory(SQLAlchemyModelFactory):

11 """Base factory."""

12

13 class Meta:

14 """Factory configuration."""

15

16 abstract = True

17 sqlalchemy_session = db.session

18 sqlalchemy_session = scoped_session(

19 lambda: db.session, scopefunc=lambda: db.session

20 )

21 sqlalchemy_session_persistence = "commit"

22

23

24 class UserFactory(BaseFactory):

25 """User factory."""

26

27 username = Sequence(lambda n: f"user{n}")

28 email = Sequence(lambda n: f"user{n}@example.com")

29 password = "pass"

30 is_email_confirmed = True

31 is_admin = False

32

33 class Meta:

34 """Factory configuration."""

35

36 model = User

37

38

39 class RoleFactory(BaseFactory):

40 """Role factory."""

41

42 name = Sequence(lambda n: f"role{n}")

43

44 class Meta:

45 """Factory configuration."""

46

47 model = Role