Skip to content

Commit

Permalink
Merge pull request #4 from 4Subsea/location_null_bug
Browse files Browse the repository at this point in the history
fix: handle "null" locations
  • Loading branch information
vegard-solum-4ss authored Jan 4, 2021
2 parents 1805cc0 + 05c085c commit a022087
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fourinsight/campaigns/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def __call__(self, dct):
except (AttributeError, ValueError):
dct_update[key] = value
else:
dct_update[key] = (float(val1), float(val2))
dct_update[key] = (
None if val1 == "null" else float(val1),
None if val2 == "null" else float(val2),
)
dct.update(dct_update)

# Remove when endpoints start returning native values
Expand Down
30 changes: 30 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,36 @@ def test_location(self):
dict_out = json.loads(json_str, object_hook=json_special_hook)
assert dict_expected == dict_out

def test_location_null(self):
json_str = """{
"a_location": "null#null",
"b_other": "something",
"nested": [
{
"nested_location_1": "null#10.11",
"nested_location_2": "12.13#null"
}
]
}"""

dict_expected = {
"a_location": (None, None),
"b_other": "something",
"nested": [
{
"nested_location_1": (None, 10.11),
"nested_location_2": (12.13, None),
}
],
}

json_special_hook = JSONSpecialParse(
location_keys=("a_location", "nested_location_1", "nested_location_2")
)

dict_out = json.loads(json_str, object_hook=json_special_hook)
assert dict_expected == dict_out

def test_numbers(self):
"""Deprecate when REST API endpoint starts returning native values"""
json_str = """{
Expand Down

0 comments on commit a022087

Please sign in to comment.