-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_render_engine_cli.py
More file actions
67 lines (51 loc) · 1.78 KB
/
test_render_engine_cli.py
File metadata and controls
67 lines (51 loc) · 1.78 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
57
58
59
60
61
62
63
64
65
66
67
import time
import ephemeral_port_reserve
import httpx
import pytest
from render_engine.page import Page
from render_engine.site import Site
from render_engine_cli.event import ServerEventHandler
@pytest.fixture(scope="module")
def site(tmp_path_factory):
"""Base Site Object"""
test_site = Site()
test_output_path = tmp_path_factory.mktemp("output")
test_site.output_path = test_output_path
@test_site.page
class Index(Page):
content = "Hello World!"
test_site.render()
return test_site
@pytest.fixture(scope="module")
def event_handler(site):
hostname = ephemeral_port_reserve.LOCALHOST
free_port = ephemeral_port_reserve.reserve(hostname)
class Handler(ServerEventHandler):
def stop_watcher(self):
time.sleep(2)
return True
handler = Handler(
server_address=(hostname, free_port),
import_path="tests.tests_cli.test_render_engine_cli",
site="test_site",
output_path=site.output_path,
dirs_to_watch=None,
)
return {
"hostname": hostname,
"port": free_port,
"handler": handler,
}
def test_server_build(event_handler):
"""Asserts you can start and stop the server"""
event_handler["handler"].start_server()
response = httpx.get(f"http://{event_handler['hostname']}:{event_handler['port']}")
event_handler["handler"].stop_server()
assert response.status_code == 200
assert response.text == "Hello World!"
def test_as_a_context_manager(event_handler):
"""Asserts you can start and stop the server with a context manager"""
with event_handler["handler"]:
response = httpx.get(f"http://{event_handler['hostname']}:{event_handler['port']}")
assert response.status_code == 200
assert response.text