Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix codeclimate issue and add tests for coverage
oldPadavan7dda72292b75
diff --git a/saleor/core/utils/json_serializer.py b/saleor/core/utils/json_serializer.pyindex 4dda883bc5..4ba0219d6b 100644--- a/saleor/core/utils/json_serializer.py+++ b/saleor/core/utils/json_serializer.py@@ -2,12 +2,9 @@ import jsonfrom django.core.serializers.base import DeserializationErrorfrom django.core.serializers.json import (- DjangoJSONEncoder,- PythonDeserializer,- Serializer as JsonSerializer)+ DjangoJSONEncoder, PythonDeserializer, Serializer as JsonSerializer)from prices import Money-MONEY_TYPE = 'Money'@@ -33,7 +30,8 @@ def object_hook(obj):def Deserializer(stream_or_string, **options):- """Deserialize a stream or string of JSON data."""+ """Deserialize a stream or string of JSON data. This is a copy of Django+ implementation with additional argument <object_hook> in json.loads"""if not isinstance(stream_or_string, (bytes, str)):stream_or_string = stream_or_string.read()if isinstance(stream_or_string, bytes):diff --git a/tests/test_product.py b/tests/test_product.pyindex f24d56a26f..739ebbad67 100644--- a/tests/test_product.py+++ b/tests/test_product.py@@ -7,6 +7,7 @@ import pytestfrom django.conf import settingsfrom django.core import serializers+from django.core.serializers.base import DeserializationErrorfrom django.urls import reversefrom prices import Money, TaxedMoney, TaxedMoneyRangefrom saleor.checkout import utils@@ -631,6 +632,43 @@ def test_product_json_deserialization(category, product_type):product = models.Product.objects.first()assert product.price == Money(Decimal('35.98'), 'USD')+ # same test for bytes+ product_json = bytes(product_json, 'utf-8')+ product_deserialized = list(serializers.deserialize(+ 'json', product_json, ignorenonexistent=True))[0]+ product_deserialized.save()+ product = models.Product.objects.first()+ assert product.price == Money(Decimal('35.98'), 'USD')+++def test_json_no_currency_deserialization(category, product_type):+ product_json = """+ [{{+ "model": "product.product",+ "pk": 60,+ "fields": {{+ "seo_title": null,+ "seo_description": "Future almost cup national.",+ "product_type": {product_type_pk},+ "name": "Kelly-Clark",+ "description": "Future almost cup national",+ "category": {category_pk},+ "price": {{"_type": "Money", "amount": "35.98"}},+ "available_on": null,+ "is_published": true,+ "attributes": "{{\\"9\\": \\"24\\", \\"10\\": \\"26\\"}}",+ "updated_at": "2018-07-19T13:30:24.195Z",+ "is_featured": false,+ "charge_taxes": true,+ "tax_rate": "standard"+ }}+ }}]+ """.format(+ category_pk=category.pk, product_type_pk=product_type.pk)+ with pytest.raises(DeserializationError):+ list(serializers.deserialize(+ 'json', product_json, ignorenonexistent=True))+def test_variant_picker_data_with_translations(product, translated_variant_fr, settings):