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

Commit

Permalink
Fix param format being received by the backend (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSchimek committed Nov 14, 2021
1 parent 18a0243 commit 0d294e7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
21 changes: 1 addition & 20 deletions resources/tenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,6 @@ def get(self):
@admin_required
def post(self):
return (
TenantModel.create(
schema=TenantSchema, payload=self._build_payload()
).json(),
TenantModel.create(schema=TenantSchema, payload=request.json).json(),
201,
)

def _build_payload(self):
valid_tenant_params = ["firstName", "lastName", "phone", "staffIDs"]
valid_lease_params = ["dateTimeEnd", "dateTimeStart", "propertyID"]

params = {}
for param in valid_tenant_params:
if request.json.get(param):
params[param] = request.json.get(param)

if set(valid_lease_params) & set(list(request.json)):
params["lease"] = {}
for param in valid_lease_params:
if request.json.get(param):
params["lease"][param] = request.json.get(param)

return params
2 changes: 1 addition & 1 deletion tests/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def emergency_contact_attrs(faker):
def property_attrs(faker, archived=False):
return {
"name": faker.unique.company(),
"address": faker.address(),
"address": faker.street_address(),
"city": faker.city(),
"num_units": faker.random_int(min=1),
"state": faker.state(),
Expand Down
7 changes: 3 additions & 4 deletions tests/integration/test_tenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,16 @@ def test_create(
tenant_attrs = tenant_attributes()
lease_attrs = lease_payload()
tenant = create_tenant()
payload = {**tenant_attrs, "lease": {**lease_attrs}}

with patch.object(TenantModel, "create", return_value=tenant) as mock_create:
response = self.client.post(
"/api/tenants",
json={**tenant_attrs, **lease_attrs},
json=payload,
headers=valid_header,
)

mock_create.assert_called_once_with(
schema=TenantSchema, payload={**tenant_attrs, "lease": {**lease_attrs}}
)
mock_create.assert_called_once_with(schema=TenantSchema, payload=payload)

assert response.json == tenant.json()
assert response.status_code == 201
Expand Down

0 comments on commit 0d294e7

Please sign in to comment.