Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Nov 4, 2024
1 parent a15adb3 commit 770a341
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 10 additions & 0 deletions open_prices/api/prices/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ def setUpTestData(cls):
)

def test_price_list_without_filter(self):
self.assertEqual(Price.objects.count(), 5)
response = self.client.get(self.url)
self.assertEqual(response.data["total"], 5)

def test_price_list_filter_by_product(self):
self.assertEqual(Price.objects.count(), 5)
# product_code
url = self.url + "?product_code=8001505005707"
response = self.client.get(url)
Expand All @@ -178,6 +180,7 @@ def test_price_list_filter_by_product(self):
self.assertEqual(response.data["total"], 3)

def test_price_list_filter_by_tags(self):
self.assertEqual(Price.objects.count(), 5)
# labels_tags
url = self.url + "?labels_tags__contains=en:organic"
response = self.client.get(url)
Expand All @@ -199,6 +202,7 @@ def test_price_list_filter_by_tags(self):
self.assertEqual(response.data["total"], 1)

def test_price_list_filter_by_price(self):
self.assertEqual(Price.objects.count(), 5)
# exact price
url = self.url + "?price=15"
response = self.client.get(url)
Expand All @@ -223,11 +227,13 @@ def test_price_list_filter_by_price(self):
self.assertEqual(response.data["total"], 4)

def test_price_list_filter_by_currency(self):
self.assertEqual(Price.objects.count(), 5)
url = self.url + "?currency=EUR"
response = self.client.get(url)
self.assertEqual(response.data["total"], 4)

def test_price_list_filter_by_location(self):
self.assertEqual(Price.objects.count(), 5)
# location_osm_id
url = self.url + f"?location_osm_id={self.user_price.location_osm_id}"
response = self.client.get(url)
Expand All @@ -245,6 +251,7 @@ def test_price_list_filter_by_location(self):
self.assertEqual(response.data["total"], 4)

def test_price_list_filter_by_proof(self):
self.assertEqual(Price.objects.count(), 5)
# proof_id
url = self.url + f"?proof_id={self.user_price.proof_id}"
response = self.client.get(url)
Expand All @@ -258,6 +265,7 @@ def test_price_list_filter_by_proof(self):
self.assertEqual(response.data["total"], 1)

def test_price_list_filter_by_date(self):
self.assertEqual(Price.objects.count(), 5)
# exact date
url = self.url + "?date=2024-01-01"
response = self.client.get(url)
Expand All @@ -276,11 +284,13 @@ def test_price_list_filter_by_date(self):
self.assertEqual(response.data["total"], 2)

def test_price_list_filter_by_owner(self):
self.assertEqual(Price.objects.count(), 5)
url = self.url + f"?owner={self.user_session.user.user_id}"
response = self.client.get(url)
self.assertEqual(response.data["total"], 4)

def test_price_list_filter_by_created(self):
self.assertEqual(Price.objects.count(), 5)
url = self.url + "?created__gte=2024-01-01T00:00:00Z"
response = self.client.get(url)
self.assertEqual(response.data["total"], 5)
Expand Down
6 changes: 2 additions & 4 deletions open_prices/api/proofs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ def test_proof_create(self):
self.assertEqual(response.data["price_count"], 0) # ignored
self.assertEqual(response.data["owner"], self.user_session.user.user_id)
self.assertTrue("source" not in response.data)
p = Proof.objects.last()
self.assertEqual(p.source, "API") # default value
self.assertEqual(Proof.objects.last().source, "API") # default value

def test_proof_create_with_location_id(self):
location_osm = LocationFactory(**LOCATION_OSM_NODE_652825274)
Expand Down Expand Up @@ -260,8 +259,7 @@ def test_proof_create_with_app_name(self):
)
self.assertEqual(response.status_code, 201)
self.assertTrue("source" not in response.data)
p = Proof.objects.last()
self.assertEqual(p.source, result)
self.assertEqual(Proof.objects.last().source, result)


class ProofUpdateApiTest(TestCase):
Expand Down

0 comments on commit 770a341

Please sign in to comment.