Commit 36060f3f by Jim Abramson

Merge pull request #8053 from edx/jsa/xcom-1606

Update ecommerce-api-client and add regression test for XCOM-1606
parents b98d85fd 31a232ed
# -*- coding: utf-8 -*-
""" Commerce app tests package. """ """ Commerce app tests package. """
import json import json
...@@ -22,21 +23,25 @@ TEST_PAYMENT_DATA = { ...@@ -22,21 +23,25 @@ TEST_PAYMENT_DATA = {
} }
@override_settings(ECOMMERCE_API_SIGNING_KEY=TEST_API_SIGNING_KEY, ECOMMERCE_API_URL=TEST_API_URL)
class EcommerceApiClientTest(TestCase): class EcommerceApiClientTest(TestCase):
""" Tests to ensure the client is initialized properly. """ """ Tests to ensure the client is initialized properly. """
TEST_USER_EMAIL = 'test@example.com' TEST_USER_EMAIL = 'test@example.com'
TEST_CLIENT_ID = 'test-client-id' TEST_CLIENT_ID = 'test-client-id'
@override_settings(ECOMMERCE_API_SIGNING_KEY=TEST_API_SIGNING_KEY, ECOMMERCE_API_URL=TEST_API_URL) def setUp(self):
super(EcommerceApiClientTest, self).setUp()
self.user = UserFactory()
self.user.email = self.TEST_USER_EMAIL
self.user.save() # pylint: disable=no-member
@httpretty.activate @httpretty.activate
def test_tracking_context(self): def test_tracking_context(self):
""" Ensure the tracking context is set up in the api client correctly """
and automatically. """ Ensure the tracking context is set up in the api client correctly and
user = UserFactory() automatically.
user.email = self.TEST_USER_EMAIL """
user.save() # pylint: disable=no-member
# fake an ecommerce api request. # fake an ecommerce api request.
httpretty.register_uri( httpretty.register_uri(
httpretty.POST, httpretty.POST,
...@@ -47,17 +52,35 @@ class EcommerceApiClientTest(TestCase): ...@@ -47,17 +52,35 @@ class EcommerceApiClientTest(TestCase):
mock_tracker = mock.Mock() mock_tracker = mock.Mock()
mock_tracker.resolve_context = mock.Mock(return_value={'client_id': self.TEST_CLIENT_ID}) mock_tracker.resolve_context = mock.Mock(return_value={'client_id': self.TEST_CLIENT_ID})
with mock.patch('commerce.tracker.get_tracker', return_value=mock_tracker): with mock.patch('commerce.tracker.get_tracker', return_value=mock_tracker):
ecommerce_api_client(user).baskets(1).post() ecommerce_api_client(self.user).baskets(1).post()
# make sure the request's JWT token payload included correct tracking context values. # make sure the request's JWT token payload included correct tracking context values.
actual_header = httpretty.last_request().headers['Authorization'] actual_header = httpretty.last_request().headers['Authorization']
expected_payload = { expected_payload = {
'username': user.username, 'username': self.user.username,
'email': user.email, 'email': self.user.email,
'tracking_context': { 'tracking_context': {
'lms_user_id': user.id, # pylint: disable=no-member 'lms_user_id': self.user.id, # pylint: disable=no-member
'lms_client_id': self.TEST_CLIENT_ID, 'lms_client_id': self.TEST_CLIENT_ID,
}, },
} }
expected_header = 'JWT {}'.format(jwt.encode(expected_payload, TEST_API_SIGNING_KEY)) expected_header = 'JWT {}'.format(jwt.encode(expected_payload, TEST_API_SIGNING_KEY))
self.assertEqual(actual_header, expected_header) self.assertEqual(actual_header, expected_header)
@httpretty.activate
def test_client_unicode(self):
"""
The client should handle json responses properly when they contain
unicode character data.
Regression test for ECOM-1606.
"""
expected_content = '{"result": "Préparatoire"}'
httpretty.register_uri(
httpretty.GET,
'{}/baskets/1/order/'.format(TEST_API_URL),
status=200, body=expected_content,
adding_headers={'Content-Type': 'application/json'},
)
actual_object = ecommerce_api_client(self.user).baskets(1).order.get()
self.assertEqual(actual_object, {u"result": u"Préparatoire"})
...@@ -50,7 +50,7 @@ git+https://github.com/edx/edx-lint.git@8bf82a32ecb8598c415413df66f5232ab8d974e9 ...@@ -50,7 +50,7 @@ git+https://github.com/edx/edx-lint.git@8bf82a32ecb8598c415413df66f5232ab8d974e9
-e git+https://github.com/edx/xblock-utils.git@581ed636c862b286002bb9a3724cc883570eb54c#egg=xblock-utils -e git+https://github.com/edx/xblock-utils.git@581ed636c862b286002bb9a3724cc883570eb54c#egg=xblock-utils
-e git+https://github.com/edx-solutions/xblock-google-drive.git@138e6fa0bf3a2013e904a085b9fed77dab7f3f21#egg=xblock-google-drive -e git+https://github.com/edx-solutions/xblock-google-drive.git@138e6fa0bf3a2013e904a085b9fed77dab7f3f21#egg=xblock-google-drive
-e git+https://github.com/edx/edx-reverification-block.git@2ff0d21f6614874067168bd244e68d8215041f3b#egg=edx-reverification-block -e git+https://github.com/edx/edx-reverification-block.git@2ff0d21f6614874067168bd244e68d8215041f3b#egg=edx-reverification-block
git+https://github.com/edx/ecommerce-api-client.git@0.3.0#egg=ecommerce-api-client==0.3.0 git+https://github.com/edx/ecommerce-api-client.git@0.4.3#egg=ecommerce-api-client==0.4.3
# Third Party XBlocks # Third Party XBlocks
-e git+https://github.com/mitodl/edx-sga@172a90fd2738f8142c10478356b2d9ed3e55334a#egg=edx-sga -e git+https://github.com/mitodl/edx-sga@172a90fd2738f8142c10478356b2d9ed3e55334a#egg=edx-sga
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