def test_lookup_task_basket_error(self, lookup_mock, retry_mock): exc = BasketException(u'Error error error') lookup_mock.side_effect = [exc, None] retry_mock.side_effect = Retry with self.assertRaises(Retry): lookup_user_task(email='*****@*****.**') retry_mock.called_with(exc)
def test_unsubscribe_user_basket_error(self, unsubscribe_mock, retry_mock): result = { 'status': 'ok', 'newsletters': ['foo', 'bar'], 'email': '*****@*****.**', 'token': 'token' } exc = BasketException(u'Error error error') unsubscribe_mock.side_effect = [exc, None] retry_mock.side_effect = Retry with self.assertRaises(Retry): unsubscribe_user_task(result, newsletters=['foo', 'bar']) retry_mock.called_with(exc)
def test_subscribe_user_basket_error(self, subscribe_mock, retry_mock): result = { 'status': 'ok', 'newsletters': ['foo', 'bar'], 'email': '*****@*****.**' } kwargs = { 'result': result, 'email': '*****@*****.**', 'newsletters': ['foobar', 'foo'] } exc = BasketException(u'Error error error') subscribe_mock.side_effect = [exc, None] retry_mock.side_effect = Retry with self.assertRaises(Retry): subscribe_user_task(**kwargs) retry_mock.called_with(exc)
def test_lookup_task_user_not_found(self, lookup_mock): lookup_mock.side_effect = BasketException(u'User not found') result = lookup_user_task(email='*****@*****.**') eq_(result, {})
def raise_basket_exception(*args, **kwargs): raise BasketException('foobar', code=BASKET_UNKNOWN_EMAIL, status_code=404)