Skip to content

Commit aa83073

Browse files
authored
Merge pull request #101 from 0hsn/fix/test-setup
Fix: broken test setup
2 parents f0899f8 + 6f41653 commit aa83073

3 files changed

Lines changed: 294 additions & 325 deletions

File tree

Lines changed: 9 additions & 325 deletions
Original file line numberDiff line numberDiff line change
@@ -1,331 +1,15 @@
1-
import pytest
21
import tests
3-
from chk.modules.http.entities import HttpSpec_V072
4-
from chk.infrastructure.file_loader import ChkFileLoader
5-
6-
7-
class TestValidationForVersion_HttpSpec_V072:
8-
def test_validate_config_success(self):
9-
config = {
10-
'version': 'default:http:0.7.2'
11-
}
12-
13-
ver = HttpSpec_V072({})
14-
ver.document = config
15-
assert type(ver.version_validated()) is dict
16-
17-
def test_validate_config_empty_version(self):
18-
config = {
19-
'version': ''
20-
}
21-
22-
ver = HttpSpec_V072({})
23-
with pytest.raises(SystemExit):
24-
ver.document = config
25-
ver.version_validated()
26-
27-
def test_validate_config_fail_non_exist_ver(self):
28-
config = {
29-
'version': 'default:http:0.7'
30-
}
31-
32-
ver = HttpSpec_V072({})
33-
with pytest.raises(SystemExit):
34-
ver.document = config
35-
ver.version_validated()
36-
37-
def test_validate_config_fail_no_doc(self):
38-
config = {}
39-
40-
ver = HttpSpec_V072({})
41-
with pytest.raises(SystemExit):
42-
ver.document = config
43-
ver.version_validated()
44-
45-
def test_validate_config_fail_on_none(self):
46-
config = None
47-
48-
ver = HttpSpec_V072({})
49-
with pytest.raises(SystemExit):
50-
ver.document = config
51-
ver.version_validated()
52-
53-
def test_validate_config_fail_no_version(self):
54-
config = {
55-
'request': {
56-
'url': 'some.url'
57-
}
58-
}
59-
60-
ver = HttpSpec_V072({})
61-
with pytest.raises(SystemExit):
62-
ver.document = config
63-
ver.version_validated()
64-
65-
66-
class TestValidationForRequest_HttpSpec_V072:
67-
"""Test chk.archetypes.defaults.http_config.HttpSpec_V072"""
68-
69-
def test_validate_schema(self):
70-
config = {
71-
'version': 'default:http:0.7.2',
72-
'request': {
73-
'url': 'https://example.com',
74-
'method': 'GET'
75-
}
76-
}
77-
78-
ver = HttpSpec_V072({})
79-
ver.document = config
80-
assert type(ver.request_validated()) is dict
81-
82-
def test_validate_fail_if_url_empty(self):
83-
config = {
84-
'version': 'default:http:0.7.2',
85-
'request': {
86-
'url': None,
87-
'method': 'GET'
88-
}
89-
}
902

91-
ver = HttpSpec_V072({})
92-
93-
with pytest.raises(SystemExit):
94-
ver.document = config
95-
ver.request_validated()
96-
97-
def test_validate_fail_if_url_wrong(self):
98-
config = {
99-
'version': 'default:http:0.7.2',
100-
'request': {
101-
'url': 'ftp://example.com/wrong/url.html',
102-
'method': 'GET'
103-
}
104-
}
105-
106-
ver = HttpSpec_V072({})
107-
108-
with pytest.raises(SystemExit):
109-
ver.document = config
110-
ver.request_validated()
111-
112-
def test_validate_success_with_method(self):
113-
config = {
114-
'version': 'default:http:0.7.2',
115-
'request': {
116-
'url': 'https://example.com',
117-
'method': 'GET'
118-
}
119-
}
120-
121-
ver = HttpSpec_V072({})
122-
ver.document = config
123-
assert type(ver.request_validated()) is dict
124-
125-
def test_validate_fail_if_method_wrong(self):
126-
config = {
127-
'version': 'default:http:0.7.2',
128-
'request': {
129-
'url': 'https://example.com',
130-
'method': 'WRONG'
131-
}
132-
}
133-
134-
ver = HttpSpec_V072({})
3+
from chk.modules.http.entities import HttpSpec_V072
4+
from chk.infrastructure.file_loader import ChkFileLoader, FileContext
5+
from chk.infrastructure.work import handle_worker
1356

