Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support consumer 20x responses #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/nrc/api/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def test_subscriptions_invalid_sink(self):
# Let callback url return 201 instead of required 204 when
# sending a notification
m.register_uri(
"POST", "https://endpoint.example.com/webhook", status_code=201
"POST", "https://endpoint.example.com/webhook", status_code=302
)
response = self.client.post(subscription_create_url, data)

Expand All @@ -207,6 +207,39 @@ def test_subscriptions_invalid_sink(self):
error = get_validation_errors(response, "nonFieldErrors")
self.assertEqual(error["code"], "invalid-callback-url")

@override_settings(
LINK_FETCHER="vng_api_common.mocks.link_fetcher_404",
ZDS_CLIENT_CLASS="vng_api_common.mocks.MockClient",
)
def test_subscriptions_callback_url_accept_20x_status_codes(self):
DomainFactory.create(name="nl.vng.zaken")

subscription_create_url = get_operation_url("subscription_create")

data = {
"protocol": ProtocolChoices.HTTP,
"source": "urn:nld:oin:00000001234567890000:systeem:Zaaksysteem",
"sink": "https://endpoint.example.com/webhook",
"domain": "nl.vng.zaken",
}

accepted_status_codes = range(200, 210)
for status_code in accepted_status_codes:
with self.subTest(callback_status_code=status_code):
with requests_mock.mock() as m:
# Let callback url return a 20x status code
m.register_uri(
"POST",
"https://endpoint.example.com/webhook",
status_code=status_code,
)
response = self.client.post(subscription_create_url, data)

self.assertEqual(
response.status_code, status.HTTP_201_CREATED, response.data
)
Subscription.objects.get().delete()

@override_settings(
LINK_FETCHER="vng_api_common.mocks.link_fetcher_404",
ZDS_CLIENT_CLASS="vng_api_common.mocks.MockClient",
Expand Down
2 changes: 1 addition & 1 deletion src/nrc/api/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __call__(self, attrs):
except requests.RequestException:
raise serializers.ValidationError(self.message, code=self.code)

if response.status_code != 204:
if not (200 <= response.status_code <= 209):
raise serializers.ValidationError(self.message, code=self.code)


Expand Down