Skip to content

Commit

Permalink
Merge pull request #19 from newmediadenver/unknown
Browse files Browse the repository at this point in the history
Adding support for allow_unknown and updating tests.
  • Loading branch information
ultimateboy committed Oct 13, 2015
2 parents 06e99e9 + 5c10366 commit 0884345
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ Create a json file, `sample.json`:
"sample-resource2": {
"sample-object-id": "objectid:sample-resource",
"sample-intrange": "1-100",
"sample-floatrange": "0.0-1.0"
"sample-floatrange": "0.0-1.0",
"sample-unknown": {
"allow_unknown": true
}
}
}
```
Expand Down Expand Up @@ -96,6 +99,9 @@ sample-resource2 = {
'embeddable': True
}
},
'sample-unknown': {
'allow_unknown': True
},
'sample-intrange': {
'max': 100,
'type': 'integer',
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Certain strings passed in via the source json will be converted to eve schema ty
- `"fieldname": "objectid:sample-entity"` will add data_relation to sample-entity to the schema
- `"fieldname": "0-100"` will create an integer with a min of 0 and a max of 100
- `"fieldname": "0.0-1.0"` will create a float with a min of 0 and a max of 1
- `"fieldname": {"allow_unknown": true}` will translate directly to fieldname that allows the unknown

## Test

Expand Down
6 changes: 6 additions & 0 deletions evegenie/evegenie.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def parse_item(self, endpoint_item):
item['schema'] = {}
for k, i in endpoint_item.iteritems():
item['schema'][k] = self.parse_item(i)

# if allow_unknown, remove the type and set allow_unknown.
if k == 'allow_unknown' and isinstance(i, bool):
del item['schema']
del item['type']
item[k] = i
elif item['type'] == 'list':
# recursively parse each item in a list and add to item schema
item['schema'] = {}
Expand Down
6 changes: 6 additions & 0 deletions tests/.test_out_control
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ user = {
}
}
},
'attributes': {
'allow_unknown': True
},
'inventory': {
'type': 'list',
'schema': {
Expand Down Expand Up @@ -88,6 +91,9 @@ artifact = {
'strike': {
'type': 'integer'
},
'extra_powers': {
'allow_unknown': True
},
'speed': {
'type': 'integer'
},
Expand Down
6 changes: 6 additions & 0 deletions tests/egtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
'attack_bonus': '1-10',
'difficulty': '0.0-1.0',
'attributes': {'allow_unknown': True},
},
'artifact': {
'name': 'Sword of Speed',
Expand All @@ -44,6 +45,7 @@
'length': 3.01,
'powers': {
'strike': 1,
'extra_powers': {'allow_unknown': True},
'deflect': 1,
'speed': 3,
},
Expand Down Expand Up @@ -115,6 +117,9 @@
'max': 1.0,
'min': 0.0,
'type': 'float'
},
'attributes': {
'allow_unknown': True
}
}
},
Expand All @@ -140,6 +145,7 @@
'strike': {'type': 'integer'},
'deflect': {'type': 'integer'},
'speed': {'type': 'integer'},
'extra_powers': {'allow_unknown': True}
}
},
}
Expand Down
14 changes: 10 additions & 4 deletions tests/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"state": "wet"
},
"attack_bonus": "1-10",
"difficulty": "0.0-1.0"
"difficulty": "0.0-1.0",
"attributes": {
"allow_unknown": true
}
},
"artifact": {
"name": "Sword of Speed",
Expand All @@ -24,9 +27,12 @@
"weight": 200.01,
"length": 3.01,
"powers": {
"strike": 1,
"deflect": 1,
"speed": 3
"strike": 1,
"extra_powers": {
"allow_unknown": true
},
"deflect": 1,
"speed": 3
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions tests/testrecursion.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
},
"objectid": "objectid:testentity2",
"string": "Hello World",
"unknown": {
"allow_unknown": true
},
"embedded1": {
"array1": [1, 2, 3],
"array2": ["a", "b", "c"],
Expand All @@ -29,7 +32,10 @@
"e": "f"
},
"objectid": "objectid:testentity2",
"string": "Hello World"
"string": "Hello World",
"unknown": {
"allow_unknown": true
}
}
},
"embedded2": [
Expand All @@ -49,7 +55,10 @@
"e": "f"
},
"objectid": "objectid:testentity2",
"string": "Hello World"
"string": "Hello World",
"unknown": {
"allow_unknown": true
}
}
}
]
Expand Down

0 comments on commit 0884345

Please sign in to comment.