Skip to content

Commit

Permalink
move a test commodity into own file
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed May 12, 2020
1 parent 73cd082 commit aaec425
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
25 changes: 25 additions & 0 deletions tests/test_commodity.py
Original file line number Diff line number Diff line change
@@ -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]
17 changes: 0 additions & 17 deletions tests/test_money.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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]

0 comments on commit aaec425

Please sign in to comment.