From e190da5b7bf3326a2e74ccc8f9196e14cba8f9d1 Mon Sep 17 00:00:00 2001 From: Samar Hassan Date: Mon, 9 Dec 2024 11:22:31 +0000 Subject: [PATCH 1/2] refactor :package: revert product resource clean method --- oscar_odin/resources/catalogue.py | 27 ---------- tests/resources/__init__.py | 0 tests/resources/test_catalogue.py | 85 ------------------------------- 3 files changed, 112 deletions(-) delete mode 100644 tests/resources/__init__.py delete mode 100644 tests/resources/test_catalogue.py diff --git a/oscar_odin/resources/catalogue.py b/oscar_odin/resources/catalogue.py index 9d874cc..39fb3da 100644 --- a/oscar_odin/resources/catalogue.py +++ b/oscar_odin/resources/catalogue.py @@ -8,13 +8,11 @@ import odin from odin.fields import StringField -from odin.exceptions import ValidationError as OdinValidationError, NON_FIELD_ERRORS from ..fields import DecimalField OscarResource = get_class("oscar_odin.resources.base", "OscarResource") -PartnerResource = get_class("oscar_odin.resources.partner", "PartnerResource") StockRecordResource = get_class("oscar_odin.resources.partner", "StockRecordResource") ProductModel = get_model("catalogue", "Product") @@ -137,28 +135,3 @@ class ProductResource(OscarCatalogueResource): children: Optional[List["ProductResource"]] = odin.ListOf.delayed( lambda: ProductResource, null=True ) - - def clean(self): - if ( - not self.stockrecords - and (self.price is not None or self.availability is not None) - and not ( - self.upc is not None - and self.currency is not None - and self.partner is not None - ) - ): - errors = { - NON_FIELD_ERRORS: [ - "upc, currency and partner are required when specifying price or availability" - ] - } - # upc is allready required so we don't need to check for it here - if ( - self.currency is None - ): # currency has a default but it can be set to null by accident - errors["currency"] = ["Currency can not be empty."] - if self.partner is None: - errors["partner"] = ["Partner can not be empty."] - - raise OdinValidationError(errors, code="simpleprice") diff --git a/tests/resources/__init__.py b/tests/resources/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/resources/test_catalogue.py b/tests/resources/test_catalogue.py deleted file mode 100644 index 7f6ee82..0000000 --- a/tests/resources/test_catalogue.py +++ /dev/null @@ -1,85 +0,0 @@ -from django.test import TestCase - -from oscar.core.loading import get_model - -from odin.exceptions import ValidationError -from oscar_odin import resources - -Product = get_model("catalogue", "Product") - - -class TestProduct(TestCase): - def setUp(self): - super().setUp() - self.maxDiff = None - - def test_init(self): - target = resources.catalogue.ProductResource() - - self.assertIsNotNone(target) - - def test_resource_with_price_needs_other_fields_to_work(self): - henk = resources.catalogue.ProductResource( - upc="klaas", price=10, structure=Product.STANDALONE, title="BATSIE" - ) - - with self.assertRaises(ValidationError) as error: - henk.full_clean() - - self.assertDictEqual( - error.exception.error_messages, - { - "__all__": [ - "upc, currency and partner are required when specifying price or availability" - ], - "partner": ["Partner can not be empty."], - }, - ) - - henk = resources.catalogue.ProductResource( - upc="klaas", - price=10, - structure=Product.STANDALONE, - currency="EUR", - title="BATSIE", - ) - - with self.assertRaises(ValidationError) as error: - henk.full_clean() - - self.assertDictEqual( - error.exception.error_messages, - { - "__all__": [ - "upc, currency and partner are required when specifying price or availability" - ], - "partner": ["Partner can not be empty."], - }, - ) - - henk = resources.catalogue.ProductResource( - upc="klaas", - price=10, - structure=Product.STANDALONE, - partner=1, - title="BATSIE", - ) - henk.full_clean() - - def test_resource_with_availability_needs_other_fields_to_work(self): - henk = resources.catalogue.ProductResource( - upc="klaas", availability=10, structure=Product.STANDALONE, title="BATSIE" - ) - - with self.assertRaises(ValidationError) as error: - henk.full_clean() - - self.assertDictEqual( - error.exception.error_messages, - { - "__all__": [ - "upc, currency and partner are required when specifying price or availability" - ], - "partner": ["Partner can not be empty."], - }, - ) From 0e76ec9dbca3a097a8b98bd28bcc43ec087d7436 Mon Sep 17 00:00:00 2001 From: Samar Hassan Date: Mon, 9 Dec 2024 12:10:33 +0000 Subject: [PATCH 2/2] Update poetry.lock --- poetry.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index 0575507..c3fe1e5 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.5 and should not be changed by hand. [[package]] name = "asgiref" @@ -2253,4 +2253,4 @@ test = ["black", "coverage", "poetry", "pylint", "pylint-django", "responses", " [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "51b0c5f91b076349d375eecaa5f6002e7f1b27b447bfcf20f486c243dfe0d747" +content-hash = "6143acc860e7d0a0acad0b785762173202e5b1cc56913e75e22a31f011ed9eea"