Skip to content

Commit c43e3fd

Browse files
authored
Merge pull request #6 from A-Baji/jeroen-pr-update
remove force get_json
2 parents 440a493 + 2f65ada commit c43e3fd

File tree

2 files changed

+54
-46
lines changed

2 files changed

+54
-46
lines changed

pharus/component_interface.py

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,16 @@ def dj_query_route(self):
129129
limit=int(request.args["limit"]) if "limit" in request.args else 1000,
130130
page=int(request.args["page"]) if "page" in request.args else 1,
131131
)
132-
return NumpyEncoder.dumps(
133-
dict(
134-
recordHeader=record_header,
135-
records=table_records,
136-
totalCount=total_count,
137-
)
132+
return (
133+
NumpyEncoder.dumps(
134+
dict(
135+
recordHeader=record_header,
136+
records=table_records,
137+
totalCount=total_count,
138+
)
139+
),
140+
200,
141+
{"Content-Type": "application/json"},
138142
)
139143

140144

@@ -299,23 +303,31 @@ def dj_query_route(self):
299303
order=request.args["order"].split(",") if "order" in request.args else None,
300304
)
301305

302-
return NumpyEncoder.dumps(
303-
dict(
304-
recordHeader=record_header,
305-
records=table_records,
306-
totalCount=total_count,
307-
)
306+
return (
307+
NumpyEncoder.dumps(
308+
dict(
309+
recordHeader=record_header,
310+
records=table_records,
311+
totalCount=total_count,
312+
)
313+
),
314+
200,
315+
{"Content-Type": "application/json"},
308316
)
309317

310318
def attributes_route(self):
311319
attributes_meta = _DJConnector._get_attributes(
312320
self.fetch_metadata["query"] & self.restriction, include_unique_values=True
313321
)
314-
return NumpyEncoder.dumps(
315-
dict(
316-
attributeHeaders=attributes_meta["attribute_headers"],
317-
attributes=attributes_meta["attributes"],
318-
)
322+
return (
323+
NumpyEncoder.dumps(
324+
dict(
325+
attributeHeaders=attributes_meta["attribute_headers"],
326+
attributes=attributes_meta["attributes"],
327+
)
328+
),
329+
200,
330+
{"Content-Type": "application/json"},
319331
)
320332

321333

@@ -359,12 +371,16 @@ def dj_query_route(self):
359371
query=fetch_metadata["query"] & self.restriction,
360372
fetch_args=fetch_metadata["fetch_args"],
361373
)
362-
return NumpyEncoder.dumps(
363-
dict(
364-
recordHeader=record_header,
365-
records=table_records,
366-
totalCount=total_count,
367-
)
374+
return (
375+
NumpyEncoder.dumps(
376+
dict(
377+
recordHeader=record_header,
378+
records=table_records,
379+
totalCount=total_count,
380+
)
381+
),
382+
200,
383+
{"Content-Type": "application/json"},
368384
)
369385

370386

@@ -390,10 +406,14 @@ def __init__(self, *args, **kwargs):
390406

391407
def dj_query_route(self):
392408
fetch_metadata = self.fetch_metadata
393-
return NumpyEncoder.dumps(
394-
(fetch_metadata["query"] & self.restriction).fetch1(
395-
*fetch_metadata["fetch_args"]
396-
)
409+
return (
410+
NumpyEncoder.dumps(
411+
(fetch_metadata["query"] & self.restriction).fetch1(
412+
*fetch_metadata["fetch_args"]
413+
)
414+
),
415+
200,
416+
{"Content-Type": "application/json"},
397417
)
398418

399419

tests/test_api_gen.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,10 @@ def test_auto_generated_route(token, client, schemas_simple):
3131
}
3232
)
3333

34-
assert expected_json == json.dumps(
35-
REST_response1.get_json(force=True), sort_keys=True
36-
)
37-
assert expected_json == json.dumps(
38-
REST_response2.get_json(force=True), sort_keys=True
39-
)
40-
assert expected_json == json.dumps(
41-
REST_response3.get_json(force=True), sort_keys=True
42-
)
43-
assert expected_json == json.dumps(
44-
REST_response4.get_json(force=True), sort_keys=True
45-
)
34+
assert expected_json == json.dumps(REST_response1.get_json(), sort_keys=True)
35+
assert expected_json == json.dumps(REST_response2.get_json(), sort_keys=True)
36+
assert expected_json == json.dumps(REST_response3.get_json(), sort_keys=True)
37+
assert expected_json == json.dumps(REST_response4.get_json(), sort_keys=True)
4638

4739

4840
def test_get_full_plot(token, client, schemas_simple):
@@ -63,9 +55,7 @@ def test_get_full_plot(token, client, schemas_simple):
6355
),
6456
sort_keys=True,
6557
)
66-
assert expected_json == json.dumps(
67-
REST_response1.get_json(force=True), sort_keys=True
68-
)
58+
assert expected_json == json.dumps(REST_response1.get_json(), sort_keys=True)
6959

7060

7161
def test_get_attributes(token, client, schemas_simple):
@@ -126,7 +116,7 @@ def test_get_attributes(token, client, schemas_simple):
126116
},
127117
}
128118

129-
assert expected_json == REST_response.get_json(force=True)
119+
assert expected_json == REST_response.get_json()
130120

131121

132122
def test_dynamic_restriction(token, client, schemas_simple):
@@ -139,6 +129,4 @@ def test_dynamic_restriction(token, client, schemas_simple):
139129
"totalCount": 2,
140130
}
141131
)
142-
assert expected_json == json.dumps(
143-
REST_response.get_json(force=True), sort_keys=True
144-
)
132+
assert expected_json == json.dumps(REST_response.get_json(), sort_keys=True)

0 commit comments

Comments
 (0)