Skip to content

Commit cd213c1

Browse files
committed
ran all the test code through flake8
1 parent a584cde commit cd213c1

File tree

5 files changed

+456
-435
lines changed

5 files changed

+456
-435
lines changed

test/cbapi/psc/livequery/test_models.py

Lines changed: 94 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -8,106 +8,106 @@
88

99
def test_run_refresh(monkeypatch):
1010
_was_called = False
11-
11+
1212
def mock_get_object(url, parms=None, default=None):
1313
nonlocal _was_called
1414
assert url == "/livequery/v1/orgs/Z100/runs/abcdefg"
1515
assert parms is None
1616
assert default is None
1717
_was_called = True
18-
return {"org_key":"Z100", "name":"FoobieBletch",
19-
"id":"abcdefg", "status":"COMPLETE"}
20-
18+
return {"org_key": "Z100", "name": "FoobieBletch",
19+
"id": "abcdefg", "status": "COMPLETE"}
20+
2121
api = CbLiveQueryAPI(url="https://example.com", token="ABCD/1234",
2222
org_key="Z100", ssl_verify=True)
23-
run = Run(api, "abcdefg", {"org_key":"Z100", "name":"FoobieBletch",
24-
"id":"abcdefg", "status":"ACTIVE"})
23+
run = Run(api, "abcdefg", {"org_key": "Z100", "name": "FoobieBletch",
24+
"id": "abcdefg", "status": "ACTIVE"})
2525
monkeypatch.setattr(api, "get_object", mock_get_object)
2626
monkeypatch.setattr(api, "post_object", ConnectionMocks.get("POST"))
2727
monkeypatch.setattr(api, "put_object", ConnectionMocks.get("PUT"))
2828
monkeypatch.setattr(api, "delete_object", ConnectionMocks.get("DELETE"))
2929
rc = run.refresh()
3030
assert _was_called
31-
assert rc == True
31+
assert rc
3232
assert run.org_key == "Z100"
3333
assert run.name == "FoobieBletch"
3434
assert run.id == "abcdefg"
3535
assert run.status == "COMPLETE"
36-
37-
36+
37+
3838
def test_run_stop(monkeypatch):
3939
_was_called = False
40-
40+
4141
def mock_put_object(url, body, **kwargs):
4242
nonlocal _was_called
4343
assert url == "/livequery/v1/orgs/Z100/runs/abcdefg/status"
4444
assert body["status"] == "CANCELLED"
4545
_was_called = True
46-
return MockResponse({"org_key":"Z100", "name":"FoobieBletch",
47-
"id":"abcdefg", "status":"CANCELLED"})
48-
46+
return MockResponse({"org_key": "Z100", "name": "FoobieBletch",
47+
"id": "abcdefg", "status": "CANCELLED"})
48+
4949
api = CbLiveQueryAPI(url="https://example.com", token="ABCD/1234",
5050
org_key="Z100", ssl_verify=True)
51-
run = Run(api, "abcdefg", {"org_key":"Z100", "name":"FoobieBletch",
52-
"id":"abcdefg", "status":"ACTIVE"})
51+
run = Run(api, "abcdefg", {"org_key": "Z100", "name": "FoobieBletch",
52+
"id": "abcdefg", "status": "ACTIVE"})
5353
monkeypatch.setattr(api, "get_object", ConnectionMocks.get("GET"))
5454
monkeypatch.setattr(api, "post_object", ConnectionMocks.get("POST"))
5555
monkeypatch.setattr(api, "put_object", mock_put_object)
5656
monkeypatch.setattr(api, "delete_object", ConnectionMocks.get("DELETE"))
5757
rc = run.stop()
5858
assert _was_called
59-
assert rc == True
59+
assert rc
6060
assert run.org_key == "Z100"
6161
assert run.name == "FoobieBletch"
6262
assert run.id == "abcdefg"
6363
assert run.status == "CANCELLED"
6464

