diff --git a/README.rst b/README.rst index 571e5c1..41fcee6 100644 --- a/README.rst +++ b/README.rst @@ -31,7 +31,7 @@ edit the `ecommerce/settings/private.py` file add change to:: NAU_FINANCIAL_MANAGER = { "edx": { "url": "http://financial-manager.local.nau.fccn.pt:8000/api/billing/transaction-complete/", - "token": "abcdABCD1234", + "token": "Bearer abcdABCD1234", } } diff --git a/nau_extensions/models.py b/nau_extensions/models.py index 97f0b9e..d51bb3d 100644 --- a/nau_extensions/models.py +++ b/nau_extensions/models.py @@ -123,7 +123,7 @@ class Meta: @staticmethod def create(basket): """ - Create a new basket transaction integration for a basket. + Create a new basket basket transaction integration or reuse an existing one for a basket. """ order = get_order(basket) if not order: @@ -131,4 +131,7 @@ def create(basket): f"The creation of BasketTransactionIntegration requires a basket with an order" f", basket '{basket}'" ) - return BasketTransactionIntegration(basket=basket) + bti = basket.basket_transaction_integration + if not bti: + bti = BasketTransactionIntegration(basket=basket) + return bti diff --git a/nau_extensions/settings/test.py b/nau_extensions/settings/test.py index 37b0c6a..b39a0c6 100644 --- a/nau_extensions/settings/test.py +++ b/nau_extensions/settings/test.py @@ -2,3 +2,5 @@ Test settings for the ecommerce nau extensions """ from ecommerce.settings.test import * + +INSTALLED_APPS += ("nau_extensions",) diff --git a/nau_extensions/tests/test_models.py b/nau_extensions/tests/test_models.py new file mode 100644 index 0000000..6f7ba92 --- /dev/null +++ b/nau_extensions/tests/test_models.py @@ -0,0 +1,27 @@ +from nau_extensions.models import BasketTransactionIntegration +from oscar.test import factories + +from ecommerce.extensions.test.factories import create_basket, create_order +from ecommerce.tests.factories import UserFactory +from ecommerce.tests.testcases import TestCase + + +class ModelsNAUExtensionsTests(TestCase): + """ + This class aims to test the specifics of the nau extensions project related to django models. + """ + + def setUp(self): + super(ModelsNAUExtensionsTests, self).setUp() + self.order = create_order(user=UserFactory()) + self.order.save() + self.order.basket.save() + + def test_basket_integration_integration_create_second(self): + """ + Test the creation of a second `BasketTransactionIntegration` for same basket/order. + """ + BasketTransactionIntegration.create(self.order.basket) + + # the 2nd call on create should fail + BasketTransactionIntegration.create(self.order.basket)