From aaec425933e44f2ea0fe9924937cc16bf3a32089 Mon Sep 17 00:00:00 2001 From: Jacob Rief Date: Tue, 12 May 2020 09:45:44 +0200 Subject: [PATCH] move a test commodity into own file --- tests/test_commodity.py | 25 +++++++++++++++++++++++++ tests/test_money.py | 17 ----------------- 2 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 tests/test_commodity.py diff --git a/tests/test_commodity.py b/tests/test_commodity.py new file mode 100644 index 000000000..98995aa8a --- /dev/null +++ b/tests/test_commodity.py @@ -0,0 +1,25 @@ +import pytest +from decimal import Decimal + +from shop.money.money_maker import MoneyMaker + +from testshop.models import Commodity + +EUR = MoneyMaker('EUR') + + +@pytest.mark.django_db +def test_field_filter(commodity_factory): + + commodity = commodity_factory(unit_price='12.34') + assert list(Commodity.objects.filter(unit_price='12.34')) == [commodity] + assert list(Commodity.objects.filter(unit_price=Decimal('12.34'))) == [commodity] + assert list(Commodity.objects.filter(unit_price=EUR('12.34'))) == [commodity] + assert list(Commodity.objects.filter(unit_price__gt='12.33')) == [commodity] + assert list(Commodity.objects.filter(unit_price__gt=EUR('12.33'))) == [commodity] + assert list(Commodity.objects.filter(unit_price__gt='12.34')) == [] + assert list(Commodity.objects.filter(unit_price__gte='12.34')) == [commodity] + assert list(Commodity.objects.filter(unit_price__lt='12.35')) == [commodity] + assert list(Commodity.objects.filter(unit_price__lt=EUR('12.35'))) == [commodity] + assert list(Commodity.objects.filter(unit_price__lt='12.34')) == [] + assert list(Commodity.objects.filter(unit_price__lte='12.34')) == [commodity] diff --git a/tests/test_money.py b/tests/test_money.py index 706607ac0..3bd146960 100644 --- a/tests/test_money.py +++ b/tests/test_money.py @@ -10,7 +10,6 @@ from rest_framework import serializers from shop.money.money_maker import AbstractMoney, MoneyMaker, _make_money from shop.rest.money import MoneyField, JSONRenderer -from testshop.models import Commodity EUR = MoneyMaker('EUR') @@ -269,19 +268,3 @@ def test_json_renderer(): data = {'amount': EUR('1.23')} rendered_json = renderer.render(data, 'application/json') assert {'amount': "€ 1.23"} == json.loads(rendered_json.decode('utf-8')) - - -@pytest.mark.django_db -def test_field_filter(commodity_factory): - commodity = commodity_factory(unit_price='12.34') - assert list(Commodity.objects.filter(unit_price='12.34')) == [commodity] - assert list(Commodity.objects.filter(unit_price=Decimal('12.34'))) == [commodity] - assert list(Commodity.objects.filter(unit_price=EUR('12.34'))) == [commodity] - assert list(Commodity.objects.filter(unit_price__gt='12.33')) == [commodity] - assert list(Commodity.objects.filter(unit_price__gt=EUR('12.33'))) == [commodity] - assert list(Commodity.objects.filter(unit_price__gt='12.34')) == [] - assert list(Commodity.objects.filter(unit_price__gte='12.34')) == [commodity] - assert list(Commodity.objects.filter(unit_price__lt='12.35')) == [commodity] - assert list(Commodity.objects.filter(unit_price__lt=EUR('12.35'))) == [commodity] - assert list(Commodity.objects.filter(unit_price__lt='12.34')) == [] - assert list(Commodity.objects.filter(unit_price__lte='12.34')) == [commodity]