diff --git a/open_prices/api/proofs/tests.py b/open_prices/api/proofs/tests.py index cd0ff83d..ace1eabd 100644 --- a/open_prices/api/proofs/tests.py +++ b/open_prices/api/proofs/tests.py @@ -14,16 +14,6 @@ from open_prices.proofs.models import Proof from open_prices.users.factories import SessionFactory -PROOF = { - "type": proof_constants.TYPE_RECEIPT, - "currency": "EUR", - "date": "2024-01-01", - "location_osm_id": 652825274, - "location_osm_type": location_constants.OSM_TYPE_NODE, - "receipt_price_count": 5, - "receipt_price_total": Decimal("45.10"), -} - LOCATION_OSM_NODE_652825274 = { "type": location_constants.TYPE_OSM, "osm_id": 652825274, @@ -32,6 +22,21 @@ "osm_lat": "45.1805534", "osm_lon": "5.7153387", } +LOCATION_OSM_NODE_6509705997 = { + "type": location_constants.TYPE_OSM, + "osm_id": 6509705997, + "osm_type": location_constants.OSM_TYPE_NODE, + "osm_name": "Carrefour", +} +PROOF = { + "type": proof_constants.TYPE_RECEIPT, + "currency": "EUR", + "date": "2024-01-01", + "location_osm_id": LOCATION_OSM_NODE_652825274["osm_id"], + "location_osm_type": LOCATION_OSM_NODE_652825274["osm_type"], + "receipt_price_count": 5, + "receipt_price_total": Decimal("45.10"), +} def create_fake_image() -> bytes: @@ -268,7 +273,13 @@ def setUpTestData(cls): **PROOF, price_count=15, owner=cls.user_session_1.user.user_id ) cls.url = reverse("api:proofs-detail", args=[cls.proof.id]) - cls.data = {"currency": "USD", "price_count": 20} + cls.data = { + "location_osm_id": LOCATION_OSM_NODE_6509705997["osm_id"], + "location_osm_type": LOCATION_OSM_NODE_6509705997["osm_type"], + "currency": "USD", + "receipt_price_count": 4, + "price_count": 20, + } def test_proof_update(self): # anonymous @@ -293,6 +304,11 @@ def test_proof_update(self): ) self.assertEqual(response.status_code, 404) # 403 ? # authenticated + self.assertEqual( + self.proof.location_osm_id, LOCATION_OSM_NODE_652825274["osm_id"] + ) + self.assertEqual(self.proof.currency, "EUR") + self.assertEqual(self.proof.receipt_price_count, 5) response = self.client.patch( self.url, self.data, @@ -300,7 +316,11 @@ def test_proof_update(self): content_type="application/json", ) self.assertEqual(response.status_code, 200) + self.assertEqual( + response.data["location_osm_id"], LOCATION_OSM_NODE_6509705997["osm_id"] + ) self.assertEqual(response.data["currency"], "USD") + self.assertEqual(response.data["receipt_price_count"], 4) self.assertEqual(Proof.objects.get(id=self.proof.id).price_count, 15) # ignored diff --git a/open_prices/proofs/models.py b/open_prices/proofs/models.py index 2f4c8413..a420c391 100644 --- a/open_prices/proofs/models.py +++ b/open_prices/proofs/models.py @@ -41,8 +41,8 @@ def with_stats(self): class Proof(models.Model): FILE_FIELDS = ["file_path", "mimetype", "image_thumb_path"] UPDATE_FIELDS = [ - # "location_osm_id", - # "location_osm_type", + "location_osm_id", + "location_osm_type", "type", "currency", "date", @@ -50,8 +50,6 @@ class Proof(models.Model): "receipt_price_total", ] CREATE_FIELDS = UPDATE_FIELDS + [ - "location_osm_id", - "location_osm_type", "location_id", # extra field (optional) ] FIX_PRICE_FIELDS = ["location", "date", "currency"] diff --git a/open_prices/proofs/tests.py b/open_prices/proofs/tests.py index fd4a6a8b..6839c0d5 100644 --- a/open_prices/proofs/tests.py +++ b/open_prices/proofs/tests.py @@ -17,6 +17,7 @@ "osm_name": "Monoprix", } LOCATION_OSM_NODE_6509705997 = { + "type": location_constants.TYPE_OSM, "osm_id": 6509705997, "osm_type": location_constants.OSM_TYPE_NODE, "osm_name": "Carrefour",