def test_get_two_valid_badges_id(self): base_url = r'<div class="c-grid-item c-grid-item--stack-lt-sm cr-public-organization-badge-' + \ r'template-grid-item" href="/org/{company}/badge/'.format(company=self.company) + \ r'{badge_id}">Nothing</div>' badges_ids = [ 'hello-world', '"></spam class="Nikki-93-Micah', 'what.eVer.123', ] urls = [ 'Url #1', 'Url #2', 'Url #3', ] responses = [ base_url.format(badge_id=badges_ids[0]), base_url.format(badge_id=badges_ids[1]), base_url.format(badge_id=badges_ids[2]), ] expected_badges_ids = [ badges_ids[0], badges_ids[2], ] self.MockGetAllUrls.return_value.get_urls = urls self.MockUrllib3_requested.data.decode.side_effect = responses get_all = GetAll(self.company) get_all._multiprocess = False get_all.execute() badges_ids = get_all.get_badges_id self.assertEqual(expected_badges_ids, badges_ids)
def test_get_number_of_badges_from_the_class_get_all_urls(self): expected_badges = 29843 self.MockGetAllUrls.return_value.get_badges = expected_badges get_all = GetAll(self.company) get_all._multiprocessing_badges = lambda x: x get_all.execute() number_of_badges = get_all.get_number_of_badges self.assertEqual(expected_badges, number_of_badges)
def test_when_an_invalid_call_the_class_get_all_urls_returns_an_empty_badges_id( self): expected_badges = [] self.MockGetAllUrls_execute.return_value = False get_all = GetAll(self.company) get_all._badges_id = None # Be sure that it's returning an empty list get_all.execute() badges = get_all.get_badges_id self.assertEqual(expected_badges, badges)
def test_when_an_invalid_call_the_class_get_all_urls_returns_false(self): expected_executed = False self.MockGetAllUrls_execute.return_value = False get_all = GetAll(self.company) executed = get_all.execute() self.assertEqual(expected_executed, executed)
def test_when_get_zero_urls(self): expected_executed = False self.MockGetAllUrls.return_value.get_urls = [] get_all = GetAll(self.company) executed = get_all.execute() self.assertEqual(expected_executed, executed)
def test_when_the_data_request_is_invalid(self): urls = [ 'Url #1', 'Url #2', 'Url #3', ] expected_calls = [ call('GET', urls[0]), call('GET', urls[1]), call('GET', urls[2]), ] self.MockGetAllUrls.return_value.get_urls = urls self.MockUrllib3_requested.data = None get_all = GetAll(self.company) get_all._multiprocess = False get_all.execute() self.MockUrllib3_request.assert_has_calls(expected_calls)
def main(): """ Main """ from app.acclaim.badges.GetAll import GetAll get_all_badges = GetAll('ibm') get_all_badges._max_workers = 256000 if get_all_badges.execute(): badges = get_all_badges.get_badges_id print('# Badges:', len(badges))
def test_call_the_class_get_all_urls(self): get_all = GetAll(self.company) get_all.execute() self.MockGetAllUrls.assert_called_once_with(self.company) self.MockGetAllUrls_execute.assert_called_once()