forked from sanic-org/sanic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_versioning.py
141 lines (95 loc) · 3.85 KB
/
test_versioning.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import pytest
from sanic import Blueprint, text
@pytest.fixture
def handler():
def handler(_):
return text("Done.")
return handler
def test_route(app, handler):
app.route("/", version=1)(handler)
_, response = app.test_client.get("/v1")
assert response.status == 200
def test_bp(app, handler):
bp = Blueprint("Test", version=1)
bp.route("/")(handler)
app.blueprint(bp)
_, response = app.test_client.get("/v1")
assert response.status == 200
def test_bp_use_route(app, handler):
bp = Blueprint("Test", version=1)
bp.route("/", version=1.1)(handler)
app.blueprint(bp)
_, response = app.test_client.get("/v1.1")
assert response.status == 200
def test_bp_group(app, handler):
bp = Blueprint("Test")
bp.route("/")(handler)
group = Blueprint.group(bp, version=1)
app.blueprint(group)
_, response = app.test_client.get("/v1")
assert response.status == 200
def test_bp_group_use_bp(app, handler):
bp = Blueprint("Test", version=1.1)
bp.route("/")(handler)
group = Blueprint.group(bp, version=1)
app.blueprint(group)
_, response = app.test_client.get("/v1.1")
assert response.status == 200
def test_bp_group_use_registration(app, handler):
bp = Blueprint("Test", version=1.1)
bp.route("/")(handler)
group = Blueprint.group(bp, version=1)
app.blueprint(group, version=1.2)
_, response = app.test_client.get("/v1.2")
assert response.status == 200
def test_bp_group_use_route(app, handler):
bp = Blueprint("Test", version=1.1)
bp.route("/", version=1.3)(handler)
group = Blueprint.group(bp, version=1)
app.blueprint(group, version=1.2)
_, response = app.test_client.get("/v1.3")
assert response.status == 200
def test_version_prefix_route(app, handler):
app.route("/", version=1, version_prefix="/api/v")(handler)
_, response = app.test_client.get("/api/v1")
assert response.status == 200
def test_version_prefix_bp(app, handler):
bp = Blueprint("Test", version=1, version_prefix="/api/v")
bp.route("/")(handler)
app.blueprint(bp)
_, response = app.test_client.get("/api/v1")
assert response.status == 200
def test_version_prefix_bp_use_route(app, handler):
bp = Blueprint("Test", version=1, version_prefix="/ignore/v")
bp.route("/", version=1.1, version_prefix="/api/v")(handler)
app.blueprint(bp)
_, response = app.test_client.get("/api/v1.1")
assert response.status == 200
def test_version_prefix_bp_group(app, handler):
bp = Blueprint("Test")
bp.route("/")(handler)
group = Blueprint.group(bp, version=1, version_prefix="/api/v")
app.blueprint(group)
_, response = app.test_client.get("/api/v1")
assert response.status == 200
def test_version_prefix_bp_group_use_bp(app, handler):
bp = Blueprint("Test", version=1.1, version_prefix="/api/v")
bp.route("/")(handler)
group = Blueprint.group(bp, version=1, version_prefix="/ignore/v")
app.blueprint(group)
_, response = app.test_client.get("/api/v1.1")
assert response.status == 200
def test_version_prefix_bp_group_use_registration(app, handler):
bp = Blueprint("Test", version=1.1, version_prefix="/alsoignore/v")
bp.route("/")(handler)
group = Blueprint.group(bp, version=1, version_prefix="/ignore/v")
app.blueprint(group, version=1.2, version_prefix="/api/v")
_, response = app.test_client.get("/api/v1.2")
assert response.status == 200
def test_version_prefix_bp_group_use_route(app, handler):
bp = Blueprint("Test", version=1.1, version_prefix="/alsoignore/v")
bp.route("/", version=1.3, version_prefix="/api/v")(handler)
group = Blueprint.group(bp, version=1, version_prefix="/ignore/v")
app.blueprint(group, version=1.2, version_prefix="/stillignoring/v")
_, response = app.test_client.get("/api/v1.3")
assert response.status == 200