-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_crawler.py
224 lines (191 loc) · 6.92 KB
/
test_crawler.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import json
import pytest
from crawler import Crawler, EmptyKeywords, NoQueryTypeProvided
@pytest.fixture()
def request_ok():
"""
Returns a valid input dict
:return: valid input dict.
"""
return dict(
keywords=["openstack", "nova", "css"],
proxies=["194.126.37.94:8080", "13.78.125.167:8080"],
type="Repositories"
)
@pytest.fixture()
def response_repos_ok():
"""
Returns a correct repos list response.
:return: correct repos list response.
"""
return [{
"url": "https://github.com/atuldjadhav/DropBox-Cloud-Storage",
"extra": {
"owner": "atuldjadhav",
"language_stats": {
"CSS": 52.0,
"JavaScript": 47.2,
"HTML": 0.8}}}]
@pytest.fixture()
def response_wikis_ok():
"""
Returns a correct wikis list response.
:return: correct wikis list response.
"""
return [
{"url": "https://github.com/vault-team/vault-website/wiki/Quick-instal"
"lation-guide"},
{"url": "https://github.com/iiwaziri/wiki_learn/wiki/Packstack"},
{"url": "https://github.com/marcosaletta/Juno-CentOS7-Guide/wiki/2.-Co"
"ntroller-and-Network-Node-Installation"},
{"url": "https://github.com/MirantisDellCrowbar/crowbar/wiki/Release-n"
"otes"},
{"url": "https://github.com/dellcloudedge/crowbar/wiki/Release-notes"},
{"url": "https://github.com/rhafer/crowbar/wiki/Release-notes"},
{"url": "https://github.com/eryeru12/crowbar/wiki/Release-notes"},
{"url": "https://github.com/vinayakponangi/crowbar/wiki/Release-note"
"s"},
{"url": "https://github.com/jamestyj/crowbar/wiki/Release-notes"},
{"url": "https://github.com/opencit/opencit/wiki/Open-CIT-3.2.1-Produc"
"t-Guide"}
]
@pytest.fixture()
def response_issues_ok():
"""
Returns a correct issues list response.
:return: correct issues list response.
"""
return [
{"url": "https://github.com/hellowj/blog/issues/37"},
{"url": "https://github.com/sfPPP/openstack-note/issues/8"},
{"url": "https://github.com/altai/nova-billing/issues/1"},
{"url": "https://github.com/novnc/websockify/issues/180"},
{"url": "https://github.com/aaronkurtz/gourmand/pull/35"},
{"url": "https://github.com/zioc/contrail-devstack-plugin/issues/27"},
{"url": "https://github.com/rcbops/rpc-openstack/pull/2257"},
{"url": "https://github.com/sphinx-doc/sphinx/issues/3782"},
{"url": "https://github.com/clearlydefined/service/issues/85"},
{"url": "https://github.com/python/core-workflow/issues/6"}
]
def test_repos_ok(request_ok, response_repos_ok):
"""
Test that the repository functionality work ok.
:param request_ok: dictionary with a correct repos query.
:param response_ok: list with a correct response
"""
cr = Crawler()
query_data = json.dumps(request_ok)
expected_response = json.dumps(response_repos_ok)
assert cr.query(query_data) == expected_response
def test_wikis_ok(request_ok, response_wikis_ok):
"""
Test that the wikis functionality work ok.
:param request_ok: dictionary with a correct wikis query.
:param response_ok: list with a correct response
"""
cr = Crawler()
request_ok['type'] = "Wikis"
query_data = json.dumps(request_ok)
expected_response = json.dumps(response_wikis_ok)
assert cr.query(query_data) == expected_response
def test_issues_ok(request_ok, response_issues_ok):
"""
Test that the issues functionality work ok.
:param request_ok: dictionary with a correct issues query.
:param response_ok: list with a correct response
"""
cr = Crawler()
request_ok['type'] = "Issues"
query_data = json.dumps(request_ok)
expected_response = json.dumps(response_issues_ok)
assert cr.query(query_data) == expected_response
def test_empty_keywords(request_ok):
"""
Test that an EmptyKeywords exception is raised when empty keywords.
:param request_ok: dictionary with a correct repos query.
"""
cr = Crawler()
request_ok['keywords'] = []
query_data = json.dumps(request_ok)
with pytest.raises(EmptyKeywords):
cr.query(query_data)
def test_not_list_keywords(request_ok):
"""
Test that a TypeError exception is raised when keywords is not a list.
:param request_ok: dictionary with a correct repos query.
"""
cr = Crawler()
request_ok['keywords'] = 123
query_data = json.dumps(request_ok)
with pytest.raises(TypeError):
cr.query(query_data)
def test_no_keywords(request_ok):
"""
Test that a KeyError exception is raised when no keywords.
:param request_ok: dictionary with a correct repos query.
"""
cr = Crawler()
del request_ok['keywords']
query_data = json.dumps(request_ok)
with pytest.raises(KeyError):
cr.query(query_data)
def test_not_list_proxies(request_ok):
"""
Test that a TypeError exception is raised when proxies is not a list.
:param request_ok: dictionary with a correct repos query.
"""
cr = Crawler()
request_ok['proxies'] = 123
query_data = json.dumps(request_ok)
with pytest.raises(TypeError):
cr.query(query_data)
def test_no_proxies(request_ok):
"""
Test that a KeyError exception is raised when no proxies.
:param request_ok: dictionary with a correct repos query.
"""
cr = Crawler()
del request_ok['proxies']
query_data = json.dumps(request_ok)
with pytest.raises(KeyError):
cr.query(query_data)
def test_empty_type(request_ok):
"""
Test that an NoQueryTypeProvided exception is raised when empty type.
:param request_ok: dictionary with a correct repos query.
"""
cr = Crawler()
request_ok['type'] = ""
query_data = json.dumps(request_ok)
with pytest.raises(NoQueryTypeProvided):
cr.query(query_data)
def test_incorrect_type(request_ok):
"""
Test that an NoQueryTypeProvided exception is raised when incorrect type.
:param request_ok: dictionary with a correct repos query.
"""
cr = Crawler()
request_ok['type'] = "blabla"
query_data = json.dumps(request_ok)
with pytest.raises(NoQueryTypeProvided):
cr.query(query_data)
def test_not_string_type(request_ok):
"""
Test that a TypeError exception is raised when proxies is not a string.
:param request_ok: dictionary with a correct repos query.
"""
cr = Crawler()
request_ok['type'] = 123
query_data = json.dumps(request_ok)
with pytest.raises(TypeError):
cr.query(query_data)
def test_no_type(request_ok):
"""
Test that a KeyError exception is raised when no type.
:param request_ok: dictionary with a correct repos query.
"""
cr = Crawler()
del request_ok['type']
query_data = json.dumps(request_ok)
with pytest.raises(KeyError):
cr.query(query_data)