def test_fetch_issues(self): """Test whether a list of issues is returned""" body = read_file('data/pagure/pagure_repo_issue_1') httpretty.register_uri( httpretty.GET, PAGURE_ISSUES_URL, body=body, status=200, ) pagure = Pagure(repository='Project-example', api_token='aaa') issues = [ issues for issues in pagure.fetch(from_date=None, to_date=None) ] self.assertEqual(len(issues), 1) issue = issues[0] self.assertEqual(issue['origin'], 'https://pagure.io/Project-example') self.assertEqual(issue['uuid'], '41071b08dd75f34ca92c6d5ecb844e7a3e5939c6') self.assertEqual(issue['updated_on'], 1583508642.0) self.assertEqual(issue['category'], CATEGORY_ISSUE) self.assertEqual(issue['tag'], 'https://pagure.io/Project-example') self.assertEqual(len(issue['data']['comments']), 1) self.assertEqual(issue['data']['comments'][0]['user']['name'], 'animeshk08') self.assertEqual(len(issue['data']['comments'][0]['reactions']), 0)
def test_fetch_from_date(self): """Test when fetching issues from a given date""" body = read_file('data/pagure/pagure_repo_issue_from_2020_03_07') httpretty.register_uri(httpretty.GET, PAGURE_ISSUES_URL, body=body, status=200, ) from_date = datetime.datetime(2020, 3, 7) pagure = Pagure(repository='Project-example') issues = [issues for issues in pagure.fetch(from_date=from_date)] self.assertEqual(len(issues), 1) issue = issues[0] self.assertEqual(issue['origin'], 'https://pagure.io/Project-example') self.assertEqual(issue['uuid'], '7dd3642664c8a7e475814b9037277df775657850') self.assertEqual(issue['updated_on'], 1583558174.0) self.assertEqual(issue['category'], CATEGORY_ISSUE) self.assertEqual(issue['tag'], 'https://pagure.io/Project-example') self.assertEqual(issue['data']['assignee']['name'], 'animeshk0806') self.assertEqual(len(issue['data']['comments']), 2) self.assertEqual(issue['data']['comments'][0]['user']['name'], 'animeshk08')
def setUp(self): super().setUp() self.backend_write_archive = Pagure(repository='Project-example', api_token='aaa', archive=self.archive) self.backend_read_archive = Pagure(repository='Project-example', api_token='aaa', archive=self.archive)
def test_fetch_more_issues(self): """Test when return two issues""" issue_1 = read_file('data/pagure/pagure_repo_issue_1') issue_2 = read_file('data/pagure/pagure_repo_only_issue_2') httpretty.register_uri( httpretty.GET, PAGURE_ISSUES_URL, body=issue_1, status=200, forcing_headers={ 'Link': '<' + PAGURE_ISSUES_URL + '/?&page=2>; rel="next", <' + PAGURE_ISSUES_URL + '/?&page=3>; rel="last"' }) httpretty.register_uri( httpretty.GET, PAGURE_ISSUES_URL + '/?&page=2', body=issue_2, status=200, ) pagure = Pagure(repository='Project-example') issues = [issues for issues in pagure.fetch()] self.assertEqual(len(issues), 2) issue = issues[0] self.assertEqual(issue['origin'], 'https://pagure.io/Project-example') self.assertEqual(issue['uuid'], '41071b08dd75f34ca92c6d5ecb844e7a3e5939c6') self.assertEqual(issue['updated_on'], 1583508642.0) self.assertEqual(issue['category'], CATEGORY_ISSUE) self.assertEqual(issue['tag'], 'https://pagure.io/Project-example') self.assertEqual(len(issue['data']['comments']), 1) self.assertEqual(issue['data']['comments'][0]['user']['name'], 'animeshk08') self.assertEqual(issue['data']['assignee']['name'], 'animeshk08') self.assertEqual(len(issue['data']['comments'][0]['reactions']), 0) issue = issues[1] self.assertEqual(issue['origin'], 'https://pagure.io/Project-example') self.assertEqual(issue['uuid'], '7dd3642664c8a7e475814b9037277df775657850') self.assertEqual(issue['updated_on'], 1583558174.0) self.assertEqual(issue['category'], CATEGORY_ISSUE) self.assertEqual(issue['tag'], 'https://pagure.io/Project-example') self.assertEqual(issue['data']['assignee']['name'], 'animeshk0806') self.assertEqual(len(issue['data']['comments']), 2) self.assertEqual(issue['data']['comments'][0]['user']['name'], 'animeshk08') self.assertEqual(len(issue['data']['comments'][0]['reactions']), 0) self.assertEqual(len(issue['data']['comments'][1]['reactions']), 1) self.assertListEqual( issue['data']['comments'][1]['reactions']['Thumbs up'], ['animeshk0806'])
def test_fetch_issues_namespace(self): """Test issues fetch from a repository within a namespace""" issue_1 = read_file('data/pagure/pagure_namespace_issue_2') httpretty.register_uri( httpretty.GET, PAGURE_NAMESPACE_ISSUES_URL, body=issue_1, status=200, ) pagure = Pagure(namespace='Test-group', repository='Project-namespace-example') issues = [issues for issues in pagure.fetch()] self.assertEqual(len(issues), 2) issue = issues[0] self.assertEqual( issue['origin'], 'https://pagure.io/Test-group/Project-namespace-example') self.assertEqual(issue['uuid'], 'bdf90e94bf3b17ed2f75f5e5187e21a62512ca5a') self.assertEqual(issue['updated_on'], 1583509042.0) self.assertEqual(issue['category'], CATEGORY_ISSUE) self.assertEqual( issue['tag'], 'https://pagure.io/Test-group/Project-namespace-example') self.assertEqual(issue['data']['assignee']['name'], 'animeshk08') self.assertEqual(len(issue['data']['comments']), 1) self.assertEqual(issue['data']['comments'][0]['user']['name'], 'animeshk08') self.assertEqual(len(issue['data']['comments'][0]['reactions']), 0) issue = issues[1] self.assertEqual( issue['origin'], 'https://pagure.io/Test-group/Project-namespace-example') self.assertEqual(issue['uuid'], 'eec4d7bf5c3ca405e39f39a8c6faf616fd4fa425') self.assertEqual(issue['updated_on'], 1583562831.0) self.assertEqual(issue['category'], CATEGORY_ISSUE) self.assertEqual( issue['tag'], 'https://pagure.io/Test-group/Project-namespace-example') self.assertEqual(issue['data']['assignee']['name'], 'animeshk0806') self.assertEqual(len(issue['data']['comments']), 2) self.assertEqual(issue['data']['comments'][1]['user']['name'], 'animeshk08') self.assertEqual(len(issue['data']['comments'][0]['reactions']), 1) self.assertListEqual( issue['data']['comments'][0]['reactions']['Heart'], ['animeshk0806'])
def test_initialization(self): """Test whether attributes are initialized""" pagure = Pagure(namespace=None, repository='Project-example', api_token='aaa', tag='test') # Testing initialization when repository is not within a namespace self.assertEqual(pagure.repository, 'Project-example') self.assertIsNone(pagure.namespace) self.assertEqual(pagure.origin, 'https://pagure.io/Project-example') self.assertEqual(pagure.tag, 'test') self.assertEqual(pagure.max_items, MAX_CATEGORY_ITEMS_PER_PAGE) self.assertEqual(pagure.categories, [CATEGORY_ISSUE]) self.assertEqual(pagure.api_token, 'aaa') self.assertTrue(pagure.ssl_verify) # When tag is empty or None it will be set to the value in origin pagure = Pagure(namespace=None, repository='Project-example', api_token='aaa', ssl_verify=False) self.assertEqual(pagure.repository, 'Project-example') self.assertIsNone(pagure.namespace) self.assertEqual(pagure.origin, 'https://pagure.io/Project-example') self.assertEqual(pagure.tag, 'https://pagure.io/Project-example') self.assertFalse(pagure.ssl_verify) self.assertEqual(pagure.api_token, 'aaa') pagure = Pagure(namespace=None, repository='Project-example', api_token='aaa', tag='') self.assertEqual(pagure.repository, 'Project-example') self.assertIsNone(pagure.namespace) self.assertEqual(pagure.origin, 'https://pagure.io/Project-example') self.assertEqual(pagure.tag, 'https://pagure.io/Project-example') self.assertEqual(pagure.api_token, 'aaa') # Empty value generates a None API token pagure = Pagure(repository='Project-example', tag='test') self.assertEqual(pagure.repository, 'Project-example') self.assertIsNone(pagure.namespace) self.assertEqual(pagure.origin, 'https://pagure.io/Project-example') self.assertEqual(pagure.tag, 'test') self.assertIsNone(pagure.api_token) # Testing initialization when repository is within a namespace pagure = Pagure(namespace='Test-group', repository='Project-example-namespace', api_token='aaa', tag='testing') self.assertEqual(pagure.repository, 'Project-example-namespace') self.assertEqual(pagure.namespace, 'Test-group') self.assertEqual(pagure.origin, 'https://pagure.io/Test-group/Project-example-namespace') self.assertEqual(pagure.tag, 'testing') self.assertEqual(pagure.max_items, MAX_CATEGORY_ITEMS_PER_PAGE) self.assertEqual(pagure.categories, [CATEGORY_ISSUE]) self.assertEqual(pagure.api_token, 'aaa') self.assertTrue(pagure.ssl_verify)
def test_fetch_empty(self): """Test when return empty""" body = "" httpretty.register_uri(httpretty.GET, PAGURE_ISSUES_URL, body=body, status=200, ) from_date = datetime.datetime(2016, 1, 1) pagure = Pagure(repository='Project-example', api_token='aaa') issues = [issues for issues in pagure.fetch(from_date=from_date)] self.assertEqual(len(issues), 0)
def test_search_fields_issues(self): """Test whether the search_fields is properly set""" body = read_file('data/pagure/pagure_repo_issue_1') httpretty.register_uri(httpretty.GET, PAGURE_ISSUES_URL, body=body, status=200, ) pagure = Pagure(repository='Project-example', api_token='aaa') issues = [issues for issues in pagure.fetch(from_date=None, to_date=None)] issue = issues[0] self.assertEqual(pagure.metadata_id(issue['data']), issue['search_fields']['item_id']) self.assertIsNone(issue['search_fields']['namespace']) self.assertEqual(issue['search_fields']['repo'], 'Project-example')
def test_fetch_issues_until_date(self): """Test when fetching issues till a particular date""" issue_1 = read_file('data/pagure/pagure_repo_issue_1') issue_2 = read_file('data/pagure/pagure_repo_only_issue_2') httpretty.register_uri( httpretty.GET, PAGURE_ISSUES_URL, body=issue_1, status=200, forcing_headers={ 'Link': '<' + PAGURE_ISSUES_URL + '/?&page=2>; rel="next", <' + PAGURE_ISSUES_URL + '/?&page=3>; rel="last"' }) httpretty.register_uri( httpretty.GET, PAGURE_ISSUES_URL + '/?&page=2', body=issue_2, status=200, ) to_date = datetime.datetime(2020, 3, 7) pagure = Pagure(repository='Project-example') issues = [issues for issues in pagure.fetch(to_date=to_date)] self.assertEqual(len(issues), 1) issue = issues[0] self.assertEqual(issue['origin'], 'https://pagure.io/Project-example') self.assertEqual(issue['uuid'], '41071b08dd75f34ca92c6d5ecb844e7a3e5939c6') self.assertEqual(issue['updated_on'], 1583508642.0) self.assertEqual(issue['category'], CATEGORY_ISSUE) self.assertEqual(issue['tag'], 'https://pagure.io/Project-example') self.assertEqual(issue['data']['assignee']['name'], 'animeshk08') self.assertEqual(len(issue['data']['comments']), 1) self.assertEqual(issue['data']['comments'][0]['user']['name'], 'animeshk08')
def test_fetch_issues_disabled(self): """Test whether a warning message is logged when the issue tracker is disabled""" body = read_file('data/pagure/pagure_empty_request') httpretty.register_uri(httpretty.GET, PAGURE_ISSUES_URL, body=body, status=404, ) pagure = Pagure(repository='Project-test-example') with self.assertLogs(logger, level='WARN') as cm: issues = [issues for issues in pagure.fetch(from_date=None, to_date=None)] print(cm.output[0]) self.assertEqual(cm.output[0], 'WARNING:perceval.backends.core.pagure:' 'The issue tracker is disabled please enable' ' the feature for the repository') self.assertListEqual(issues, [])
def test_has_archiving(self): """Test if it returns True when has_archiving is called""" self.assertEqual(Pagure.has_archiving(), True)