def test_auth_token_known_error(self):
        """
        If there's an error code in the response, raise an
        ETRestError.
        """
        backend = ExactTargetRest()
        backend._request = Mock()
        backend._request.return_value.json.return_value = {"errorcode": "17", "message": "SNAKES"}
        with self.assertRaises(ETRestError) as ETRE:
            backend.auth_token

        self.assertEqual(str(ETRE.exception), "17: SNAKES")
Esempio n. 2
0
def add_sms_user(send_name, mobile_number, optin):
    messages = get_sms_messages()
    if send_name not in messages:
        return
    et = ExactTargetRest()

    try:
        et.send_sms([mobile_number], messages[send_name])
    except ETRestError as error:
        return add_sms_user.retry(exc=error)

    if optin:
        add_sms_user_optin.delay(mobile_number)
    def test_auth_token_expired(self):
        backend = ExactTargetRest()
        with patch("news.backends.exacttarget_rest.time.time") as mock_time:
            # Not expired
            mock_time.return_value = 100
            backend._access_token_expires = 200
            backend._access_token_expire_buffer = 50
            self.assertFalse(backend.auth_token_expired())

            # Not expired but within buffer
            mock_time.return_value = 100
            backend._access_token_expires = 120
            backend._access_token_expire_buffer = 50
            self.assertTrue(backend.auth_token_expired())

            # Expired
            mock_time.return_value = 100
            backend._access_token_expires = 80
            backend._access_token_expire_buffer = 50
            self.assertTrue(backend.auth_token_expired())
 def test_auth_token_has_token(self):
     """If we already have a valid auth token, return it."""
     backend = ExactTargetRest()
     backend._access_token = "mytoken"
     backend.auth_token_expired = Mock(return_value=False)
     self.assertEqual(backend.auth_token, "mytoken")