Skip to content

Commit

Permalink
fix: retry fullfillment
Browse files Browse the repository at this point in the history
When retry fullfillment, the BasketTransactionIntegration was rasing mysql error.
fix #4
  • Loading branch information
igobranco committed Jan 26, 2024
1 parent acc5987 commit 0d32acc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}

Expand Down
7 changes: 5 additions & 2 deletions nau_extensions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,15 @@ 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:
raise ValueError(
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
2 changes: 2 additions & 0 deletions nau_extensions/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
Test settings for the ecommerce nau extensions
"""
from ecommerce.settings.test import *

INSTALLED_APPS += ("nau_extensions",)
27 changes: 27 additions & 0 deletions nau_extensions/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0d32acc

Please sign in to comment.