-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfactories.py
More file actions
55 lines (39 loc) · 1.55 KB
/
factories.py
File metadata and controls
55 lines (39 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from datetime import timedelta
from django.contrib.auth.models import User
from django.utils import timezone
import factory.django
from oauth2_provider.models import AccessToken
from bats_ai.core.models import VettingDetails
class UserFactory(factory.django.DjangoModelFactory[User]):
class Meta:
model = User
username = factory.SelfAttribute('email')
email = factory.Faker('safe_email')
first_name = factory.Faker('first_name')
last_name = factory.Faker('last_name')
class SuperuserFactory(factory.django.DjangoModelFactory[User]):
class Meta:
model = User
django_get_or_create = ('email',)
username = factory.SelfAttribute('email')
email = factory.Faker('safe_email')
first_name = factory.Faker('first_name')
last_name = factory.Faker('last_name')
is_superuser = True
is_staff = True
@classmethod
def _create(cls, model_class, *args, **kwargs):
manager = cls._get_manager(model_class)
return manager.create_superuser(*args, **kwargs)
class VettingDetailsFactory(factory.django.DjangoModelFactory[VettingDetails]):
class Meta:
model = VettingDetails
user = factory.SubFactory(UserFactory)
reference_materials = factory.Faker('paragraph', nb_sentences=3)
class AccessTokenFactory(factory.django.DjangoModelFactory[AccessToken]):
class Meta:
model = AccessToken
user = factory.SubFactory(UserFactory)
token = factory.Faker('uuid4')
scope = 'read write'
expires = factory.LazyFunction(lambda: timezone.now() + timedelta(hours=1))