response code can be defined on the callback url
This commit is contained in:
parent
00eb6f3902
commit
0ed52a3cf6
|
@ -64,3 +64,13 @@ def test_callback_view_filters_excluded_headers(settings, monkeypatch):
|
||||||
assert "headers" in data
|
assert "headers" in data
|
||||||
assert "Excluded" not in data["headers"].keys()
|
assert "Excluded" not in data["headers"].keys()
|
||||||
assert "Not-Excluded" in data["headers"].keys()
|
assert "Not-Excluded" in data["headers"].keys()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("status", [200, 201, 400, 401, 403, 404, 500])
|
||||||
|
def test_callback_view_non_default_response(status, monkeypatch):
|
||||||
|
monkeypatch.setattr("callbacks.views.async_to_sync", lambda x: lambda x, y: None)
|
||||||
|
callback = uuid.uuid4()
|
||||||
|
res = Client().get(
|
||||||
|
reverse("callback-submit-response", kwargs={"uuid": callback, "status": status})
|
||||||
|
)
|
||||||
|
assert res.status_code == status
|
||||||
|
|
|
@ -42,7 +42,8 @@ class CallbackView(View):
|
||||||
async_to_sync(channel_layer.group_send)(
|
async_to_sync(channel_layer.group_send)(
|
||||||
kwargs["uuid"], {"type": "new_request", "data": self._request_data(request)}
|
kwargs["uuid"], {"type": "new_request", "data": self._request_data(request)}
|
||||||
)
|
)
|
||||||
return HttpResponse()
|
response_status = kwargs.get("status", 200)
|
||||||
|
return HttpResponse(status=response_status)
|
||||||
|
|
||||||
def _request_data(self, request):
|
def _request_data(self, request):
|
||||||
body = request.body.decode("utf-8")
|
body = request.body.decode("utf-8")
|
||||||
|
|
|
@ -19,5 +19,6 @@ from callbacks.views import HomeView, CheckView, CallbackView
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("check", CheckView.as_view(), name="callback-check"),
|
path("check", CheckView.as_view(), name="callback-check"),
|
||||||
path("<uuid>", CallbackView.as_view(), name="callback-submit"),
|
path("<uuid>", CallbackView.as_view(), name="callback-submit"),
|
||||||
|
path("<uuid>/<status>", CallbackView.as_view(), name="callback-submit-response"),
|
||||||
path("", HomeView.as_view(), name="callback-home"),
|
path("", HomeView.as_view(), name="callback-home"),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue