I would like some help to mock a query_param using responses and pytest.
I have this view:
@api_view(["GET"])
@csrf_exempt
@permission_classes((AllowAny,))
def get_code_and_extra(request):
code = request.GET.get("code", "")
extra = request.GET.get("extra", "")
if code and extra:
# do something
return HttpResponse("", status=200)
return HttpResponse("", status=400)
And my test mocked:
@responses.activate
def test_receive(self, db, client):
responses.add(
responses.GET,
"https://test.com/?code=some-code&extra=extra",
json={},
status=200,
content_type="application/json",
)
resp = client.get(reverse("my-url"))
assert resp.status_code == 200
When I run my test works, but the view does not receive the query_params. I would like to pass it so that the test works as expected.
A little more context: this view serves as a webhook that receives these parameters from another site. The view is working, but I wanted to have this test.