Skip to content

Commit

Permalink
fix: failing patch requests (#246)
Browse files Browse the repository at this point in the history
* fix: failing patch requests

`request.data` is a regular dict for `application/json`. `request.data._mutable` is not required.

* fix: reset `errors_count` and `is_token_expired` while updating an integration (#247)
  • Loading branch information
1 parent ff35402 commit b32183b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion apps/integrations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def create(self, validated_data):
'is_active': True,
'org_name': validated_data['org_name'],
'tpa_id': validated_data['tpa_id'],
'tpa_name': validated_data['tpa_name']
'tpa_name': validated_data['tpa_name'],
'errors_count': 0,
'is_token_expired': False
}
)
elif not validated_data['is_active']:
Expand Down
1 change: 0 additions & 1 deletion apps/integrations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def patch(self, request, *args, **kwargs):

try:
org_id = get_org_id_and_name_from_access_token(access_token)['id']
request.data._mutable = True
request.data['org_id'] = org_id
except Exception as error:
logger.info(error)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_integrations/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ def test_integrations_view_patch(api_client, mocker, access_token):
api_client.credentials(HTTP_AUTHORIZATION='Bearer {}'.format(access_token))


response = api_client.patch(url, patch_integration_no_tpa_name)
response = api_client.patch(url, json.dumps(patch_integration_no_tpa_name), content_type="application/json")
assert response.status_code == 400, 'PATCH without a tpa_name should return 400'

response = api_client.patch(url, patch_integration_invalid_tpa_name)
response = api_client.patch(url, json.dumps(patch_integration_invalid_tpa_name), content_type="application/json")
assert response.status_code == 400, 'PATCH with an invalid tpa_name should return 400'

# Update two fields
response = api_client.patch(url, patch_integration)
response = api_client.patch(url, json.dumps(patch_integration), content_type="application/json")
assert response.status_code == 200, 'Valid PATCH request should be successful'

response = json.loads(response.content)
Expand All @@ -267,7 +267,7 @@ def test_integrations_view_patch(api_client, mocker, access_token):
assert response['is_token_expired'] == patch_integration['is_token_expired']

# Update one field, leaving the other as it is
response = api_client.patch(url, patch_integration_partial)
response = api_client.patch(url, json.dumps(patch_integration_partial), content_type="application/json")
assert response.status_code == 200, 'Valid PATCH request should be successful'

response = json.loads(response.content)
Expand Down

0 comments on commit b32183b

Please sign in to comment.