136-
with pytest.raises(SystemExit):
137-
ver.document = config
138-
ver.request_validated()
1397

140-
def test_validate_get_expect_pass(self):
8+
class TestHttpSpec_V072:
9+
def test_get_plain_pass(self):
14110
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'pass_cases/GET-Plain.chk')
142-
ver = HttpSpec_V072({})
143-
ver.document = doc
144-
assert type(ver.request_validated()) is dict
145-
146-
def test_validate_get_with_query_expect_pass(self):
147-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'pass_cases/GET-WithQuery.chk')
148-
ver = HttpSpec_V072({})
149-
ver.document = doc
150-
assert type(ver.request_validated()) is dict
151-
152-
def test_validate_get_with_query_empty_expect_fail(self):
153-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/GET-WithQuery-Empty.chk')
154-
ver = HttpSpec_V072({})
155-
156-
with pytest.raises(SystemExit):
157-
ver.document = doc
158-
ver.request_validated()
159-
160-
def test_validate_get_with_query_as_list_expect_fail(self):
161-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/GET-WithQuery-AsList.chk')
162-
ver = HttpSpec_V072({})
163-
164-
with pytest.raises(SystemExit):
165-
ver.document = doc
166-
ver.request_validated()
167-
168-
def test_validate_get_with_headers_expect_pass(self):
169-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'pass_cases/GET-WithHeaders.chk')
170-
ver = HttpSpec_V072({})
171-
ver.document = doc
172-
assert type(ver.request_validated()) is dict
173-
174-
def test_validate_get_with_headers_empty_expect_fail(self):
175-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/GET-WithHeaders-Empty.chk')
176-
ver = HttpSpec_V072({})
177-
178-
with pytest.raises(SystemExit):
179-
ver.document = doc
180-
ver.request_validated()
181-
182-
def test_validate_get_with_headers_as_list_expect_fail(self):
183-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/GET-WithHeaders-AsList.chk')
184-
ver = HttpSpec_V072({})
185-
186-
with pytest.raises(SystemExit):
187-
ver.document = doc
188-
ver.request_validated()
189-
190-
def test_validate_get_with_ba_expect_pass(self):
191-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'pass_cases/GET-WithBasicAuth.chk')
192-
ver = HttpSpec_V072({})
193-
ver.document = doc
194-
assert type(ver.request_validated()) is dict
195-
196-
def test_validate_get_with_ba_empty_expect_fail(self):
197-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/GET-WithBasicAuth-Empty.chk')
198-
ver = HttpSpec_V072({})
199-
200-
with pytest.raises(SystemExit):
201-
ver.document = doc
202-
ver.request_validated()
203-
204-
def test_validate_get_with_ba_as_list_expect_fail(self):
205-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/GET-WithBasicAuth-AsList.chk')
206-
ver = HttpSpec_V072({})
207-
208-
with pytest.raises(SystemExit):
209-
ver.document = doc
210-
ver.request_validated()
211-
212-
def test_validate_get_with_ba_and_be_sametime_expect_fail(self):
213-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/GET-WithBasicAuth-AndBearer.chk')
214-
ver = HttpSpec_V072({})
215-
216-
with pytest.raises(SystemExit):
217-
ver.document = doc
218-
ver.request_validated()
219-
220-
def test_validate_get_with_be_expect_pass(self):
221-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'pass_cases/GET-WithBearerAuth.chk')
222-
ver = HttpSpec_V072({})
223-
ver.document = doc
224-
assert type(ver.request_validated()) is dict
225-
226-
def test_validate_get_with_be_empty_expect_fail(self):
227-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/GET-WithBearerAuth-Empty.chk')
228-
ver = HttpSpec_V072({})
229-
230-
with pytest.raises(SystemExit):
231-
ver.document = doc
232-
ver.request_validated()
233-
234-
def test_validate_get_with_be_as_list_expect_fail(self):
235-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/GET-WithBearerAuth-AsList.chk')
236-
ver = HttpSpec_V072({})
237-
238-
with pytest.raises(SystemExit):
239-
ver.document = doc
240-
ver.request_validated()
241-
242-
def test_validate_post_plain_expect_pass(self):
243-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'pass_cases/POST-Plain.chk')
244-
ver = HttpSpec_V072({})
245-
246-
ver.document = doc
247-
assert type(ver.request_validated()) is dict
248-
249-
def test_validate_post_with_form_body_expect_pass(self):
250-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'pass_cases/POST-WithBodyForm.chk')
251-
ver = HttpSpec_V072({})
252-
253-
ver.document = doc
254-
assert type(ver.request_validated()) is dict
255-
256-
def test_validate_post_with_form_body_as_list_expect_fail(self):
257-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/POST-WithBodyForm-AsList.chk')
258-
ver = HttpSpec_V072({})
259-
260-
with pytest.raises(SystemExit):
261-
ver.document = doc
262-
ver.request_validated()
263-
264-
def test_validate_post_with_form_body_as_empty_expect_fail(self):
265-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/POST-WithBodyForm-Empty.chk')
266-
ver = HttpSpec_V072({})
267-
268-
with pytest.raises(SystemExit):
269-
ver.document = doc
270-
ver.request_validated()
271-
272-
def test_validate_post_with_form_data_body_expect_pass(self):
273-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'pass_cases/POST-WithBodyFormData.chk')
274-
ver = HttpSpec_V072({})
275-
276-
ver.document = doc
277-
assert type(ver.request_validated()) is dict
278-
279-
def test_validate_post_with_form_data_body_as_list_expect_fail(self):
280-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/POST-WithBodyFormData-AsList.chk')
281-
ver = HttpSpec_V072({})
282-
283-
with pytest.raises(SystemExit):
284-
ver.document = doc
285-
ver.request_validated()
286-
287-
def test_validate_post_with_form_data_body_as_empty_expect_fail(self):
288-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/POST-WithBodyFormData-Empty.chk')
289-
ver = HttpSpec_V072({})
290-
291-
with pytest.raises(SystemExit):
292-
ver.document = doc
293-
ver.request_validated()
294-
295-
def test_validate_post_with_json_body_expect_pass(self):
296-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'pass_cases/POST-WithBodyJson.chk')
297-
ver = HttpSpec_V072({})
298-
299-
ver.document = doc
300-
assert type(ver.request_validated()) is dict
301-
302-
def test_validate_post_with_json_body_as_empty_expect_fail(self):
303-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/POST-WithBodyJson-Empty.chk')
304-
ver = HttpSpec_V072({})
305-
306-
with pytest.raises(SystemExit):
307-
ver.document = doc
308-
ver.request_validated()
309-
310-
def test_validate_post_with_xml_body_expect_pass(self):
311-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'pass_cases/GET-WithBodyXML.chk')
312-
ver = HttpSpec_V072({})
313-
314-
ver.document = doc
315-
assert type(ver.request_validated()) is dict
316-
317-
def test_validate_post_with_xml_body_as_empty_expect_fail(self):
318-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/POST-WithBodyXML-Empty.chk')
319-
ver = HttpSpec_V072({})
320-
321-
with pytest.raises(SystemExit):
322-
ver.document = doc
323-
ver.request_validated()
324-
325-
def test_validate_post_with_many_body_expect_fail(self):
326-
doc = ChkFileLoader.to_dict(tests.RES_DIR + 'fail_cases/POST-WithManyBody.chk')
327-
ver = HttpSpec_V072({})
11+
file_ctx = FileContext(None, None, None, doc)
32812

329-
with pytest.raises(SystemExit):
330-
ver.document = doc
331-
ver.request_validated()
13+
http = HttpSpec_V072(file_ctx)
14+
response = handle_worker(http)
15+
assert type(response) == dict

0 commit comments

Comments
 (0)