def test_from_repr_query_with_several_orders(): orders = [ PropertyOrder('property1', direction=Direction.ASCENDING), PropertyOrder('property2', direction=Direction.DESCENDING) ] original_query = Query(order=orders) data = { 'kind': [], 'order': [ { 'property': { 'name': orders[0].prop }, 'direction': orders[0].direction }, { 'property': { 'name': orders[1].prop }, 'direction': orders[1].direction } ] } output_query = Query.from_repr(data) assert output_query == original_query
def test_order_to_repr(): property_name = 'my_prop' direction = Direction.DESCENDING order = PropertyOrder(property_name, direction) r = order.to_repr() assert r['property']['name'] == property_name assert r['direction'] == direction.value
def test_to_repr_query_with_several_orders(): orders = [ PropertyOrder('property1', direction=Direction.ASCENDING), PropertyOrder('property2', direction=Direction.DESCENDING) ] query = Query(order=orders) r = query.to_repr() assert len(r['order']) == 2 assert r['order'][0] == orders[0].to_repr() assert r['order'][1] == orders[1].to_repr()
def test_order_from_repr(property_order): original_order = property_order data = { 'property': { 'name': original_order.prop }, 'direction': original_order.direction } output_order = PropertyOrder.from_repr(data) assert output_order == original_order
def test_order_defaults_to_ascending(): assert PropertyOrder('prop_name').direction == Direction.ASCENDING
def property_order() -> PropertyOrder: return PropertyOrder(prop='prop_name', direction=Direction.DESCENDING)