Skip to content

Commit

Permalink
fix: NotificationSettingsClient.delete now returns None for 204 No Co…
Browse files Browse the repository at this point in the history
…ntent response
  • Loading branch information
davidgrayston-paddle committed Sep 24, 2024
1 parent ce5845b commit c249667
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx
### Changed

- `paddle_billing.Entities.Shared.CustomData` is no longer a `dataclass`
- `NotificationSettingsClient.delete` now returns `None` for `204 No Content` response

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def update(self, notification_setting_id: str, operation: UpdateNotificationSett
return NotificationSetting.from_dict(parser.get_data())


def delete(self, notification_setting_id: str) -> NotificationSetting:
self.response = self.client.delete_raw(f"/notification-settings/{notification_setting_id}")
parser = ResponseParser(self.response)
def delete(self, notification_setting_id: str) -> None:
self.client.delete_raw(f"/notification-settings/{notification_setting_id}")

return NotificationSetting.from_dict(parser.get_data())
return None
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,10 @@ def test_get_notification_settings_returns_expected_response(


@mark.parametrize(
'notification_setting_id, expected_response_status, expected_response_body, expected_url',
'notification_setting_id, expected_response_status, expected_path',
[(
'ntfset_01gkpjp8bkm3tm53kdgkx6sms7',
200,
ReadsFixtures.read_raw_json_fixture('response/full_entity'),
204,
'/notification-settings/ntfset_01gkpjp8bkm3tm53kdgkx6sms7',
)],
ids=["Delete a notification setting by its id"],
Expand All @@ -364,23 +363,19 @@ def test_delete_notification_setting_returns_expected_response(
mock_requests,
notification_setting_id,
expected_response_status,
expected_response_body,
expected_url,
expected_path,
):
"""Although the API doesn't specify a returned body, in practice it returns the deleted notification setting."""

expected_url = f"{test_client.base_url}{expected_url}"
mock_requests.delete(expected_url, status_code=expected_response_status, text=expected_response_body)
expected_url = f"{test_client.base_url}{expected_path}"
mock_requests.delete(expected_url, status_code=expected_response_status)

response = test_client.client.notification_settings.delete(notification_setting_id)
response_json = test_client.client.notification_settings.response.json()
last_request = mock_requests.last_request

assert isinstance(response, NotificationSetting)
assert response is None
assert last_request is not None
assert last_request.method == 'DELETE'
assert test_client.client.status_code == expected_response_status
assert unquote(last_request.url) == expected_url, \
"The URL does not match the expected URL, verify the query string is correct"
assert response_json == loads(str(expected_response_body)), \
"The response JSON generated by ResponseParser() doesn't match the expected fixture JSON"

0 comments on commit c249667

Please sign in to comment.