Skip to content

Commit

Permalink
remove all occurences of six
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed May 11, 2020
1 parent 9ed4127 commit bcf8a41
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 39 deletions.
11 changes: 6 additions & 5 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 6 additions & 7 deletions tests/test_cart.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions tests/test_catalog.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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


Expand All @@ -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

Expand All @@ -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
Expand Down
11 changes: 4 additions & 7 deletions tests/test_deferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from shop import deferred

import copy
import six
from types import new_class


def create_regular_class(name, fields={}, meta={}):
Expand All @@ -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=()):
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions tests/test_enum.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from django.db import models
from django.utils import six
from shop.models.fields import ChoiceEnum, ChoiceEnumField


Expand Down Expand Up @@ -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():
Expand Down
17 changes: 8 additions & 9 deletions tests/test_money.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit bcf8a41

Please sign in to comment.