Exemple #1
0
 def test_all(self):
     res = Parse({})
     q = Order.objects.filter(res)
     assert q.count() == 2
     self.assertEqual(
         str(q.query),
         'SELECT "test_app_order"."id", "test_app_order"."order_date", "test_app_order"."status", "test_app_order"."ordered_by_id" FROM "test_app_order"'
     )
Exemple #2
0
 def test_basic(self):
     res = Parse({"status": "Completed"})
     q = Order.objects.filter(res)
     assert q.count() == 1
     self.assertEqual(
         str(q.query),
         'SELECT "test_app_order"."id", "test_app_order"."order_date", "test_app_order"."status", "test_app_order"."ordered_by_id" FROM "test_app_order" WHERE "test_app_order"."status" = Completed'
     )
Exemple #3
0
 def test_not_and_success(self):
     d = {"and": {"status": "Completed", "~ordered_by_id": 2}}
     res = Parse(d)
     q = Order.objects.filter(res)
     assert q.count() == 1
     self.assertEqual(
         str(q.query),
         'SELECT "test_app_order"."id", "test_app_order"."order_date", "test_app_order"."status", "test_app_order"."ordered_by_id" FROM "test_app_order" WHERE ("test_app_order"."status" = Completed AND NOT ("test_app_order"."ordered_by_id" = 2))'
     )
Exemple #4
0
 def test_or(self):
     d = {"or": {"status": "Completed", "ordered_by_id": 2}}
     res = Parse(d)
     q = Order.objects.filter(res)
     assert q.count() == 2
     self.assertEqual(
         str(q.query),
         'SELECT "test_app_order"."id", "test_app_order"."order_date", "test_app_order"."status", "test_app_order"."ordered_by_id" FROM "test_app_order" WHERE ("test_app_order"."status" = Completed OR "test_app_order"."ordered_by_id" = 2)'
     )