def test_returns_error_if_api_call_fails(self): self.add_response( body='{"errors":[{"message":"Rate limit exceeded","code":88}]}', status=429) result = VerifyFetcher(screen_name='jill').fetch() self.assertFalse(result[0]['success']) self.assertIn('Rate limit exceeded', result[0]['messages'][0])
def test_returns_correct_success_response(self): "Data returned is correct" self.add_response(body=self.make_response_body()) result = VerifyFetcher().fetch() self.assertEqual(len(result), 2) self.assertTrue(result[1]['account'], 'jill') self.assertTrue(result[1]['success'])
def test_returns_error_if_no_creds(self): "If an account has no API credentials, the result is correct" user = UserFactory(screen_name='bobby') account = AccountFactory(user=user) self.add_response(body=self.make_response_body()) result = VerifyFetcher(screen_name='bobby').fetch() self.assertFalse(result[0]['success']) self.assertIn('Account has no API credentials', result[0]['messages'][0])
def test_saves_users(self): "Updates the Account's user data in the DB with fetched data." user = UserFactory(twitter_id=12552, screen_name='philgyford', name='This should change') account = AccountWithCredentialsFactory(id=4, user=user) self.add_response(body=self.make_response_body()) result = VerifyFetcher(screen_name='philgyford').fetch() user_reloaded = User.objects.get(screen_name='philgyford') self.assertEqual(user_reloaded.name, 'Phil Gyford')
def test_ignores_account_with_no_creds(self, fetch_avatar): user_3 = UserFactory() account_3 = AccountFactory(user=user_3) self.add_response(body=self.make_response_body()) result = VerifyFetcher().fetch() self.assertEqual(2, len(responses.calls))
def test_api_requests_for_all_accounts(self, fetch_avatar): self.add_response(body=self.make_response_body()) result = VerifyFetcher().fetch() self.assertEqual(2, len(responses.calls))
def test_api_request_for_one_account(self, fetch_avatar): self.add_response(body=self.make_response_body()) result = VerifyFetcher(screen_name='jill').fetch() self.assertEqual(1, len(responses.calls))