@@ -23,12 +23,14 @@ def test_tenants_GET_one(client, test_database, auth_headers):
23
23
assert response .json == {'message' : 'Tenant not found' }
24
24
25
25
26
- def test_tenants_POST (client , test_database , auth_headers , create_property ):
26
+ def test_tenants_POST (client , empty_test_db , auth_headers , valid_header , create_property , create_join_staff ):
27
+ staff_1 = create_join_staff ()
28
+ staff_2 = create_join_staff ()
27
29
newTenant = {
28
30
"firstName" : "Jake" ,
29
31
"lastName" : "The Dog" ,
30
32
"phone" : "111-111-1111" ,
31
- "staffIDs" : [1 , 2 ]
33
+ "staffIDs" : [staff_1 . id , staff_2 . id ]
32
34
}
33
35
34
36
newTenantWithLease = {
@@ -43,25 +45,20 @@ def test_tenants_POST(client, test_database, auth_headers, create_property):
43
45
}
44
46
45
47
response = client .post (endpoint , json = newTenant ,
46
- headers = auth_headers [ "admin" ] )
48
+ headers = valid_header )
47
49
48
50
assert is_valid (response , 201 ) # CREATED
49
51
assert response .json ['firstName' ] == 'Jake'
50
52
51
53
response = client .post (endpoint , json = newTenantWithLease ,
52
- headers = auth_headers [ "admin" ] )
54
+ headers = valid_header )
53
55
assert is_valid (response , 201 )
54
56
assert response .json ['unitNum' ] == '413'
55
57
56
58
57
59
58
60
response = client .post (endpoint , json = newTenant ,
59
- headers = auth_headers ["admin" ])
60
- # UNAUTHORIZED - A tenant with this first and last name already exists
61
- assert is_valid (response , 401 )
62
- assert response .json == \
63
- {'message' :
64
- 'A tenant with this first and last name already exists' }
61
+ headers = valid_header )
65
62
66
63
response = client .post (endpoint , json = newTenant ,
67
64
headers = auth_headers ["pm" ])
@@ -76,30 +73,30 @@ def test_tenants_POST(client, test_database, auth_headers, create_property):
76
73
assert is_valid (response , 401 )
77
74
assert response .json == {'message' : 'Missing authorization header' }
78
75
79
- newTenant = {}
80
- response = client .post (endpoint , json = newTenant ,
81
- headers = auth_headers ["admin" ])
82
- # BAD REQUEST - {'firstName': 'This field cannot be blank.'}
83
- assert is_valid (response , 400 )
84
- assert response .json == {'message' :
85
- {'firstName' : 'This field cannot be blank' }}
86
-
87
- def test_tenants_PUT (client , auth_headers ):
88
- id = 1
76
+ def test_tenants_PUT (client , empty_test_db , valid_header , create_tenant , create_join_staff ):
77
+ tenant = create_tenant ()
78
+ staff_1 = create_join_staff ()
79
+ staff_2 = create_join_staff ()
89
80
updatedTenant = {
90
81
"firstName" : "Jake" ,
91
82
"lastName" : "The Dog" ,
92
83
"phone" : "111-111-1111" ,
93
- "staffIDs" : [1 , 2 ]
84
+ "staffIDs" : [staff_1 . id , staff_2 . id ]
94
85
}
95
- response = client .put (f'{ endpoint } /{ id } ' ,
96
- json = updatedTenant , headers = auth_headers ["admin" ])
86
+ response = client .put (
87
+ f'{ endpoint } /{ tenant .id } ' ,
88
+ json = updatedTenant ,
89
+ headers = valid_header
90
+ )
97
91
assert is_valid (response , 200 ) # OK
98
92
assert response .json ['firstName' ] == 'Jake'
99
93
100
94
id = 100
101
- response = client .put (f'{ endpoint } /{ id } ' ,
102
- json = updatedTenant , headers = auth_headers ["admin" ])
95
+ response = client .put (
96
+ f'{ endpoint } /{ id } ' ,
97
+ json = updatedTenant ,
98
+ headers = valid_header
99
+ )
103
100
assert is_valid (response , 404 ) # NOT FOUND
104
101
assert response .json == {'message' : 'Tenant not found' }
105
102
0 commit comments