Skip to content

Commit

Permalink
yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
pnwpedro committed Oct 12, 2023
1 parent e92ba07 commit 9318ea9
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 77 deletions.
17 changes: 13 additions & 4 deletions fauna/encoding/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,15 @@ def _encode(o: Any, _markers: Optional[Set] = None):
elif isinstance(o, date):
return {"value": FaunaEncoder.from_date(o)}
elif isinstance(o, Document):
return {"value": FaunaEncoder.from_doc_ref(DocumentReference(o.coll, o.id))}
return {
"value": FaunaEncoder.from_doc_ref(DocumentReference(o.coll, o.id))
}
elif isinstance(o, NamedDocument):
return {"value": FaunaEncoder.from_named_doc_ref(
NamedDocumentReference(o.coll, o.name))}
return {
"value":
FaunaEncoder.from_named_doc_ref(
NamedDocumentReference(o.coll, o.name))
}
elif isinstance(o, NullDocument):
return FaunaEncoder.encode(o.ref)
elif isinstance(o, (list, tuple)):
Expand Down Expand Up @@ -196,4 +201,8 @@ def _encode_dict(dct, markers):
raise ValueError("Circular reference detected")

markers.add(id(dct))
return {"object": {k: FaunaEncoder._encode(v, markers) for k, v in dct.items()}}
return {
"object": {
k: FaunaEncoder._encode(v, markers) for k, v in dct.items()
}
}
29 changes: 26 additions & 3 deletions tests/integration/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,37 @@ def update_doc_by_email(email: str, data: dict):


def test_array_composition(client):
queries = [fql("1"), fql("2"), {"key": 3}, [fql("${inner}", inner={"inner": "thing"})]]
queries = [
fql("1"),
fql("2"), {
"key": 3
}, [fql("${inner}", inner={"inner": "thing"})]
]
q = fql("${queries}", queries=queries)
res = client.query(q).data
assert [1, 2, {'key': 3}, [{'inner': 'thing'}]] == res


def test_object_composition(client):
queries = {1: fql("1"), 2: fql("2"), 3: {"key": fql("3")}, 4: {"inner": fql("${inner}", inner=["inner", "thing"])}}
queries = {
1: fql("1"),
2: fql("2"),
3: {
"key": fql("3")
},
4: {
"inner": fql("${inner}", inner=["inner", "thing"])
}
}
q = fql("${queries}", queries=queries)
res = client.query(q).data
assert {'1': 1, '2': 2, '3': {'key': 3}, '4': {'inner': ['inner', 'thing']}} == res
assert {
'1': 1,
'2': 2,
'3': {
'key': 3
},
'4': {
'inner': ['inner', 'thing']
}
} == res
80 changes: 54 additions & 26 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,15 @@ def complex_typed_object():
}]
}


@pytest.fixture
def complex_wire_encoded_object():
return {
'object': {
'bugs_coll': {
'value': {'@mod': 'Bugs'}
'value': {
'@mod': 'Bugs'
}
},
'bug': {
'value': {
Expand All @@ -164,22 +167,33 @@ def complex_wire_encoded_object():
}
}
},
'name':
{'value': 'fir'},
'name': {
'value': 'fir'
},
'age': {
'value': {'@int': '200'}
'value': {
'@int': '200'
}
},
'birthdate': {
'value': {'@date': '1823-02-08'}
'value': {
'@date': '1823-02-08'
}
},
'molecules': {
'value': {'@long': '999999999999999999'}
'value': {
'@long': '999999999999999999'
}
},
'circumference': {
'value': {'@double': '3.82'}
'value': {
'@double': '3.82'
}
},
'created_at': {
'value': {'@time': '2003-02-08T13:28:12.000555+00:00'}
'value': {
'@time': '2003-02-08T13:28:12.000555+00:00'
}
},
'extras': {
'object': {
Expand All @@ -189,46 +203,60 @@ def complex_wire_encoded_object():
'object': {
'egg': {
'object': {
'fertilized': {'value': False}
'fertilized': {
'value': False
}
}
}
}
},
'num_sticks': {
'value': {'@int': '58'}
'value': {
'@int': '58'
}
},
}
}
}

},
'measurements': {
'array': [{
'object': {
'id': {
'value': {'@int': '1'}
'value': {
'@int': '1'
}
},
'employee': {
'value': {'@int': '3'}
'value': {
'@int': '3'
}
},
'time': {
'value': {'@time': '2013-02-08T12:00:05.000123+00:00'}
'value': {
'@time': '2013-02-08T12:00:05.000123+00:00'
}
}
}
}, {
'object': {
'id': {
'value': {'@int': '2'}
},
'employee': {
'value': {'@int': '5'}
},
'time': {
'value': {'@time': '2023-02-08T14:22:01.000001+00:00'}
}
}
'object': {
'id': {
'value': {
'@int': '2'
}
},
'employee': {
'value': {
'@int': '5'
}
},
'time': {
'value': {
'@time': '2023-02-08T14:22:01.000001+00:00'
}
}
}
}]
}

}
}
Loading

0 comments on commit 9318ea9

Please sign in to comment.