From acb141a99025895b6ce2610bd8c0d04725bdd3f9 Mon Sep 17 00:00:00 2001 From: Clinton Blackburn Date: Fri, 13 Mar 2015 02:36:22 -0400 Subject: [PATCH] Corrected data sent to E-Commerce API Data is now properly encoded as JSON. --- lms/djangoapps/commerce/tests.py | 2 +- lms/djangoapps/commerce/views.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/commerce/tests.py b/lms/djangoapps/commerce/tests.py index c26e05a75f..b3f79fbd91 100644 --- a/lms/djangoapps/commerce/tests.py +++ b/lms/djangoapps/commerce/tests.py @@ -184,7 +184,7 @@ class OrdersViewTests(ModuleStoreTestCase): # Verify the correct information was passed to the E-Commerce API request = httpretty.last_request() sku = CourseMode.objects.filter(course_id=self.course.id, mode_slug='honor', sku__isnull=False)[0].sku - self.assertEqual(request.body, 'sku={}'.format(sku)) + self.assertEqual(request.body, '{{"sku": "{}"}}'.format(sku)) self.assertEqual(request.headers['Content-Type'], 'application/json') # Verify the JWT is correct diff --git a/lms/djangoapps/commerce/views.py b/lms/djangoapps/commerce/views.py index c16ab8fa52..e029998e9e 100644 --- a/lms/djangoapps/commerce/views.py +++ b/lms/djangoapps/commerce/views.py @@ -1,5 +1,5 @@ """ Commerce views. """ - +import json import logging from simplejson import JSONDecodeError @@ -111,7 +111,8 @@ class OrdersView(APIView): try: timeout = getattr(settings, 'ECOMMERCE_API_TIMEOUT', 5) - response = requests.post(url, data={'sku': course_modes[0].sku}, headers=headers, timeout=timeout) + response = requests.post(url, data=json.dumps({'sku': course_modes[0].sku}), headers=headers, + timeout=timeout) except Exception as ex: # pylint: disable=broad-except log.exception('Call to E-Commerce API failed: %s.', ex.message) return ApiErrorResponse()