Ejemplo n.º 1
0
 def test_update_followers_for_candidate_ok(self, store_mock, new_mock, previous_mock):
     twitter = MagicMock()
     candidate = Candidate(**{'screen_name': 'test'})
     FollowerUpdateService.update_followers_for_candidate(twitter, candidate)
     assert store_mock.call_count == 1
     assert new_mock.call_count == 1
     assert previous_mock.call_count == 1
Ejemplo n.º 2
0
 def test_update_with_credential_ok(self, unlock_mock, finish_mock, update_mock, next_mock, twitter_mock):
     credential = Credential(**{'ID': 'test', 'CONSUMER_KEY': 'test', 'CONSUMER_SECRET': 'test'})
     FollowerUpdateService.update_with_credential(credential)
     assert unlock_mock.call_count == 1
     assert finish_mock.call_count == 1
     assert update_mock.call_count == 1
     assert next_mock.call_count == 2
     assert twitter_mock.call_count == 1
Ejemplo n.º 3
0
 def test_update_with_credential_no_candidates(self, unlock_mock, finish_mock, update_mock, next_mock, twitter_mock):
     FollowerUpdateHelper.ITERATIONS = 0
     credential = Credential(**{'ID': 'test', 'CONSUMER_KEY': 'test', 'CONSUMER_SECRET': 'test'})
     FollowerUpdateService.update_with_credential(credential)
     assert unlock_mock.call_count == 1
     assert finish_mock.call_count == 0
     assert update_mock.call_count == 0
     assert next_mock.call_count == 1
     assert twitter_mock.call_count == 1
Ejemplo n.º 4
0
 def test_update_followers_for_candidate_integration(self, store_mock, previous_mock, time_mock, continue_mock):
     twitter = MagicMock()
     twitter.get_followers_ids.side_effect = FollowerUpdateHelper.mock_get_followers_ids_with_exception
     candidate = Candidate(**{'screen_name': 'test'})
     FollowerUpdateService.update_followers_for_candidate(twitter, candidate)
     assert store_mock.call_count == 1
     assert previous_mock.call_count == 1
     assert time_mock.call_count == 1
     assert twitter.get_followers_ids.call_count == 3
     assert continue_mock.call_count == 2
Ejemplo n.º 5
0
 def test_do_request_with_exception(self, time_mock):
     twitter = MagicMock()
     twitter.get_followers_ids.side_effect = FollowerUpdateHelper.mock_get_followers_ids_with_exception
     response = FollowerUpdateService.do_request(twitter, 'test', 0)
     assert response is not None
     assert response == {'ids': [12, 324], 'next_cursor': 678}
     assert twitter.get_followers_ids.call_count == 2
     assert time_mock.call_count == 1
Ejemplo n.º 6
0
 def test_get_new_followers_ids(self, request_mock, retrieve_mock):
     twitter = MagicMock()
     candidate = Candidate(**{'screen_name': 'test'})
     followers_ids = ['123', '456', '789']
     # Do test
     new_followers = FollowerUpdateService.get_new_followers_ids(twitter, candidate, followers_ids)
     assert retrieve_mock.call_count == 2
     assert request_mock.call_count == 2  # Once outside the while, once inside of it
     assert len(new_followers) == 4
     assert new_followers == {'12', '324', '678', '55'}
Ejemplo n.º 7
0
 def initialize_context(cls):
     """ Create instances of all environment services in a Spring-like fashion."""
     cls.LOGGER.info('Instantiating context services and components.')
     ConfigurationManager()
     ConcurrencyUtils()
     Scheduler()
     CandidateDAO()
     RawFollowerDAO()
     CandidatesFollowersDAO()
     CredentialService()
     CandidateService()
     FollowerUpdateService()
     TweetUpdateService()
     FollowersQueueService()
Ejemplo n.º 8
0
 def test_update_followers_credentials_exception(self, async_mock, credentials_mock):
     FollowerUpdateService.update_followers()
     assert credentials_mock.call_count == 1
     assert async_mock.call_count == 0
Ejemplo n.º 9
0
 def test_next_candidate_no_more_candidates_to_update(self, get_mock):
     candidate = FollowerUpdateService.next_candidate()
     assert candidate is None
     assert get_mock.call_count == 1
Ejemplo n.º 10
0
 def test_next_candidate_ok(self, get_mock):
     candidate = FollowerUpdateService.next_candidate()
     assert candidate is not None
     assert candidate.screen_name == 'test'
     assert get_mock.call_count == 1
Ejemplo n.º 11
0
 def test_should_retrieve_more_followers_false(self, get_mock):
     result = FollowerUpdateService.should_retrieve_more_followers({'012', '234', '463'}, {'012', '234', '987'})
     assert not result
     assert get_mock.call_count == 1
Ejemplo n.º 12
0
 def test_store_new_followers(self, increase_mock, put_mock):
     FollowerUpdateService.store_new_followers({'012', '324', '678', '055'}, 'test-name')
     assert put_mock.call_count == 4
     assert increase_mock.call_count == 1