44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from factory import alchemy, Sequence, RelatedFactory, LazyAttribute
|
|
from factory.faker import Faker
|
|
from factory.fuzzy import FuzzyInteger, FuzzyChoice
|
|
|
|
from .dependencies import db
|
|
from .students.models import Student, Group, ProjectSupervisor
|
|
|
|
|
|
class ProjectSupervisorFactory(alchemy.SQLAlchemyModelFactory):
|
|
class Meta:
|
|
model = ProjectSupervisor
|
|
sqlalchemy_session = db.session
|
|
|
|
first_name = Faker('first_name')
|
|
last_name = Faker('last_name')
|
|
email = Faker('email')
|
|
limit_group = 4 # FuzzyInteger(3, 5)
|
|
count_groups = 4
|
|
mode = FuzzyChoice([True, False])
|
|
|
|
|
|
class GroupFactory(alchemy.SQLAlchemyModelFactory):
|
|
class Meta:
|
|
model = Group
|
|
sqlalchemy_session = db.session
|
|
|
|
name = Sequence(lambda n: f'Group-{n}')
|
|
# project_supervisor = RelatedFactory(ProjectSupervisorFactory, 'project_supervisor')
|
|
|
|
|
|
class StudentFactory(alchemy.SQLAlchemyModelFactory):
|
|
class Meta:
|
|
model = Student
|
|
sqlalchemy_session = db.session
|
|
|
|
first_name = Faker('first_name')
|
|
last_name = Faker('last_name')
|
|
email = Faker('email')
|
|
index = Sequence(lambda n: 400_000 + n)
|
|
first_term = FuzzyInteger(1, 5)
|
|
second_term = FuzzyInteger(1, 5)
|
|
# group = RelatedFactory(GroupFactory)
|
|
mode = FuzzyChoice([True, False])
|