Ejemplo n.º 1
0
class StaticQueryTest(PythonicTestCase):
    def setUp(self):
        self.query = StaticQuery([1, 2, 3, 4, 5])
    
    def test_can_return_all_items(self):
        assert_equals([1, 2, 3, 4, 5], self.query.all())
    
    def test_can_return_all_items_with_iteration(self):
        assert_equals([1, 2, 3, 4, 5], list(self.query))
    
    def test_can_use_offset(self):
        assert_equals([3, 4, 5], self.query.offset(2).all())
    
    def test_can_build_static_query(self):
        assert_equals([1, 2], list(self.query.limit(2)))
    
    def test_knows_number_of_items(self):
        all_items = self.query.offset(1).all()
        assert_length(4, all_items)
        assert_equals(4, self.query.count())
        assert_equals(4, len(self.query))
    
    def test_supports_slicing(self):
        assert_equals([3, 4, 5], self.query[2:])
        assert_equals(3, self.query.offset(1)[2])
    
    def test_can_return_first_item(self):
        assert_equals(1, self.query.first())
        list(self.query) # consume all other items
        assert_none(self.query.first())
Ejemplo n.º 2
0
class StaticQueryTest(PythonicTestCase):
    def setUp(self):
        self.query = StaticQuery([1, 2, 3, 4, 5])

    def test_can_return_all_items(self):
        assert_equals([1, 2, 3, 4, 5], self.query.all())

    def test_can_return_all_items_with_iteration(self):
        assert_equals([1, 2, 3, 4, 5], list(self.query))

    def test_can_use_offset(self):
        assert_equals([3, 4, 5], self.query.offset(2).all())

    def test_can_build_static_query(self):
        assert_equals([1, 2], list(self.query.limit(2)))

    def test_knows_number_of_items(self):
        all_items = self.query.offset(1).all()
        assert_length(4, all_items)
        assert_equals(4, self.query.count())
        assert_equals(4, len(self.query))

    def test_supports_slicing(self):
        assert_equals([3, 4, 5], self.query[2:])
        assert_equals(3, self.query.offset(1)[2])

    def test_can_return_first_item(self):
        assert_equals(1, self.query.first())
        list(self.query)  # consume all other items
        assert_none(self.query.first())
Ejemplo n.º 3
0
 def _apply_access_restrictions_to_query(self, query, permission_name, perm):
     conditions = []
     for policy in self.policies_for_permission(permission_name):
         result = policy.access_condition_for_query(query, permission_name, perm)
         if result == True:
             return QueryResultProxy(query)
         elif result == False:
             return StaticQuery([])
         elif result is None:
             continue
         
         condition = result
         if isinstance(result, tuple):
             condition, query = result
         conditions.append(condition)
     
     if len(conditions) == 0:
         # if there is no condition which can possibly allow the access, 
         # we should not return any items
         return StaticQuery([])
     restricted_query = query.distinct().filter(or_(*conditions))
     return QueryResultProxy(restricted_query)
Ejemplo n.º 4
0
 def setUp(self):
     self.query = StaticQuery([1, 2, 3, 4, 5])
Ejemplo n.º 5
0
 def setUp(self):
     self.query = StaticQuery([1, 2, 3, 4, 5])