Commit cd60dd56 by Clinton Blackburn

Merge pull request #8771 from edx/clintonb/currency-comparison-fix

Comparing currencies with same case
parents 747c6b74 301a874c
...@@ -86,6 +86,11 @@ class CourseMode(models.Model): ...@@ -86,6 +86,11 @@ class CourseMode(models.Model):
""" meta attributes of this model """ """ meta attributes of this model """
unique_together = ('course_id', 'mode_slug', 'currency') unique_together = ('course_id', 'mode_slug', 'currency')
def save(self, force_insert=False, force_update=False, using=None):
# Ensure currency is always lowercase.
self.currency = self.currency.lower()
super(CourseMode, self).save(force_insert, force_update, using)
@classmethod @classmethod
def all_modes_for_courses(cls, course_id_list): def all_modes_for_courses(cls, course_id_list):
"""Find all modes for a list of course IDs, including expired modes. """Find all modes for a list of course IDs, including expired modes.
...@@ -308,7 +313,7 @@ class CourseMode(models.Model): ...@@ -308,7 +313,7 @@ class CourseMode(models.Model):
""" """
modes = cls.modes_for_course(course_id) modes = cls.modes_for_course(course_id)
for mode in modes: for mode in modes:
if (mode.currency == currency) and (mode.slug == 'verified'): if (mode.currency.lower() == currency.lower()) and (mode.slug == 'verified'):
return mode.min_price return mode.min_price
return 0 return 0
...@@ -490,7 +495,7 @@ class CourseMode(models.Model): ...@@ -490,7 +495,7 @@ class CourseMode(models.Model):
If there is no mode found, will return the price of DEFAULT_MODE, which is 0 If there is no mode found, will return the price of DEFAULT_MODE, which is 0
""" """
modes = cls.modes_for_course(course_id) modes = cls.modes_for_course(course_id)
return min(mode.min_price for mode in modes if mode.currency == currency) return min(mode.min_price for mode in modes if mode.currency.lower() == currency.lower())
@classmethod @classmethod
def enrollment_mode_display(cls, mode, verification_status): def enrollment_mode_display(cls, mode, verification_status):
......
...@@ -39,6 +39,15 @@ class CourseModeModelTest(TestCase): ...@@ -39,6 +39,15 @@ class CourseModeModelTest(TestCase):
currency=currency, currency=currency,
) )
def test_save(self):
""" Verify currency is always lowercase. """
cm, __ = self.create_mode('honor', 'honor', 0, '', 'USD')
self.assertEqual(cm.currency, 'usd')
cm.currency = 'GHS'
cm.save()
self.assertEqual(cm.currency, 'ghs')
def test_modes_for_course_empty(self): def test_modes_for_course_empty(self):
""" """
If we can't find any modes, we should get back the default mode If we can't find any modes, we should get back the default mode
......
...@@ -33,7 +33,7 @@ class CourseApiViewTestMixin(object): ...@@ -33,7 +33,7 @@ class CourseApiViewTestMixin(object):
""" Serialize a CourseMode to a dict. """ """ Serialize a CourseMode to a dict. """
return { return {
u'name': course_mode.mode_slug, u'name': course_mode.mode_slug,
u'currency': course_mode.currency, u'currency': course_mode.currency.lower(),
u'price': course_mode.min_price, u'price': course_mode.min_price,
u'sku': course_mode.sku u'sku': course_mode.sku
} }
......
...@@ -357,7 +357,7 @@ def _payment_accepted(order_id, auth_amount, currency, decision): ...@@ -357,7 +357,7 @@ def _payment_accepted(order_id, auth_amount, currency, decision):
raise CCProcessorDataException(_("The payment processor accepted an order whose number is not in our system.")) raise CCProcessorDataException(_("The payment processor accepted an order whose number is not in our system."))
if decision == 'ACCEPT': if decision == 'ACCEPT':
if auth_amount == order.total_cost and currency == order.currency: if auth_amount == order.total_cost and currency.lower() == order.currency.lower():
return { return {
'accepted': True, 'accepted': True,
'amt_charged': auth_amount, 'amt_charged': auth_amount,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment