'Ensure the tracking context is set up in the api client correctly and
automatically.'

@httpretty.activate
def test_tracking_context(self):

    with freeze_time('2015-7-2'):
        httpretty.register_uri(httpretty.POST, '{}/baskets/1/'.format(settings.ECOMMERCE_API_URL.strip('/')), status=200, body='{}', adding_headers={'Content-Type': JSON})
        mock_tracker = mock.Mock()
        mock_tracker.resolve_context = mock.Mock(return_value={'client_id': self.TEST_CLIENT_ID, 'ip': '127.0.0.1'})
        with mock.patch('openedx.core.djangoapps.commerce.utils.tracker.get_tracker', return_value=mock_tracker):
            ecommerce_api_client(self.user).baskets(1).post()
        actual_header = httpretty.last_request().headers['Authorization']
        claims = {'tracking_context': {'lms_user_id': self.user.id, 'lms_client_id': self.TEST_CLIENT_ID, 'lms_ip': '127.0.0.1'}}
        expected_jwt = JwtBuilder(self.user).build_token(['email', 'profile'], additional_claims=claims)
        expected_header = 'JWT    {}'.format(expected_jwt)
        self.assertEqual(actual_header, expected_header)
