-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_render_mixin.py
More file actions
56 lines (43 loc) · 1.65 KB
/
test_render_mixin.py
File metadata and controls
56 lines (43 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import httpx
import respx
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.resources.commerce.mixins.render_mixin import AsyncRenderMixin, RenderMixin
from tests.unit.conftest import DummyModel
class DummyRenderService(
RenderMixin[DummyModel],
Service[DummyModel],
):
_endpoint = "public/v1/dummy/render"
_model_class = DummyModel
class AsyncDummyRenderService(
AsyncRenderMixin[DummyModel],
AsyncService[DummyModel],
):
_endpoint = "public/v1/dummy/render"
_model_class = DummyModel
def test_render(http_client):
service = DummyRenderService(http_client=http_client)
rendered_content = "<h1>Dummy Rendered Content</h1>"
with respx.mock:
respx.get("https://api.example.com/public/v1/dummy/render/DUMMY-123/render").mock(
return_value=httpx.Response(
status_code=httpx.codes.OK,
headers={"content-type": "text/html"},
content=rendered_content,
)
)
result = service.render("DUMMY-123")
assert result == rendered_content
async def test_async_render(async_http_client):
service = AsyncDummyRenderService(http_client=async_http_client)
rendered_content = "<h1>Dummy Rendered Content</h1>"
with respx.mock:
respx.get("https://api.example.com/public/v1/dummy/render/DUMMY-123/render").mock(
return_value=httpx.Response(
status_code=httpx.codes.OK,
headers={"content-type": "text/html"},
content=rendered_content,
)
)
result = await service.render("DUMMY-123")
assert result == rendered_content