Example #1
0
    def test_delete_all_records_in_repository(self, test_domain):
        """Delete all objects in a repository"""

        test_domain.repository_for(Person)._dao.create(id=1,
                                                       first_name="Athos",
                                                       last_name="Musketeer",
                                                       age=2)
        test_domain.repository_for(Person)._dao.create(id=2,
                                                       first_name="Porthos",
                                                       last_name="Musketeer",
                                                       age=3)
        test_domain.repository_for(Person)._dao.create(id=3,
                                                       first_name="Aramis",
                                                       last_name="Musketeer",
                                                       age=4)
        test_domain.repository_for(Person)._dao.create(id=4,
                                                       first_name="dArtagnan",
                                                       last_name="Musketeer",
                                                       age=5)

        person_records = test_domain.repository_for(Person)._dao.query.filter(
            Q())
        assert person_records.total == 4

        test_domain.repository_for(Person)._dao.delete_all()

        person_records = test_domain.repository_for(Person)._dao.query.filter(
            Q())
        assert person_records.total == 0
Example #2
0
 def test_deconstruct_and(self):
     q1 = Q(price__gt=10.0)
     q2 = Q(price=11.0)
     q = q1 & q2
     path, args, kwargs = q.deconstruct()
     assert args == (
         ("price__gt", 10.0),
         ("price", 11.0),
     )
     assert kwargs == {}
Example #3
0
 def test_deconstruct_or(self):
     q1 = Q(price__gt=10.0)
     q2 = Q(price=11.0)
     q3 = q1 | q2
     path, args, kwargs = q3.deconstruct()
     assert args == (
         ("price__gt", 10.0),
         ("price", 11.0),
     )
     assert kwargs == {"_connector": "OR"}
Example #4
0
 def test_deconstruct_multiple_kwargs(self):
     q = Q(price__gt=10.0, price=11.0)
     path, args, kwargs = q.deconstruct()
     assert args == (
         ("price", 11.0),
         ("price__gt", 10.0),
     )
     assert kwargs == {}
Example #5
0
 def test_deconstruct_negated(self):
     q = ~Q(price__gt=10.0)
     path, args, kwargs = q.deconstruct()
     assert args == ()
     assert kwargs == {
         "price__gt": 10.0,
         "_negated": True,
     }
Example #6
0
 def test_reconstruct_and(self):
     q1 = Q(price__gt=10.0)
     q2 = Q(price=11.0)
     q = q1 & q2
     path, args, kwargs = q.deconstruct()
     assert Q(*args, **kwargs) == q
Example #7
0
 def test_reconstruct_negated(self):
     q = ~Q(price__gt=10.0)
     path, args, kwargs = q.deconstruct()
     assert Q(*args, **kwargs) == q
Example #8
0
 def test_deconstruct(self):
     q = Q(price__gt=10.0)
     path, args, kwargs = q.deconstruct()
     assert path == "protean.utils.query.Q"
     assert args == ()
     assert kwargs == {"price__gt": 10.0}