65-
65+
6666
def test_run_stop_failed(monkeypatch):
6767
_was_called = False
68-
68+
6969
def mock_put_object(url, body, **kwargs):
7070
nonlocal _was_called
7171
assert url == "/livequery/v1/orgs/Z100/runs/abcdefg/status"
7272
assert body["status"] == "CANCELLED"
7373
_was_called = True
74-
return MockResponse({"error_message":"The query is not presently running."}, 409)
75-
74+
return MockResponse({"error_message": "The query is not presently running."}, 409)
75+
7676
api = CbLiveQueryAPI(url="https://example.com", token="ABCD/1234",
7777
org_key="Z100", ssl_verify=True)
78-
run = Run(api, "abcdefg", {"org_key":"Z100", "name":"FoobieBletch",
79-
"id":"abcdefg", "status":"CANCELLED"})
78+
run = Run(api, "abcdefg", {"org_key": "Z100", "name": "FoobieBletch",
79+
"id": "abcdefg", "status": "CANCELLED"})
8080
monkeypatch.setattr(api, "get_object", ConnectionMocks.get("GET"))
8181
monkeypatch.setattr(api, "post_object", ConnectionMocks.get("POST"))
8282
monkeypatch.setattr(api, "put_object", mock_put_object)
8383
monkeypatch.setattr(api, "delete_object", ConnectionMocks.get("DELETE"))
8484
rc = run.stop()
8585
assert _was_called
86-
assert rc == False
87-
88-
86+
assert not rc
87+
88+
8989
def test_run_delete(monkeypatch):
9090
_was_called = False
91-
91+
9292
def mock_delete_object(url):
9393
nonlocal _was_called
9494
if _was_called:
9595
pytest.fail("delete should not be called twice!")
9696
assert url == "/livequery/v1/orgs/Z100/runs/abcdefg"
9797
_was_called = True
9898
return MockResponse(None)
99-
99+
100100
api = CbLiveQueryAPI(url="https://example.com", token="ABCD/1234",
101101
org_key="Z100", ssl_verify=True)
102-
run = Run(api, "abcdefg", {"org_key":"Z100", "name":"FoobieBletch",
103-
"id":"abcdefg", "status":"ACTIVE"})
102+
run = Run(api, "abcdefg", {"org_key": "Z100", "name": "FoobieBletch",
103+
"id": "abcdefg", "status": "ACTIVE"})
104104
monkeypatch.setattr(api, "get_object", ConnectionMocks.get("GET"))
105105
monkeypatch.setattr(api, "post_object", ConnectionMocks.get("POST"))
106106
monkeypatch.setattr(api, "put_object", ConnectionMocks.get("PUT"))
107107
monkeypatch.setattr(api, "delete_object", mock_delete_object)
108108
rc = run.delete()
109109
assert _was_called
110-
assert rc == True
110+
assert rc
111111
assert run._is_deleted
112112
# Now ensure that certain operations that don't make sense on a deleted object raise ApiError
113113
with pytest.raises(ApiError):
@@ -116,31 +116,31 @@ def mock_delete_object(url):
116116
run.stop()
117117
# And make sure that deleting a deleted object returns True immediately
118118
rc = run.delete()
119-
assert rc == True
120-
121-
119+
assert rc
120+
121+
122122
def test_run_delete_failed(monkeypatch):
123123
_was_called = False
124-
124+
125125
def mock_delete_object(url):
126126
nonlocal _was_called
127127
assert url == "/livequery/v1/orgs/Z100/runs/abcdefg"
128128
_was_called = True
129129
return MockResponse(None, 403)
130-
130+
131131
api = CbLiveQueryAPI(url="https://example.com", token="ABCD/1234",
132132
org_key="Z100", ssl_verify=True)
133-
run = Run(api, "abcdefg", {"org_key":"Z100", "name":"FoobieBletch",
134-
"id":"abcdefg", "status":"ACTIVE"})
133+
run = Run(api, "abcdefg", {"org_key": "Z100", "name": "FoobieBletch",
134+
"id": "abcdefg", "status": "ACTIVE"})
135135
monkeypatch.setattr(api, "get_object", ConnectionMocks.get("GET"))
136136
monkeypatch.setattr(api, "post_object", ConnectionMocks.get("POST"))
137137
monkeypatch.setattr(api, "put_object", ConnectionMocks.get("PUT"))
138138
monkeypatch.setattr(api, "delete_object", mock_delete_object)
139139
rc = run.delete()
140140
assert _was_called
141-
assert rc == False
141+
assert not rc
142142
assert not run._is_deleted
143-
143+
144144

