-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
358 lines (267 loc) · 12.3 KB
/
test.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import unittest
import li
from li.exceptions import DocTypeException, DocIDException
class LITestSequence(unittest.TestCase):
def setup(self):
pass
def test_for_valid_document_id(self):
"""Tests that an invalid doc_id throws
an exception
"""
with self.assertRaises(DocIDException):
li.get_license({'a': 'b'})
def test_for_valid_document_type(self):
"""Tests that an invalid doc_type
throws an exeception
"""
with self.assertRaises(DocTypeException):
li.get_documents('foo')
with self.assertRaises(DocTypeException):
li.get_document('foo', '000000')
def test_get_appeal_hearing(self):
"""Returns details for a single appeal hearing
"""
response = li.get_appeal_hearing('5')
self.assertEqual(type(response['results']), dict)
self.assertTrue('appeal_hearing_id' in response['results'].keys())
def test_get_appeal_hearings(self):
"""Returns the first 1,000 most recent appeal hearings
"""
response = li.get_appeal_hearings()
self.assertEqual(type(response['results']), list)
self.assertEqual(len(response['results']), 1000)
for result in response['results']:
self.assertTrue('appeal_hearing_id' in result.keys())
def test_get_building_board_appeal(self):
"""Returns details for a single building board appeal
"""
response = li.get_building_board_appeal('593403')
self.assertEqual(type(response['results']), dict)
self.assertTrue('appeal_id' in response['results'].keys())
def test_get_building_board_appeals(self):
"""Returns the first 1,000 most building board appeals
"""
response = li.get_building_board_appeals()
self.assertEqual(type(response['results']), list)
self.assertGreater(len(response['results']), 500)
for result in response['results']:
self.assertTrue('appeal_id' in result.keys())
def test_get_case(self):
"""Returns details for a single case
"""
response = li.get_case('0203312')
self.assertEqual(type(response['results']), dict)
self.assertTrue('case_number' in response['results'].keys())
def test_get_cases(self):
"""Returns the first 1,000 most recent cases
"""
response = li.get_cases()
self.assertEqual(type(response['results']), list)
self.assertEqual(len(response['results']), 1000)
for result in response['results']:
self.assertTrue('case_number' in result.keys())
def test_get_contractor(self):
"""Returns details for a single contractor
"""
response = li.get_contractor('10210')
self.assertEqual(type(response['results']), dict)
self.assertTrue('licensed_contractor_id' in response['results'].keys())
def test_get_contractors(self):
"""Returns the first 1,000 licensed contractors
"""
response = li.get_contractors()
self.assertEqual(type(response['results']), list)
self.assertEqual(len(response['results']), 1000)
for result in response['results']:
self.assertTrue('licensed_contractor_id' in result.keys())
def test_get_hearing_date(self):
"""Returns details for a single hearing date
"""
response = li.get_hearing_date('2009-04-29')
self.assertEqual(type(response), dict)
self.assertTrue('hearing_id' in response['results'].keys())
def test_get_hearing_dates(self):
"""Returns the first 1,000 most recent licenses
"""
response = li.get_hearing_dates()
self.assertEqual(type(response['results']), list)
self.assertEqual(len(response['results']), 1000)
for result in response['results']:
self.assertTrue('hearing_id' in result.keys())
def test_get_license(self):
"""Returns details for a single license
"""
response = li.get_license('015020')
self.assertEqual(type(response['results']), dict)
self.assertTrue('license_number' in response['results'].keys())
def test_get_licenses(self):
"""Returns the first 1,000 most recent licenses
"""
response = li.get_licenses()
self.assertEqual(type(response['results']), list)
self.assertEqual(len(response['results']), 1000)
for result in response['results']:
self.assertTrue('license_number' in result.keys())
def test_get_location(self):
"""Returns details for a single location
"""
response = li.get_location('333710')
self.assertEqual(type(response['results']), dict)
self.assertTrue('location_id' in response['results'].keys())
def test_get_locations(self):
"""Returns the first 1,000 locations, ordered by location_id
"""
response = li.get_locations()
self.assertEqual(type(response['results']), list)
self.assertEqual(len(response['results']), 1000)
for result in response['results']:
self.assertTrue('location_id' in result.keys())
def test_get_li_review_board_appeal(self):
"""Returns details for a single li review board appeal
"""
response = li.get_li_review_board_appeal('593634')
self.assertEqual(type(response['results']), dict)
self.assertTrue('appeal_id' in response['results'].keys())
def test_get_li_review_board_appeals(self):
"""Returns the first 1,000 most recent li review board
appeals
"""
response = li.get_li_review_board_appeals()
self.assertEqual(type(response['results']), list)
self.assertEqual(len(response['results']), 1000)
for result in response['results']:
self.assertTrue('appeal_id' in result.keys())
def test_get_permit(self):
"""Returns details for a single permit
"""
response = li.get_permit('333274')
self.assertEqual(type(response['results']), dict)
self.assertTrue('permit_type_code' in response['results'].keys())
def test_get_permits(self):
"""Returns the first 1,000 most recent permits
"""
response = li.get_permits()
self.assertEqual(type(response['results']), list)
self.assertEqual(len(response['results']), 1000)
for result in response['results']:
self.assertTrue('permit_number' in result.keys())
def test_get_violation(self):
"""Returns details for a single violation
"""
response = li.get_violation('3941')
self.assertEqual(type(response['results']), dict)
self.assertTrue('violation_details_id' in response['results'].keys())
def test_get_violations(self):
"""Returns the first 1,000 most recent violations
"""
response = li.get_violations()
self.assertEqual(type(response['results']), list)
self.assertEqual(len(response['results']), 1000)
for result in response['results']:
self.assertTrue('violation_details_id' in result.keys())
def test_get_zoning_board_appeal(self):
"""Returns details for a single zoning board appeal
"""
response = li.get_zoning_board_appeal('593142')
self.assertEqual(type(response['results']), dict)
self.assertTrue('appeal_id' in response['results'].keys())
def test_get_zoning_board_appeals(self):
"""Returns the first 1,000 most recent zoning board appeals
"""
response = li.get_zoning_board_appeals()
self.assertEqual(type(response['results']), list)
self.assertEqual(len(response['results']), 1000)
for result in response['results']:
self.assertTrue('appeal_id' in result.keys())
def test_get_permit_with_related(self):
"""Returns details for a specific permit,
with the related documents retrieved
"""
response = li.get_permit('333274', related=True)
self.assertEqual(type(response['results']), dict)
self.assertTrue('permit_type_code' in response['results'].keys())
self.assertTrue('results' in response['results']['zoningboardappeals'].keys())
self.assertTrue('street_name' in response['results']['locations'].keys())
self.assertTrue('results' in response['results']['buildingboardappeals'].keys())
def test_get_location_with_related(self):
"""Returns details for a specific locations,
with the related documents retrieved
"""
response = li.get_location('333710', related=True)
self.assertEqual(type(response['results']), dict)
self.assertTrue('location_id' in response['results'].keys())
self.assertTrue('results' in response['results']['zoningboardappeals'].keys())
self.assertTrue('results' in response['results']['lireviewboardappeals'].keys())
self.assertTrue('results' in response['results']['buildingboardappeals'].keys())
self.assertTrue('results' in response['results']['appealhearings'].keys())
self.assertTrue('results' in response['results']['cases'].keys())
self.assertTrue('results' in response['results']['permits'].keys())
self.assertTrue('results' in response['results']['licenses'].keys())
self.assertTrue('results' in response['results']['violationdetails'].keys())
def test_get_licenses_with_related(self):
"""Returns details for a specific permit,
with the related documents retrieved
"""
response = li.get_license('015020', related=True)
self.assertEqual(type(response['results']), dict)
self.assertTrue('license_number' in response['results'].keys())
self.assertTrue('street_name' in response['results']['locations'].keys())
def test_get_permits_with_raw_sql_filter(self):
"""Allows the user to directly pass the $filter as
as a ODATA SQL statement rather than passing a dict
of params that is constructed into a ODATA SQL statement
"""
sql = "application_type eq 'ZP_ZONING'"
response = li.get_permits(filter=sql)
for result in response['results']:
self.assertEqual(result['application_type'], 'ZP_ZONING')
def test_top_param(self):
"""The $top query parameter limits the request results
to the number value of $top
"""
response = li.get_permits(top=10)
self.assertEqual(len(response['results']), 10)
response = li.get_licenses(top=140)
self.assertEqual(len(response['results']), 140)
response = li.get_contractors(top=0)
self.assertEqual(len(response['results']), 0)
def test_inlinecount_query_param(self):
"""$inlinecount=allpages adds a '__count' key to the
results with the total count of documents
"""
response = li.get_permits(inlinecount='allpages')
self.assertTrue(response['count'] is not None)
def test_expand_query_param(self):
"""$expand retrieves related document details. Only
works for locations at the moment. API throws a
SQL error otherwise
"""
response = li.get_permits(expand='locations')
self.assertTrue('street_name' in response['results'][0]['locations'])
def test_count_param_true(self):
"""Count is a convienent way to specify the
$inlinecount query param with 'allpages' as the value
"""
# if count is True, count should be set to a number
response = li.get_permits(count=True)
self.assertTrue(response['count'] is not None)
self.assertTrue(type(response['count']) is int)
def test_count_param_false(self):
"""Count is a convienent way to specify the
$inlinecount query param with 'allpages' as the value
"""
# if count is False, or not specified, the
# return value of count should be None
response = li.get_permits(count=False)
self.assertTrue(response['count'] is None)
response = li.get_permits()
self.assertTrue(response['count'] is None)
def test_api_error(self):
"""Passing a bogus query to the API should
give us an error message stored at response['error']
"""
sql = 'a bunch of stuff'
response = li.get_permits(filter=sql)
self.assertTrue('error' in response)
if __name__ == '__main__':
unittest.main()