Esempio n. 1
0
 def test_iterator_count(self, class_entity_repo, ent0, ent1):
     agg = class_entity_repo.get_aggregate(IMyEntity)
     with pytest.raises(StopIteration):
         next(agg.iterator())
     agg.add(ent0)
     assert next(agg.iterator()) is ent0
     # Iterator heeds filtering.
     agg.filter = eq(id=ent1.id)
     with pytest.raises(StopIteration):
         next(agg.iterator())
     agg.add(ent1)
     assert next(agg.iterator()) is ent1
     # Iterator heeds ordering.
     agg.filter = None
     agg.order = asc('id')
     assert isinstance(agg.order, AscendingOrderSpecification)
     assert next(agg.iterator()) is ent0
     # Iterator heeds slice.
     assert len(list(agg.iterator())) == 2
     agg.slice = slice(0, 1)
     assert len(list(agg.iterator())) == 1
     # Count ignores slice.
     assert agg.count() == 2
     # Count heeds filtering.
     agg.filter = eq(id=1)
     assert agg.count() == 1
Esempio n. 2
0
 def test_filter_order_slice(self):
     ent0 = MyEntity(id=0)
     ent1 = MyEntity(id=1)
     ent2 = MyEntity(id=2)
     cache = EntityCache(entities=[])
     cache.add(ent0)
     cache.add(ent1)
     cache.add(ent2)
     filter_expr = EvalFilterExpression(~eq(id=0))
     order_expr = EvalOrderExpression(asc('id'))
     slice_key = slice(1, 2)
     self.assert_equal(list(cache.retrieve(filter_expression=filter_expr,
                                           order_expression=order_expr,
                                           slice_key=slice_key)),
                       [ent2])
Esempio n. 3
0
 def test_nested_attribute(self, class_entity_repo, ent0, ent1, ent2):
     agg = class_entity_repo.get_aggregate(IMyEntity)
     agg.add(ent0)
     agg.add(ent1)
     agg.add(ent2)
     assert len(list(agg.iterator())) == 3
     agg.filter = eq(**{'parent.text':'222'})
     assert len(list(agg.iterator())) == 1
     agg.filter = None
     assert len(list(agg.iterator())) == 3
     agg.order = asc('parent.text')
     assert next(agg.iterator()) is ent2
     # With nested filter and order.
     agg.filter = gt(**{'parent.text':'000'})
     assert next(agg.iterator()) is ent1
     # With nested filter, order, and slice.
     agg.slice = slice(1, 2)
     assert next(agg.iterator()) is ent0
Esempio n. 4
0
 def test_filter_order_slice(self, class_configurator):
     class_configurator.begin()
     try:
         ent0 = MyEntity(id=0)
         ent1 = MyEntity(id=1)
         ent2 = MyEntity(id=2)
         cache = EntityCache(entities=[])
         cache.add(ent0)
         cache.add(ent1)
         cache.add(ent2)
         filter_expr = EvalFilterExpression(~eq(id=0))
         order_expr = EvalOrderExpression(asc('id'))
         slice_key = slice(1, 2)
         assert list(cache.retrieve(filter_expression=filter_expr,
                                    order_expression=order_expr,
                                    slice_key=slice_key)) \
                == [ent2]
     finally:
         class_configurator.end()
 def test_asc_generator(self):
     second_candidate = Candidate(number_attr=0, text_attr='b')
     spec = asc('number_attr') & asc('text_attr')
     self.assert_true(spec.lt(self.candidate, second_candidate))
Esempio n. 6
0
 def test_asc_generator(self):
     second_candidate = Candidate(number_attr=0, text_attr='b')
     spec = asc('number_attr') & asc('text_attr')
     self.assert_true(spec.lt(self.candidate, second_candidate))