145145
def test_result_device_summaries(monkeypatch):
146146
_was_called = False
@@ -155,22 +155,22 @@ def mock_post_object(url, body, **kwargs):
155155
assert t["field"] == "device_name"
156156
assert t["order"] == "ASC"
157157
_was_called = True
158-
metrics = [{"key":"aaa", "value":0.0}, {"key":"bbb", "value":0.0}]
159-
res1 = {"id":"ghijklm", "total_results":2, "device_id":314159, "metrics":metrics}
160-
res2 = {"id":"mnopqrs", "total_results":3, "device_id":271828, "metrics":metrics}
161-
return MockResponse({"org_key":"Z100", "num_found":2, "results":[res1, res2]})
162-
158+
metrics = [{"key": "aaa", "value": 0.0}, {"key": "bbb", "value": 0.0}]
159+
res1 = {"id": "ghijklm", "total_results": 2, "device_id": 314159, "metrics": metrics}
160+
res2 = {"id": "mnopqrs", "total_results": 3, "device_id": 271828, "metrics": metrics}
161+
return MockResponse({"org_key": "Z100", "num_found": 2, "results": [res1, res2]})
162+
163163
api = CbLiveQueryAPI(url="https://example.com", token="ABCD/1234",
164164
org_key="Z100", ssl_verify=True)
165-
tmp_id = {"id":"abcdefg"}
166-
result = Result(api, {"id": "abcdefg", "device":tmp_id, "fields":{}, "metrics":{}})
165+
tmp_id = {"id": "abcdefg"}
166+
result = Result(api, {"id": "abcdefg", "device": tmp_id, "fields": {}, "metrics": {}})
167167
monkeypatch.setattr(api, "get_object", ConnectionMocks.get("GET"))
168168
monkeypatch.setattr(api, "post_object", mock_post_object)
169169
monkeypatch.setattr(api, "put_object", ConnectionMocks.get("PUT"))
170170
monkeypatch.setattr(api, "delete_object", ConnectionMocks.get("DELETE"))
171171
query = result.query_device_summaries().where("foo").criteria(device_name=["AxCx", "A7X"])
172172
query = query.sort_by("device_name")
173-
assert isinstance(query, ResultQuery)
173+
assert isinstance(query, ResultQuery)
174174
count = 0
175175
for item in query.all():
176176
if item.id == "ghijklm":
@@ -184,8 +184,8 @@ def mock_post_object(url, body, **kwargs):
184184
count = count + 1
185185
assert _was_called
186186
assert count == 2
187-
188-
187+
188+
189189
def test_result_query_result_facets(monkeypatch):
190190
_was_called = False
191191

