Skip to content

Commit e3986bb

Browse files
committed
Use ordereddict for easier index-validation
1 parent ff23df2 commit e3986bb

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

tests/conftest.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
import json
33
import os
4+
import collections
45

56
import pytest
67

@@ -23,7 +24,7 @@ def validator(data_json):
2324
Returns the original json (pass-through)
2425
"""
2526
fields = spec["fields"]
26-
data = json.loads(data_json)
27+
data = json.loads(data_json, object_pairs_hook=collections.OrderedDict)
2728
for k, v in fields.items():
2829
if v.get("required"):
2930
found = False
@@ -57,15 +58,8 @@ def validator(data_json):
5758
data[k], k
5859
)
5960
)
60-
if v.get("index"):
61-
index = v.get("index")
62-
key = json.loads(
63-
data_json.split(",")[index].split(":")[0].strip().lstrip("{")
64-
)
65-
if key != k:
66-
raise ValidationError(
67-
"Key {0} is not at index {1}".format(k, index)
68-
)
61+
if v.get("index") and list(data.keys())[v.get("index")] != k:
62+
raise ValidationError("Key {0} is not at index {1}".format(k, index))
6963

7064
return data_json
7165

0 commit comments

Comments
 (0)