-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
163 lines (136 loc) · 5.82 KB
/
tests.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
import asyncio
import aiohttp
import unittest
import jobs
from jobs import GithubJobsWrapper as testGJW
from jobs import TheMuseJobsWrapper as testTMJW
class SearchTests(unittest.TestCase):
def setUp(self):
self.loop = asyncio.get_event_loop()
def test_GithubSearch(self):
'''
Verify that searching does work.
'''
async def test():
searchResults = await testGJW.search("jobs",
description="Software Engineer",
location="New York City",
full_time="true"
)
self.assertIsInstance(searchResults, list)
self.loop.run_until_complete(test())
def test_MuseSearch(self):
'''
Verify that searching does work.
'''
async def test():
searchResults = await testTMJW.search("jobs",
page="1",
location="New York",
)
self.assertIsInstance(searchResults, dict)
self.loop.run_until_complete(test())
class ResponseProcessingTest(unittest.TestCase):
def setUp(self):
self.loop = asyncio.get_event_loop()
def test_GithubResponseProcessing(self):
'''
Tests processing class method (listResults) for the GithubJobs wrapper.
'''
async def test():
searchResults = await testGJW.search("jobs",
description="Software Engineer",
location="New York City",
full_time="true"
)
'''
Remove comments if you want to see the results fly by.
async for result in testGJW.listResults(searchResults):
print(result)
'''
self.loop.run_until_complete(test())
def test_MuseResponseProcessing(self):
'''
Tests processing class method (listResults) for the The Muse API wrapper.
'''
async def test():
searchResults = await testTMJW.search("jobs",
page="1",
location="New York",
)
'''
Remove comments if you want to see the results fly by.
async for result in testTMJW.listResults(searchResults):
print(result)
'''
self.loop.run_until_complete(test())
class ValidationTests(unittest.TestCase):
def setUp(self):
self.loop = asyncio.get_event_loop()
def test_GithubAPISpecificError1(self):
'''
Tests for an APISpecificError exception when both parameters lat and long are provided,
but the location parameter has already been provided.
'''
async def test():
await testGJW.search("jobs",
description="Software Engineer",
location="New York City",
lat="40.7128",
long="74.0060",
full_time="true"
)
with self.assertRaises(jobs.APISpecificError):
self.loop.run_until_complete(test())
def test_GithubAPISpecificError2(self):
'''
Tests for an APISpecificError exception when either parameters lat or long are provided,
but the other was not passed.
'''
async def test():
await testGJW.search("jobs",
description="Software Engineer",
location="New York City",
lat="40.7128",
full_time="true"
)
with self.assertRaises(jobs.APISpecificError):
self.loop.run_until_complete(test())
def test_GithubInvalidFieldError(self):
'''
Tests for an InvalidFieldError exception when client code passes a field not supported
by the Github Jobs API.
'''
async def test():
await testGJW.search("jobs",
description="Software Engineer",
location="New York City",
invalidparameter="Despacito"
)
with self.assertRaises(jobs.InvalidFieldError):
self.loop.run_until_complete(test())
def test_MuseAPISpecificError1(self):
'''
Tests for APISpecificError when client code fails to provide a page keyword parameter to their query.
'''
async def test():
await testTMJW.search("jobs",
company="Google",
location="New York City"
)
with self.assertRaises(jobs.APISpecificError):
self.loop.run_until_complete(test())
def test_MuseInvalidFieldError1(self):
'''
Tests for InvalidFieldError when client code provides a not-supported field to an endpoint in their query.
'''
async def test():
await testTMJW.search("jobs",
foo="bar",
company="Google",
location="New York City"
)
with self.assertRaises(jobs.APISpecificError):
self.loop.run_until_complete(test())
if __name__ == '__main__':
unittest.main()