added a few more tests
This commit is contained in:
parent
ee58e5590e
commit
bff1aeba6a
|
@ -1,4 +1,4 @@
|
|||
{% load staticfiles %} <!DOCTYPE html>
|
||||
{% load static %} <!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import uuid
|
||||
import pytest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from django.test import Client
|
||||
from django.urls import reverse
|
||||
|
@ -21,13 +22,26 @@ def test_check_callback_renders_template():
|
|||
@pytest.mark.parametrize(
|
||||
"method", ["get", "put", "post", "head", "delete", "patch", "options"]
|
||||
)
|
||||
def test_callback_view_always_return_200(method):
|
||||
def test_callback_view_always_return_200(method, monkeypatch):
|
||||
monkeypatch.setattr("callbacks.views.async_to_sync", lambda x: lambda x, y: None)
|
||||
callback = uuid.uuid4()
|
||||
c = Client()
|
||||
response = getattr(c, method)(reverse("callback-submit", kwargs={"uuid": callback}))
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_callback_view_submits_request_info_to_channel_layer():
|
||||
# TODO
|
||||
pass
|
||||
def test_callback_view_submits_request_info_to_channel_layer(monkeypatch):
|
||||
mock = MagicMock()
|
||||
request_data = {"body": {"some": "data"}, "headers": {"header": "one"}}
|
||||
monkeypatch.setattr("callbacks.views.async_to_sync", lambda x: mock)
|
||||
monkeypatch.setattr(
|
||||
"callbacks.views.CallbackView._request_data", lambda x, y: request_data
|
||||
)
|
||||
callback = str(uuid.uuid4())
|
||||
response = Client().post(
|
||||
reverse("callback-submit", kwargs={"uuid": callback}),
|
||||
data={"some": "data"},
|
||||
headers={"header": "one"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
mock.assert_called_with(callback, {"type": "new_request", "data": request_data})
|
||||
|
|
Loading…
Reference in New Issue