aboutsummaryrefslogtreecommitdiff
path: root/test_utils/managers/gr/conftest.py
blob: 3e3a4adcde3fe7648532cfe37fe763b49a237e46 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from __future__ import annotations

from typing import Callable
from uuid import uuid4

import pytest
from pydantic import PositiveInt
from pydantic_extra_types.phone_numbers import PhoneNumber

from generalresearch.managers.gr.authentication import GRUserManager
from generalresearch.managers.gr.business import (
    BusinessAddressManager,
    BusinessBankAccountManager,
    BusinessManager,
)
from generalresearch.managers.gr.team import TeamManager
from generalresearch.models.custom_types import UUIDStr
from generalresearch.models.gr.authentication import GRUser
from generalresearch.models.gr.business import (
    Business,
    BusinessAddress,
    BusinessBankAccount,
    BusinessType,
    TransferMethod,
)
from generalresearch.models.gr.team import Team


@pytest.fixture
def gr_user_factory(gr_um: GRUserManager) -> Callable[..., GRUser]:

    def _inner(
        sub: str | None = None,
        is_superuser: bool = False,
    ) -> GRUser:
        sub = sub or f"{uuid4().hex}-{uuid4().hex}"

        return gr_um.create(
            sub=sub,
            is_superuser=is_superuser,
        )

    return _inner


@pytest.fixture
def gr_business_bank_account_factory(
    gr_bbam: BusinessBankAccountManager,
) -> Callable[..., BusinessBankAccount]:

    def _inner(
        business_id: PositiveInt,
        uuid: UUIDStr | None = None,
        transfer_method: TransferMethod | None = None,
        account_number: str | None = None,
        routing_number: str | None = None,
        iban: str | None = None,
        swift: str | None = None,
    ):
        from generalresearch.models.gr.business import TransferMethod

        return gr_bbam.create(
            business_id=business_id,
            uuid=uuid or uuid4().hex,
            transfer_method=transfer_method or TransferMethod.ACH,
            account_number=account_number or uuid4().hex[:6],
            routing_number=routing_number or uuid4().hex[:6],
            iban=iban or uuid4().hex[:6],
            swift=swift or uuid4().hex[:6],
        )

    return _inner


@pytest.fixture
def gr_business_address_factory(
    gr_bam: BusinessAddressManager,
) -> Callable[..., BusinessAddress]:

    def _inner(
        business_id: PositiveInt,
        uuid: UUIDStr | None = None,
        line_1: str | None = None,
        line_2: str | None = None,
        city: str | None = None,
        state: str | None = None,
        postal_code: str | None = None,
        phone_number: PhoneNumber | None = None,
        country: str | None = None,
    ):
        uuid = uuid or uuid4().hex
        line_1 = line_1 or "abc"
        line_2 = line_2 or "bczx"
        city = city or "Downingtown"
        state = state or "CA"
        postal_code = postal_code or "94041"
        phone_number = None
        country = country or "US"

        return gr_bam.create(
            business_id=business_id,
            uuid=uuid,
            line_1=line_1,
            line_2=line_2,
            city=city,
            state=state,
            postal_code=postal_code,
            phone_number=phone_number,
            country=country,
        )

    return _inner


@pytest.fixture
def gr_business_factory(
    gr_bm: BusinessManager,
) -> Callable[..., Business]:

    def _inner(
        uuid: UUIDStr | None = None,
        name: str | None = None,
        team: Team | None = None,
        kind: BusinessType | None = None,
        tax_number: str | None = None,
    ) -> Business:
        from random import randint

        uuid = uuid or uuid4().hex
        name = name or "< Unknown >"
        tax_number = tax_number or str(randint(1, 999_999_999))

        return gr_bm.create(
            uuid=uuid, name=name, team=team, kind=kind, tax_number=tax_number
        )

    return _inner


@pytest.fixture
def gr_team(
    gr_tm: TeamManager,
) -> Callable[..., Team]:

    def _inner(uuid: UUIDStr | None = None, name: str | None = None) -> Team:
        uuid = uuid or uuid4().hex
        name = name or f"name-{uuid4().hex[:12]}"

        return gr_tm.create(uuid=uuid, name=name)

    return _inner