aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/users/tests/factories.py
blob: 53584b7324c83468a070793d10e6cecea2b593bf (plain) (blame)
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
56
57
from typing import Any, Sequence

from django.contrib.auth import get_user_model
from ctrack.organisations.models import Organisation, Address, AddressType
from factory import DjangoModelFactory, Faker, post_generation, SubFactory


class AddressTypeFactory(DjangoModelFactory):
    descriptor = "Primary Address"

    class Meta:
        model = AddressType


class OrganisationFactory(DjangoModelFactory):
    name = Faker("company", locale="en_GB")

    class Meta:
        model = Organisation


class AddressFactory(DjangoModelFactory):
    type = SubFactory(AddressTypeFactory)
    organisation = SubFactory(OrganisationFactory)
    line1 = Faker("secondary_address", locale="en_GB")
    line2 = Faker("street_name", locale="en_GB")
    line3 = Faker("secondary_address", locale="en_GB")
    city = Faker("city", locale="en_GB")
    county = Faker("lexify", locale="en_GB", text="??????", letters="aeioutzyj")
    postcode = Faker("postcode", locale="en_GB")
    country = Faker("country")
    other_details = Faker("lexify", locale="en_GB", text="??????", letters="aeioutzyj")

    class Meta:
        model = Address


class UserFactory(DjangoModelFactory):
    username = Faker("user_name")
    email = Faker("email")
    name = Faker("name")

    @post_generation
    def password(self, create: bool, extracted: Sequence[Any], **kwargs):
        password = Faker(
            "password",
            length=42,
            special_chars=True,
            digits=True,
            upper_case=True,
            lower_case=True,
        ).generate(extra_kwargs={})
        self.set_password(password)

    class Meta:
        model = get_user_model()
        django_get_or_create = ["username"]