Esempio n. 1
0
    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

        # fake an ecommerce api request.
        httpretty.register_uri(
            httpretty.POST,
            '{}/baskets/1/'.format(TEST_API_URL),
            status=200,
            body='{}',
            adding_headers={'Content-Type': 'application/json'})
        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()

        # 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,
            'tracking_context': {
                'lms_user_id': 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)
Esempio n. 2
0
def test_is_email_retired_is_retired():
    """
    Check functionality of is_email_retired when email is retired
    """
    user = UserFactory()
    original_email = user.email
    retired_email = get_retired_email_by_email(user.email)

    # Fake email retirement.
    user.email = retired_email
    user.save()

    assert is_email_retired(original_email)
Esempio n. 3
0
def test_is_email_retired_is_retired():
    """
    Check functionality of is_email_retired when email is retired
    """
    user = UserFactory()
    original_email = user.email
    retired_email = get_retired_email_by_email(user.email)

    # Fake email retirement.
    user.email = retired_email
    user.save()

    assert is_email_retired(original_email)