From bcf8a418d83a72f2a5174deee8cf6c3bc4a8a289 Mon Sep 17 00:00:00 2001 From: Jacob Rief Date: Mon, 11 May 2020 16:34:11 +0200 Subject: [PATCH] remove all occurences of six --- tests/test_auth.py | 11 ++++++----- tests/test_cart.py | 13 ++++++------- tests/test_catalog.py | 9 ++++----- tests/test_deferred.py | 11 ++++------- tests/test_enum.py | 7 +------ tests/test_money.py | 17 ++++++++--------- 6 files changed, 29 insertions(+), 39 deletions(-) diff --git a/tests/test_auth.py b/tests/test_auth.py index b8331147e..10e4e7881 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -58,10 +58,7 @@ def test_login_presistent(registered_customer, api_client): shall_expire = datetime.now(tz=tz_gmt).replace(microsecond=0) + timedelta(seconds=settings.SESSION_COOKIE_AGE) assert response.status_code == 200 session_cookie = response.cookies.get('sessionid') - if DJANGO_VERSION < (2,): - expires = datetime.strptime(session_cookie['expires'], '%a, %d-%b-%Y %H:%M:%S GMT') - else: - expires = datetime.strptime(session_cookie['expires'], '%a, %d %b %Y %H:%M:%S GMT') + expires = datetime.strptime(session_cookie['expires'], '%a, %d %b %Y %H:%M:%S GMT') expires = expires.replace(tzinfo=tz_gmt) assert abs(expires - shall_expire) < timedelta(seconds=5) assert session_cookie['max-age'] == settings.SESSION_COOKIE_AGE @@ -88,7 +85,11 @@ def test_change_password_fail(registered_customer, api_client): } response = api_client.post(change_url, data, format='json') assert response.status_code == 422 - assert response.json() == {'password_change_form': {'new_password2': ["The two password fields didn't match."]}} + payload = response.json() + if DJANGO_VERSION < (3,): + assert payload == {'password_change_form': {'new_password2': ["The two password fields didn't match."]}} + else: + assert payload == {'password_change_form': {'new_password2': ["The two password fields didn’t match."]}} @pytest.mark.django_db diff --git a/tests/test_cart.py b/tests/test_cart.py index a6c16a374..5491f8d1f 100644 --- a/tests/test_cart.py +++ b/tests/test_cart.py @@ -1,7 +1,6 @@ import pytest from django.contrib.auth.models import AnonymousUser from django.contrib.messages.storage import default_storage -from django.utils import six from shop.conf import app_settings from shop.models.cart import CartModel from shop.models.defaults.customer import Customer @@ -22,8 +21,8 @@ def test_add_to_cart(commodity_factory, api_client, rf): response = api_client.post(reverse('shop:cart-list'), data) assert response.status_code == 201 assert response.data['quantity'] == 2 - assert response.data['unit_price'] == six.text_type(product.unit_price) - assert response.data['line_total'] == six.text_type(2 * product.unit_price) + assert response.data['unit_price'] == str(product.unit_price) + assert response.data['line_total'] == str(2 * product.unit_price) # verify that the product is in the cart request = rf.get('/my-cart') @@ -48,8 +47,8 @@ def test_list_cart(api_rf, filled_cart): assert response.status_code == 200 assert response.data['num_items'] == 1 assert response.data['total_quantity'] == 2 - assert response.data['subtotal'] == six.text_type(filled_cart.subtotal) - assert response.data['total'] == six.text_type(filled_cart.total) + assert response.data['subtotal'] == str(filled_cart.subtotal) + assert response.data['total'] == str(filled_cart.total) @pytest.mark.django_db @@ -135,9 +134,9 @@ def test_include_tax_modifier(api_rf, filled_cart): response = CartViewSet.as_view({'get': 'list'})(request) assert response.status_code == 200 - assert response.data['subtotal'] == six.text_type(filled_cart.subtotal) + assert response.data['subtotal'] == str(filled_cart.subtotal) tax_rate = 1 + app_settings.SHOP_VALUE_ADDED_TAX / 100 - assert response.data['total'] == six.text_type(filled_cart.subtotal * tax_rate) + assert response.data['total'] == str(filled_cart.subtotal * tax_rate) @pytest.mark.django_db diff --git a/tests/test_catalog.py b/tests/test_catalog.py index 8217980b3..274a6dc82 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -1,6 +1,5 @@ from django.contrib.auth.models import AnonymousUser from django.urls import reverse -from django.utils import six from shop.models.cart import CartModel, CartItemModel from shop.models.customer import CustomerModel from shop.views.catalog import ProductListView, ProductRetrieveView, AddToCartView @@ -29,7 +28,7 @@ def test_catalog_detail(commodity_factory, customer_factory, rf): response = ProductRetrieveView.as_view()(request, slug=product.slug) response.render() assert response.data['product_code'] == product.product_code - assert response.data['price'] == six.text_type(product.unit_price) + assert response.data['price'] == str(product.unit_price) assert response.data['slug'] == product.slug @@ -42,7 +41,7 @@ def test_get_add_to_cart(commodity_factory, customer_factory, rf): response = AddToCartView.as_view()(request, slug=product.slug) response.render() assert response.data['quantity'] == 1 - assert response.data['unit_price'] == six.text_type(product.unit_price) + assert response.data['unit_price'] == str(product.unit_price) assert response.data['product_code'] == product.product_code assert response.data['is_in_cart'] is False @@ -60,8 +59,8 @@ def test_too_greedy(commodity_factory, customer_factory, rf): response = AddToCartView.as_view()(request, slug=product.slug) assert response.status_code == 202 assert response.data['quantity'] == 5 # not 10, as requested - assert response.data['unit_price'] == six.text_type(product.unit_price) - assert response.data['subtotal'] == six.text_type(5 * product.unit_price) + assert response.data['unit_price'] == str(product.unit_price) + assert response.data['subtotal'] == str(5 * product.unit_price) @pytest.mark.django_db diff --git a/tests/test_deferred.py b/tests/test_deferred.py index d7fabd3e4..4d267002b 100644 --- a/tests/test_deferred.py +++ b/tests/test_deferred.py @@ -6,7 +6,7 @@ from shop import deferred import copy -import six +from types import new_class def create_regular_class(name, fields={}, meta={}): @@ -26,11 +26,8 @@ def create_deferred_base_class(name, fields={}, meta={}, polymorphic=False): meta.setdefault('app_label', 'foo') meta.setdefault('abstract', True) Meta = type(str('Meta'), (), meta) - return type( - str(name), - (six.with_metaclass(metaclass, model_class),), - dict(Meta=Meta, __module__=__name__, **fields), - ) + cls_dict = dict(Meta=Meta, __metaclass__=metaclass, __module__=__name__, **fields) + return new_class(name, (model_class,), {'metaclass': metaclass}, lambda attrs: attrs.update(cls_dict)) def create_deferred_class(name, base, fields={}, meta={}, mixins=()): @@ -130,7 +127,7 @@ def create_deferred_class(name, base, fields={}, meta={}, mixins=()): class DeferredTestCase(TestCase): def assert_same_model(self, to, model): - if isinstance(to, six.string_types): + if isinstance(to, str): self.assertEqual(to, model.__name__) else: self.assertIs(to, model) diff --git a/tests/test_enum.py b/tests/test_enum.py index 8e41fe722..7d7a176df 100644 --- a/tests/test_enum.py +++ b/tests/test_enum.py @@ -1,6 +1,5 @@ import pytest from django.db import models -from django.utils import six from shop.models.fields import ChoiceEnum, ChoiceEnumField @@ -42,11 +41,7 @@ def test_str_enum(): assert MyColor.BLUE.label == "Pure blue" assert MyColor.BLUE == MyColor('#0000ff') assert str(MyColor.BLUE) == "Pure blue" - if six.PY2: - # Python-2 sorts members by value - assert MyColor.choices == [('#0000ff', "Pure blue"), ('#ff0000', "Pure red")] - else: - assert MyColor.choices == [('#ff0000', "Pure red"), ('#0000ff', "Pure blue")] + assert MyColor.choices == [('#ff0000', "Pure red"), ('#0000ff', "Pure blue")] def test_to_python(): diff --git a/tests/test_money.py b/tests/test_money.py index 72fee2d46..706607ac0 100644 --- a/tests/test_money.py +++ b/tests/test_money.py @@ -7,7 +7,6 @@ import pickle import json -from django.utils.six import text_type from rest_framework import serializers from shop.money.money_maker import AbstractMoney, MoneyMaker, _make_money from shop.rest.money import MoneyField, JSONRenderer @@ -76,28 +75,28 @@ def test_str_with_too_much_precision(): def test_thousand_separator(settings): value = EUR() - assert text_type(value) == "€ –" + assert str(value) == "€ –" value = EUR('999999.99') settings.USE_THOUSAND_SEPARATOR = False - assert text_type(value) == "€ 999999.99" + assert str(value) == "€ 999999.99" settings.USE_THOUSAND_SEPARATOR = True - assert text_type(value) == "€ 999,999.99" + assert str(value) == "€ 999,999.99" settings.LANGUAGE_CODE = 'de' - assert text_type(value) == "€ 999.999,99" + assert str(value) == "€ 999.999,99" settings.USE_THOUSAND_SEPARATOR = False - assert text_type(value) == "€ 999999,99" + assert str(value) == "€ 999999,99" def test_check_rounding(): value = EUR('999999.995') - assert text_type(value) == "€ 1000000.00" + assert str(value) == "€ 1000000.00" value = EUR('-111111.114') - assert text_type(value) == "-€ 111111.11" + assert str(value) == "-€ 111111.11" def test_check_formatting_currency(): value = -EUR('111111.11') value.MONEY_FORMAT='{minus}{amount} {code}' - assert text_type(value) == "-111111.11 EUR" + assert str(value) == "-111111.11 EUR" def test_reduce():