1
|
|
|
# Test gw_web_pattern |
2
|
|
|
def test_web_pattern(basicApp, WebPlugin): |
3
|
|
|
plugin = WebPlugin(basicApp) |
4
|
|
|
plugin.activate() |
5
|
|
|
|
6
|
|
|
assert basicApp.plugins.get("WebPlugin") is not None |
7
|
|
|
assert plugin.active is True |
8
|
|
|
|
9
|
|
|
assert hasattr(basicApp, "web") is True |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
def test_web_servers(basicApp, WebPlugin): |
13
|
|
|
|
14
|
|
|
def _test_server_start(): |
15
|
|
|
return "started" |
16
|
|
|
|
17
|
|
|
plugin = WebPlugin(basicApp) |
18
|
|
|
plugin.activate() |
19
|
|
|
|
20
|
|
|
plugin.web.servers.register("server_start", _test_server_start, "start test server") |
21
|
|
|
|
22
|
|
|
server = plugin.app.web.servers.get("server_start") |
23
|
|
|
assert server is not None |
24
|
|
|
assert server.name == "server_start" |
25
|
|
|
assert server.function() == "started" |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
def test_web_contexts(basicApp, WebPlugin, tmpdir): |
29
|
|
|
|
30
|
|
|
plugin = WebPlugin(basicApp) |
31
|
|
|
plugin.activate() |
32
|
|
|
|
33
|
|
|
template_folder = tmpdir.mkdir("template") |
34
|
|
|
static_folder = tmpdir.mkdir("static") |
35
|
|
|
|
36
|
|
|
plugin.web.contexts.register("test_context", str(template_folder), str(static_folder), "/test", "test context") |
37
|
|
|
|
38
|
|
|
context = plugin.app.web.contexts.get("test_context") |
39
|
|
|
assert context is not None |
40
|
|
|
assert context.name == "test_context" |
41
|
|
|
assert context.template_folder == template_folder |
42
|
|
|
assert context.static_folder == static_folder |
43
|
|
|
assert context.url_prefix == "/test" |
44
|
|
|
assert context.description == "test context" |
45
|
|
|
assert context.plugin == plugin |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
def test_web_routes(basicApp, WebPlugin): |
49
|
|
|
|
50
|
|
|
def _view(): |
51
|
|
|
pass |
52
|
|
|
|
53
|
|
|
plugin = WebPlugin(basicApp) |
54
|
|
|
plugin.activate() |
55
|
|
|
|
56
|
|
|
plugin.web.routes.register("/", ["GET", "POST"], _view, name="test_route", description="test route") |
57
|
|
|
|
58
|
|
|
route = plugin.app.web.routes.get("test_route") |
59
|
|
|
|
60
|
|
|
assert route is not None |
61
|
|
|
assert route.url == "/" |
62
|
|
|
assert route.methods == ["GET", "POST"] |
63
|
|
|
assert route.endpoint == _view |
64
|
|
|
assert route.context == plugin.app.web.contexts.default_context |
65
|
|
|
assert route.name == "test_route" |
66
|
|
|
assert route.description == "test route" |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
def test_web_menus(basicApp, WebPlugin): |
70
|
|
|
plugin = WebPlugin(basicApp) |
71
|
|
|
plugin.activate() |
72
|
|
|
|
73
|
|
|
menu_level_1 = plugin.web.menus.register("level_1_menu", "level_1") |
74
|
|
|
menu_level_2 = menu_level_1.register("level_2_menu", "level_2") |
75
|
|
|
assert plugin.app.web.menus.get("level_1_menu") == menu_level_1 |
76
|
|
|
assert plugin.app.web.menus.get("level_1_menu").sub_menus["level_2_menu"] == menu_level_2 |
77
|
|
|
|
78
|
|
|
# Cluster tests |
79
|
|
|
menu_level_1_a = plugin.web.menus.register("level_1_menu", "level_1", cluster="a") |
80
|
|
|
menu_level_2_a = menu_level_1_a.register("level_2_menu", "level_2") |
81
|
|
|
assert plugin.app.web.menus.get("level_1_menu", cluster="a") == menu_level_1_a |
82
|
|
|
assert plugin.app.web.menus.get("level_1_menu", cluster="a").sub_menus["level_2_menu"] == menu_level_2_a |
83
|
|
|
|