Skip to content
This repository was archived by the owner on Dec 19, 2021. It is now read-only.

Commit 0361c01

Browse files
authored
Update creat tenant factory (#409)
* create_tenant accepts a list of staff or a number
1 parent 0d294e7 commit 0361c01

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

tests/factory_fixtures/tenant.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ def _tenant_attributes(staff=None):
1818

1919

2020
@pytest.fixture
21-
def create_tenant(tenant_attributes):
22-
def _create_tenant():
21+
def create_tenant(tenant_attributes, create_join_staff):
22+
def _create_tenant(staff=None):
23+
if isinstance(staff, int):
24+
staff = [create_join_staff().id for _ in range(staff)]
25+
elif staff is None:
26+
staff = []
27+
2328
return TenantModel.create(
24-
schema=TenantSchema, payload=tenant_attributes(staff=[])
29+
schema=TenantSchema, payload=tenant_attributes(staff=staff)
2530
)
2631

2732
yield _create_tenant

tests/unit/test_tenant.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ class TestTenantModel:
1717
def test_json(self, create_tenant, create_lease):
1818
tenant = create_tenant()
1919
lease = create_lease(tenant=tenant)
20-
2120
assert tenant.json() == {
2221
"id": tenant.id,
2322
"firstName": tenant.firstName,
2423
"lastName": tenant.lastName,
2524
"fullName": "{} {}".format(tenant.firstName, tenant.lastName),
2625
"phone": tenant.phone,
27-
"staff": tenant.staff,
26+
"staff": tenant.staff.json(),
2827
"lease": lease.json(),
2928
"created_at": Time.format_date(tenant.created_at),
3029
"updated_at": Time.format_date(tenant.updated_at),
@@ -36,3 +35,13 @@ def test_json(self, create_tenant, create_lease):
3635
class TestTenantFactory:
3736
def test_create_tenant(self, create_tenant):
3837
assert create_tenant()
38+
39+
def test_create_tenant_with_staff_as_list(self, create_tenant, create_join_staff):
40+
staff = [create_join_staff().id for _ in range(3)]
41+
tenant = create_tenant(staff)
42+
assert [join_staff.id for join_staff in tenant.staff] == staff
43+
44+
def test_create_tenant_with_staff_as_int(self, create_tenant, create_join_staff):
45+
number_of_staff = 4
46+
tenant = create_tenant(number_of_staff)
47+
assert len(tenant.staff) == number_of_staff

0 commit comments

Comments
 (0)