Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not send basket with seat with full discount to Sage X3 #316

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/billing/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def create(self, validated_data):
product_id=item.product_id,
)

create_and_async_send_transactions_to_processor_task(transaction=transaction)
if not float(transaction.total_amount_include_vat) == 0:
create_and_async_send_transactions_to_processor_task(transaction=transaction)

return validated_data

Expand Down
36 changes: 35 additions & 1 deletion apps/billing/tests/test_process_transaction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import decimal
import json
import logging
from copy import deepcopy
from unittest import mock

import factory
Expand All @@ -10,7 +11,7 @@
from rest_framework.test import APIClient

from apps.billing.factories import TransactionFactory, TransactionItemFactory
from apps.billing.models import Transaction
from apps.billing.models import SageX3TransactionInformation, Transaction
from apps.billing.serializers import TransactionItemSerializer, TransactionSerializer

from .test_transaction_service import processor_success_response
Expand Down Expand Up @@ -69,6 +70,39 @@ def test_create_transaction(self, mock):

self.assertEqual(value, transaction_data[key])

igobranco marked this conversation as resolved.
Show resolved Hide resolved
self.assertTrue(SageX3TransactionInformation.objects.filter(transaction=transaction).exists())

@mock.patch("requests.post", side_effect=processor_success_response)
def test_doest_not_send_transaction_with_zero_as_total_amount(self, mock):
"""
Test that a transaction will not be sent to the processor if the total amound sold is zero.
"""
payload = deepcopy(self.payload)
payload["total_amount_exclude_vat"] = 0
payload["total_amount_include_vat"] = 0
self.client.credentials(HTTP_AUTHORIZATION="Token " + self.token.key)

log.info(payload)
response = self.client.post(self.endpoint, payload, format="json")
log.info(response.content)
self.assertEqual(response.status_code, 201)

transaction = Transaction.objects.get(transaction_id=payload["transaction_id"])
transaction_data = TransactionSerializer(transaction).data
transaction_data["items"] = [
TransactionItemSerializer(item).data for item in transaction.transaction_items.all()
]

for key, value in dict(response.data["data"]).items():
if key == "items":
for item in value:
same_item = [i for i in transaction_data["items"] if i == item][0]
[self.assertEqual(v, same_item[k]) for k, v in dict(item).items()]

self.assertEqual(value, transaction_data[key])

self.assertFalse(SageX3TransactionInformation.objects.filter(transaction=transaction).exists())

def test_create_transaction_without_token(self):
"""
Test that a transaction cannot be created without a valid token.
Expand Down
Loading