Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Feb 23, 2025
1 parent 4a29f00 commit 86a4b2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions open_prices/stats/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,19 @@ def setUpTestData(cls):
type=proof_constants.TYPE_PRICE_TAG,
location_osm_id=cls.location.osm_id,
location_osm_type=cls.location.osm_type,
currency="EUR",
owner=cls.user.user_id,
)
cls.proof_receipt = ProofFactory(
type=proof_constants.TYPE_RECEIPT,
location_osm_id=cls.location_2.osm_id,
location_osm_type=cls.location_2.osm_type,
currency="EUR",
owner=cls.user_2.user_id,
)
cls.proof_gdpr_request = ProofFactory(
type=proof_constants.TYPE_GDPR_REQUEST,
currency="EUR",
owner=cls.user_2.user_id,
)
cls.price = PriceFactory(
Expand All @@ -64,7 +67,7 @@ def setUpTestData(cls):
location_osm_type=cls.location.osm_type,
proof_id=cls.proof_price_tag.id,
price=1.0,
currency="EUR",
currency=cls.proof_price_tag.currency,
owner=cls.user.user_id,
)
PriceFactory(
Expand All @@ -85,7 +88,7 @@ def setUpTestData(cls):
location_osm_type=cls.location.osm_type,
proof_id=cls.proof_gdpr_request.id,
price=2.0,
currency="EUR",
currency=cls.proof_gdpr_request.currency,
owner=cls.user_2.user_id,
)
PriceTagFactory(proof=cls.proof_price_tag, status=None)
Expand Down
10 changes: 10 additions & 0 deletions open_prices/users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from open_prices.locations.factories import LocationFactory
from open_prices.prices.factories import PriceFactory
from open_prices.prices.models import Price
from open_prices.proofs import constants as proof_constants
from open_prices.proofs.factories import ProofFactory
from open_prices.users.factories import UserFactory
from open_prices.users.models import User
Expand Down Expand Up @@ -44,6 +45,7 @@ def setUpTestData(cls):
cls.location_1 = LocationFactory(**LOCATION_OSM_NODE_652825274)
cls.location_2 = LocationFactory(**LOCATION_ONLINE_DECATHLON)
cls.proof = ProofFactory(
type=proof_constants.TYPE_PRICE_TAG,
location_osm_id=cls.location_1.osm_id,
location_osm_type=cls.location_1.osm_type,
currency="EUR",
Expand All @@ -70,18 +72,26 @@ def setUpTestData(cls):
def test_update_price_count(self):
self.user.refresh_from_db()
self.assertEqual(self.user.price_count, 2) # price signals
self.assertEqual(self.user.price_type_group_community_count, 0)
self.assertEqual(self.user.price_type_group_consumption_count, 0)
self.assertEqual(self.user.price_currency_count, 0)
# update_price_count() should fix price counts
self.user.update_price_count()
self.assertEqual(self.user.price_count, 2)
self.assertEqual(self.user.price_type_group_community_count, 1)
self.assertEqual(self.user.price_type_group_consumption_count, 0)
self.assertEqual(self.user.price_currency_count, 2)
# bulk delete prices to skip signals
Price.objects.filter(owner=self.user.user_id).delete()
self.assertEqual(self.user.price_count, 2) # should be 0
self.assertEqual(self.user.price_type_group_community_count, 1)
self.assertEqual(self.user.price_type_group_consumption_count, 0)
self.assertEqual(self.user.price_currency_count, 2) # should be 0
# update_price_count() should fix price counts
self.user.update_price_count()
self.assertEqual(self.user.price_count, 0)
self.assertEqual(self.user.price_type_group_community_count, 0)
self.assertEqual(self.user.price_type_group_consumption_count, 0)
self.assertEqual(self.user.price_currency_count, 0)

def test_update_location_count(self):
Expand Down

0 comments on commit 86a4b2d

Please sign in to comment.