def test_get_issues_for_org_merges_issues_pull_requests(github, requests_mock): """ The '_get_issues_for_org' helper should merge both issues with pull requests and treat them both as issues """ repo1 = fixtures.repository( issues=[fixtures.issue(), fixtures.issue(), fixtures.issue()], pull_requests=[fixtures.issue(pr=True)], private=False ) repo2 = fixtures.repository( issues=[fixtures.issue(), fixtures.issue()], pull_requests=[fixtures.issue(pr=True), fixtures.issue(pr=True)], private=False ) expected_titles_are_pr = {} for repo in [repo1, repo2]: for issue in repo['issues']['nodes']: expected_titles_are_pr[issue['title']] = False for pull_request in repo['pullRequests']['nodes']: expected_titles_are_pr[pull_request['title']] = True api_response_body = fixtures.api_response_body(repos=[repo1, repo2]) requests_mock.add_github_graphql(json=api_response_body) issues = github._get_issues_for_org(requests.Session(), 'org') titles_are_pr = {i['title']: i['is_pull_request'] for i in issues} assert titles_are_pr == expected_titles_are_pr
def test_get_issues_for_org_merges_issues_pull_requests(github, requests_mock): """ The '_get_issues_for_org' helper should merge both issues with pull requests and treat them both as issues """ repo1 = fixtures.repository( issues=[fixtures.issue(), fixtures.issue(), fixtures.issue()], pull_requests=[fixtures.issue(pr=True)], private=False) repo2 = fixtures.repository( issues=[fixtures.issue(), fixtures.issue()], pull_requests=[fixtures.issue(pr=True), fixtures.issue(pr=True)], private=False) expected_titles_are_pr = {} for repo in [repo1, repo2]: for issue in repo['issues']['nodes']: expected_titles_are_pr[issue['title']] = False for pull_request in repo['pullRequests']['nodes']: expected_titles_are_pr[pull_request['title']] = True api_response_body = fixtures.api_response_body(repos=[repo1, repo2]) requests_mock.add_github_graphql(json=api_response_body) issues = github._get_issues_for_org(requests.Session(), 'org') titles_are_pr = {i['title']: i['is_pull_request'] for i in issues} assert titles_are_pr == expected_titles_are_pr
def test_get_issues_merges_orgs(github, requests_mock): """ Tests whether 'get_issues' makes two HTTP requests for each given GitHub organization name and whether both data gets combined in the results """ issue_org1 = fixtures.issue() requests_mock.add_github_graphql(json=fixtures.api_response_body(repos=[ fixtures.repository( issues=[issue_org1], pull_requests=[], private=False), ]), ) issue_org2 = fixtures.issue() requests_mock.add_github_graphql(json=fixtures.api_response_body(repos=[ fixtures.repository( issues=[issue_org2], pull_requests=[], private=False), ]), ) issues = github.get_issues(['org1', 'org2']) titles = set(i['title'] for i in issues) assert titles == {issue_org1['title'], issue_org2['title']}
def test_get_issues_merges_orgs(github, requests_mock): """ Tests whether 'get_issues' makes two HTTP requests for each given GitHub organization name and whether both data gets combined in the results """ issue_org1 = fixtures.issue() requests_mock.add_github_graphql( json=fixtures.api_response_body(repos=[ fixtures.repository(issues=[issue_org1], pull_requests=[], private=False), ]), ) issue_org2 = fixtures.issue() requests_mock.add_github_graphql( json=fixtures.api_response_body(repos=[ fixtures.repository(issues=[issue_org2], pull_requests=[], private=False), ]), ) issues = github.get_issues(['org1', 'org2']) titles = set(i['title'] for i in issues) assert titles == {issue_org1['title'], issue_org2['title']}
def test_get_issues_for_org_skips_private(github, requests_mock): """ The '_get_issues_for_org' helper should skip private repositories """ public_repo = fixtures.repository(private=False) expected_titles = set() for issue in public_repo['issues']['nodes']: expected_titles.add(issue['title']) for pull_request in public_repo['pullRequests']['nodes']: expected_titles.add(pull_request['title']) api_response_body = fixtures.api_response_body(repos=[ fixtures.repository(private=True), public_repo, fixtures.repository(private=True), fixtures.repository(private=True), fixtures.repository(private=True), ]) requests_mock.add_github_graphql(json=api_response_body) issues = github._get_issues_for_org(requests.Session(), 'org') titles = set(i['title'] for i in issues) assert titles == expected_titles