@@ -198,51 +198,51 @@ def mock_post_object(url, body, **kwargs):
198198
t = body["terms"]
199199
assert t["fields"] == ["alpha", "bravo", "charlie"]
200200
_was_called = True
201-
v1 = {"total":1, "id":"alpha1", "name":"alpha1"}
202-
v2 = {"total":2, "id":"alpha2", "name":"alpha2"}
203-
term1 = {"field":"alpha", "values":[v1, v2]}
204-
v1 = {"total":1, "id":"bravo1", "name":"bravo1"}
205-
v2 = {"total":2, "id":"bravo2", "name":"bravo2"}
206-
term2 = {"field":"bravo", "values":[v1, v2]}
207-
v1 = {"total":1, "id":"charlie1", "name":"charlie1"}
208-
v2 = {"total":2, "id":"charlie2", "name":"charlie2"}
209-
term3 = {"field":"charlie", "values":[v1, v2]}
210-
return MockResponse({"terms":[term1, term2, term3]})
211-
201+
v1 = {"total": 1, "id": "alpha1", "name": "alpha1"}
202+
v2 = {"total": 2, "id": "alpha2", "name": "alpha2"}
203+
term1 = {"field": "alpha", "values": [v1, v2]}
204+
v1 = {"total": 1, "id": "bravo1", "name": "bravo1"}
205+
v2 = {"total": 2, "id": "bravo2", "name": "bravo2"}
206+
term2 = {"field": "bravo", "values": [v1, v2]}
207+
v1 = {"total": 1, "id": "charlie1", "name": "charlie1"}
208+
v2 = {"total": 2, "id": "charlie2", "name": "charlie2"}
209+
term3 = {"field": "charlie", "values": [v1, v2]}
210+
return MockResponse({"terms": [term1, term2, term3]})
211+
212212
api = CbLiveQueryAPI(url="https://example.com", token="ABCD/1234",
213213
org_key="Z100", ssl_verify=True)
214-
tmp_id = {"id":"abcdefg"}
215-
result = Result(api, {"id": "abcdefg", "device":tmp_id, "fields":{}, "metrics":{}})
214+
tmp_id = {"id": "abcdefg"}
215+
result = Result(api, {"id": "abcdefg", "device": tmp_id, "fields": {}, "metrics": {}})
216216
monkeypatch.setattr(api, "get_object", ConnectionMocks.get("GET"))
217217
monkeypatch.setattr(api, "post_object", mock_post_object)
218218
monkeypatch.setattr(api, "put_object", ConnectionMocks.get("PUT"))
219219
monkeypatch.setattr(api, "delete_object", ConnectionMocks.get("DELETE"))
220220
query = result.query_result_facets().where("xyzzy")
221221
query = query.facet_field("alpha").facet_field(["bravo", "charlie"])
222-
query = query.criteria(device_name=["AxCx", "A7X"])
222+
query = query.criteria(device_name=["AxCx", "A7X"])
223223
assert isinstance(query, FacetQuery)
224224
count = 0
225225
for item in query.all():
226226
vals = item.values
227227
if item.field == "alpha":
228-
assert vals[0]["id"] == "alpha1"
229-
assert vals[1]["id"] == "alpha2"
228+
assert vals[0]["id"] == "alpha1"
229+
assert vals[1]["id"] == "alpha2"
230230
elif item.field == "bravo":
231-
assert vals[0]["id"] == "bravo1"
232-
assert vals[1]["id"] == "bravo2"
231+
assert vals[0]["id"] == "bravo1"
232+
assert vals[1]["id"] == "bravo2"
233233
elif item.field == "charlie":
234-
assert vals[0]["id"] == "charlie1"
235-
assert vals[1]["id"] == "charlie2"
234+
assert vals[0]["id"] == "charlie1"
235+
assert vals[1]["id"] == "charlie2"
236236
else:
237-
pytest.fail("Unknown field name %s seen" % item.field)
237+
pytest.fail("Unknown field name %s seen" % item.field)
238238
count = count + 1
239239
assert _was_called
240240
assert count == 3
241-
242-
241+
242+
243243
def test_result_query_device_summary_facets(monkeypatch):
244244
_was_called = False
245-
245+
246246
def mock_post_object(url, body, **kwargs):
247247
nonlocal _was_called
248248
assert url == "/livequery/v1/orgs/Z100/runs/abcdefg/results/device_summaries/_facet"
@@ -252,43 +252,43 @@ def mock_post_object(url, body, **kwargs):
252252
t = body["terms"]
253253
assert t["fields"] == ["alpha", "bravo", "charlie"]
254254
_was_called = True
255-
v1 = {"total":1, "id":"alpha1", "name":"alpha1"}
256-
v2 = {"total":2, "id":"alpha2", "name":"alpha2"}
257-
term1 = {"field":"alpha", "values":[v1, v2]}
258-
v1 = {"total":1, "id":"bravo1", "name":"bravo1"}
259-
v2 = {"total":2, "id":"bravo2", "name":"bravo2"}
260-
term2 = {"field":"bravo", "values":[v1, v2]}
261-
v1 = {"total":1, "id":"charlie1", "name":"charlie1"}
262-
v2 = {"total":2, "id":"charlie2", "name":"charlie2"}
263-
term3 = {"field":"charlie", "values":[v1, v2]}
264-
return MockResponse({"terms":[term1, term2, term3]})
265-
255+
v1 = {"total": 1, "id": "alpha1", "name": "alpha1"}
256+
v2 = {"total": 2, "id": "alpha2", "name": "alpha2"}
257+
term1 = {"field": "alpha", "values": [v1, v2]}
258+
v1 = {"total": 1, "id": "bravo1", "name": "bravo1"}
259+
v2 = {"total": 2, "id": "bravo2", "name": "bravo2"}
260+
term2 = {"field": "bravo", "values": [v1, v2]}
261+
v1 = {"total": 1, "id": "charlie1", "name": "charlie1"}
262+
v2 = {"total": 2, "id": "charlie2", "name": "charlie2"}
263+
term3 = {"field": "charlie", "values": [v1, v2]}
264+
return MockResponse({"terms": [term1, term2, term3]})
265+
266266
api = CbLiveQueryAPI(url="https://example.com", token="ABCD/1234",
267267
org_key="Z100", ssl_verify=True)
268-
tmp_id = {"id":"abcdefg"}
269-
result = Result(api, {"id": "abcdefg", "device":tmp_id, "fields":{}, "metrics":{}})
268+
tmp_id = {"id": "abcdefg"}
269+
result = Result(api, {"id": "abcdefg", "device": tmp_id, "fields": {}, "metrics": {}})
270270
monkeypatch.setattr(api, "get_object", ConnectionMocks.get("GET"))
271271
monkeypatch.setattr(api, "post_object", mock_post_object)
272272
monkeypatch.setattr(api, "put_object", ConnectionMocks.get("PUT"))
273273
monkeypatch.setattr(api, "delete_object", ConnectionMocks.get("DELETE"))
274274
query = result.query_device_summary_facets().where("xyzzy")
275275
query = query.facet_field("alpha").facet_field(["bravo", "charlie"])
276-
query = query.criteria(device_name=["AxCx", "A7X"])
276+
query = query.criteria(device_name=["AxCx", "A7X"])
277277
assert isinstance(query, FacetQuery)
278278
count = 0
279279
for item in query.all():
280280
vals = item.values
281281
if item.field == "alpha":
282-
assert vals[0]["id"] == "alpha1"
283-
assert vals[1]["id"] == "alpha2"
282+
assert vals[0]["id"] == "alpha1"
283+
assert vals[1]["id"] == "alpha2"
284284
elif item.field == "bravo":
285-
assert vals[0]["id"] == "bravo1"
286-
assert vals[1]["id"] == "bravo2"
285+
assert vals[0]["id"] == "bravo1"
286+
assert vals[1]["id"] == "bravo2"
287287
elif item.field == "charlie":
288-
assert vals[0]["id"] == "charlie1"
289-
assert vals[1]["id"] == "charlie2"
288+
assert vals[0]["id"] == "charlie1"
289+
assert vals[1]["id"] == "charlie2"
290290
else:
291-
pytest.fail("Unknown field name %s seen" % item.field)
291+
pytest.fail("Unknown field name %s seen" % item.field)
292292
count = count + 1
293293
assert _was_called
294294
assert count == 3

0 commit comments

Comments
 (0)