Merge pull request #8053 from edx/jsa/xcom-1606
Update ecommerce-api-client and add regression test for XCOM-1606
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" Commerce app tests package. """
|
||||
import json
|
||||
|
||||
@@ -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):
|
||||
""" Tests to ensure the client is initialized properly. """
|
||||
|
||||
TEST_USER_EMAIL = 'test@example.com'
|
||||
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
|
||||
def test_tracking_context(self):
|
||||
""" Ensure the tracking context is set up in the api client correctly
|
||||
and automatically. """
|
||||
user = UserFactory()
|
||||
user.email = self.TEST_USER_EMAIL
|
||||
user.save() # pylint: disable=no-member
|
||||
|
||||
"""
|
||||
Ensure the tracking context is set up in the api client correctly and
|
||||
automatically.
|
||||
"""
|
||||
# fake an ecommerce api request.
|
||||
httpretty.register_uri(
|
||||
httpretty.POST,
|
||||
@@ -47,17 +52,35 @@ class EcommerceApiClientTest(TestCase):
|
||||
mock_tracker = mock.Mock()
|
||||
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):
|
||||
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.
|
||||
actual_header = httpretty.last_request().headers['Authorization']
|
||||
expected_payload = {
|
||||
'username': user.username,
|
||||
'email': user.email,
|
||||
'username': self.user.username,
|
||||
'email': self.user.email,
|
||||
'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,
|
||||
},
|
||||
}
|
||||
expected_header = 'JWT {}'.format(jwt.encode(expected_payload, TEST_API_SIGNING_KEY))
|
||||
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
|
||||
-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/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
|
||||
-e git+https://github.com/mitodl/edx-sga@172a90fd2738f8142c10478356b2d9ed3e55334a#egg=edx-sga
|
||||
|
||||
Reference in New Issue
Block a user