mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-29 11:09:27 -05:00
Use pytest_httpx
This commit is contained in:
parent
9f5b706b2d
commit
e2a24ce95e
@ -11,6 +11,7 @@ from guardian.shortcuts import assign_perm
|
|||||||
from guardian.shortcuts import get_groups_with_perms
|
from guardian.shortcuts import get_groups_with_perms
|
||||||
from guardian.shortcuts import get_users_with_perms
|
from guardian.shortcuts import get_users_with_perms
|
||||||
from httpx import HTTPStatusError
|
from httpx import HTTPStatusError
|
||||||
|
from pytest_httpx import HTTPXMock
|
||||||
from rest_framework.test import APITestCase
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
from documents.signals.handlers import run_workflows
|
from documents.signals.handlers import run_workflows
|
||||||
@ -2670,8 +2671,12 @@ class TestWorkflows(
|
|||||||
|
|
||||||
mock_post.assert_called_once()
|
mock_post.assert_called_once()
|
||||||
|
|
||||||
@mock.patch("httpx.post")
|
|
||||||
def test_send_webhook_data_and_json(self, mock_post):
|
class TestWebhookSend:
|
||||||
|
def test_send_webhook_data_and_json(
|
||||||
|
self,
|
||||||
|
httpx_mock: HTTPXMock,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
- Nothing
|
- Nothing
|
||||||
@ -2680,9 +2685,8 @@ class TestWorkflows(
|
|||||||
THEN:
|
THEN:
|
||||||
- data is sent as form-encoded and json, respectively
|
- data is sent as form-encoded and json, respectively
|
||||||
"""
|
"""
|
||||||
mock_post.return_value = mock.Mock(
|
httpx_mock.add_response(
|
||||||
status_code=200,
|
content=b"ok",
|
||||||
json=mock.Mock(return_value={"status": "ok"}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
send_webhook(
|
send_webhook(
|
||||||
@ -2691,24 +2695,17 @@ class TestWorkflows(
|
|||||||
headers={},
|
headers={},
|
||||||
files=None,
|
files=None,
|
||||||
)
|
)
|
||||||
|
assert httpx_mock.get_request().content == b"Test message"
|
||||||
|
httpx_mock.reset()
|
||||||
|
|
||||||
mock_post.assert_called_once_with(
|
httpx_mock.add_response(
|
||||||
"http://paperless-ngx.com",
|
json={"status": "ok"},
|
||||||
data="Test message",
|
|
||||||
headers={},
|
|
||||||
files=None,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
send_webhook(
|
send_webhook(
|
||||||
url="http://paperless-ngx.com",
|
url="http://paperless-ngx.com",
|
||||||
data={"message": "Test message"},
|
data={"message": "Test message"},
|
||||||
headers={},
|
headers={},
|
||||||
files=None,
|
files=None,
|
||||||
)
|
)
|
||||||
|
assert httpx_mock.get_request().headers["Content-Type"] == "application/json"
|
||||||
mock_post.assert_called_with(
|
assert httpx_mock.get_request().content == b'{"message":"Test message"}'
|
||||||
"http://paperless-ngx.com",
|
|
||||||
json={"message": "Test message"},
|
|
||||||
headers={},
|
|
||||||
files=None,
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user