From 227e37a8f7fca8fbf55cc82e9e5f6f0d600457c6 Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Tue, 22 Dec 2015 14:37:37 +0100 Subject: [PATCH] round amount computed from query string (#9174) --- lingo/views.py | 4 ++-- tests/test_payment.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lingo/views.py b/lingo/views.py index 32f8a60..0d8e863 100644 --- a/lingo/views.py +++ b/lingo/views.py @@ -57,7 +57,7 @@ class AddBasketItemApiView(View): def get_amount(self, amount): if isinstance(amount, list): - d = sum([Decimal(a) for a in amount]) + d = Decimal(sum([Decimal(a) for a in amount])) else: d = Decimal(amount) return d.quantize(Decimal('0.01'), ROUND_HALF_UP) @@ -69,7 +69,7 @@ class AddBasketItemApiView(View): extra = request_body.get('extra', {}) item = BasketItem(amount=0) - item.amount = sum([Decimal(x) for x in request.GET.getlist('amount')]) + item.amount = self.get_amount(request.GET.getlist('amount')) if request_body.get('amount'): item.amount += self.get_amount(request_body['amount']) diff --git a/tests/test_payment.py b/tests/test_payment.py index e5d531c..f75d39a 100644 --- a/tests/test_payment.py +++ b/tests/test_payment.py @@ -103,10 +103,11 @@ def test_add_amount_to_basket(regie, user): data['amount'] = [amount] data['extra'] = {'amount': ['22.22', '12']} - resp = client.post(url, json.dumps(data), content_type='application/json') + resp = client.post('%s&amount=5' % url, json.dumps(data), + content_type='application/json') assert resp.status_code == 200 assert json.loads(resp.content) == {'result': 'success'} - assert BasketItem.objects.filter(amount=Decimal('76.22')).exists() + assert BasketItem.objects.filter(amount=Decimal('81.22')).exists() def test_payment_callback(regie, user):