class TestCommentingGithubIssuesParser(unittest.TestCase, GithubApiTestMixin): def setUp(self): self.init_github() self.gh = get_github_api('TestUser', 'TestPass') self.mock_util = MockUtil('TestOwner', 'TestRepo') self.title = 'Issues' self.issue_number_without_comments = 1 self.issue_number_with_beta_comment = 2 self.issue_number_without_beta_comment = 3 self.issue_number_with_prod_comment = 4 self.issue_number_without_prod_comment = 5 self.pr_number = 6 self.pr_url = 'http://example.com/pulls/{}'.format(self.pr_number) self.tag_prod = 'prod/1.2' self.tag_beta = 'beta/1.2-Beta_3' self.tag_not_prod_or_beta = 'foo' self.version_number_prod = '1.1' self.version_number_beta = '1.2 (Beta 3)' def _create_generator(self, tag): generator = GithubReleaseNotesGenerator( self.gh, self.github_info.copy(), PARSER_CONFIG, tag, publish=True, ) return generator @responses.activate def test_render_issue_without_comments(self): issue_number = self.issue_number_without_comments tag = self.tag_not_prod_or_beta self.mock_util.mock_get_repo() self.mock_util.mock_post_comment(issue_number) # Mock the issue api_url = '{}/issues/{}'.format( self.repo_api_url, issue_number, ) expected_issue = self._get_expected_issue(issue_number) responses.add( method=responses.GET, url=api_url, json=expected_issue, ) # Mock the comments list api_url = '{}/issues/{}/comments'.format( self.repo_api_url, issue_number, ) responses.add( method=responses.GET, url=api_url, body=[], content_type='application/json', ) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [{ 'issue_number': issue_number, 'pr_number': self.pr_number, 'pr_url': self.pr_url, }] expected_render = self._create_expected_render( issue_number, expected_issue['title'], False, ) render = parser.render() self.assertEqual(render, expected_render) self.assertEqual(len(responses.calls._calls), 3) @responses.activate def test_render_issue_with_beta_comment(self): issue_number = self.issue_number_with_beta_comment tag = self.tag_beta self.mock_util.mock_get_repo() self.mock_util.mock_post_comment(issue_number) # Mock the issue api_url = '{}/issues/{}'.format( self.repo_api_url, issue_number, ) expected_issue = self._get_expected_issue(issue_number) responses.add( method=responses.GET, url=api_url, json=expected_issue, ) # Mock the comments list api_url = '{}/issues/{}/comments'.format( self.repo_api_url, issue_number, ) expected_comment_1 = self._get_expected_issue_comment( GithubIssuesParser.ISSUE_COMMENT['beta'], ) expected_comments = [ expected_comment_1, ] responses.add( method=responses.GET, url=api_url, json=expected_comments, ) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [{ 'issue_number': issue_number, 'pr_number': self.pr_number, 'pr_url': self.pr_url, }] expected_render = self._create_expected_render( issue_number, expected_issue['title'], False, ) render = parser.render() self.assertEqual(render, expected_render) self.assertEqual(len(responses.calls._calls), 4) @responses.activate def test_render_issue_without_beta_comment(self): issue_number = self.issue_number_without_beta_comment tag = self.tag_beta self.mock_util.mock_get_repo() # Mock the issue api_url = '{}/issues/{}'.format( self.repo_api_url, issue_number, ) expected_issue = self._get_expected_issue(issue_number) responses.add( method=responses.GET, url=api_url, json=expected_issue, ) # Mock the comments list api_url = '{}/issues/{}/comments'.format( self.repo_api_url, issue_number, ) expected_comment_1 = self._get_expected_issue_comment( 'Some other comment', ) expected_comments = [ expected_comment_1, ] responses.add( method=responses.GET, url=api_url, body=[], content_type='application/json', ) # Mock the comment post response api_url = '{}/issues/{}/comments'.format( self.repo_api_url, issue_number, ) expected_comment_1 = self._get_expected_issue_comment( '{} {}'.format( GithubIssuesParser.ISSUE_COMMENT['beta'], self.version_number_beta, ) ) responses.add( method=responses.POST, url=api_url, json=expected_comment_1, ) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [{ 'issue_number': issue_number, 'pr_number': self.pr_number, 'pr_url': self.pr_url, }] expected_render = self._create_expected_render( issue_number, expected_issue['title'], False, ) self.assertEqual(parser.render(), expected_render) self.assertEqual(len(responses.calls._calls), 5) @responses.activate def test_render_issue_with_prod_comment(self): issue_number = self.issue_number_with_prod_comment tag = self.tag_prod self.mock_util.mock_get_repo() # Mock the issue api_url = '{}/issues/{}'.format( self.repo_api_url, issue_number, ) expected_issue = self._get_expected_issue(issue_number) responses.add( method=responses.GET, url=api_url, json=expected_issue, ) # Mock the comments list api_url = '{}/issues/{}/comments'.format( self.repo_api_url, issue_number, ) expected_comment_1 = self._get_expected_issue_comment( GithubIssuesParser.ISSUE_COMMENT['prod'], ) expected_comments = [ expected_comment_1, ] responses.add( method=responses.GET, url=api_url, json=expected_comments, ) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [{ 'issue_number': issue_number, 'pr_number': self.pr_number, 'pr_url': self.pr_url, }] expected_render = self._create_expected_render( issue_number, expected_issue['title'], False, ) self.assertEqual(parser.render(), expected_render) self.assertEqual(len(responses.calls._calls), 3) @responses.activate def test_render_issue_without_prod_comment(self): issue_number = self.issue_number_without_prod_comment tag = self.tag_prod self.mock_util.mock_get_repo() # Mock the issue api_url = '{}/issues/{}'.format( self.repo_api_url, issue_number, ) expected_issue = self._get_expected_issue(issue_number) responses.add( method=responses.GET, url=api_url, json=expected_issue, ) # Mock the comments list api_url = '{}/issues/{}/comments'.format( self.repo_api_url, issue_number, ) expected_comment_1 = self._get_expected_issue_comment( 'Some other comment', ) expected_comments = [ expected_comment_1, ] responses.add( method=responses.GET, url=api_url, body=[], content_type='application/json', ) # Mock the comment post response api_url = '{}/issues/{}/comments'.format( self.repo_api_url, issue_number, ) expected_comment_1 = self._get_expected_issue_comment( '{} {}'.format( GithubIssuesParser.ISSUE_COMMENT['prod'], self.version_number_prod, ) ) responses.add( method=responses.POST, url=api_url, json=expected_comment_1, ) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [{ 'issue_number': issue_number, 'pr_number': self.pr_number, 'pr_url': self.pr_url, }] expected_render = self._create_expected_render( issue_number, expected_issue['title'], False, ) render = parser.render() self.assertEqual(render, expected_render) self.assertEqual(len(responses.calls._calls), 3) def _create_expected_render(self, issue_number, issue_title, link_pr): render = '# {}\r\n\r\n#{}: {}'.format( self.title, issue_number, issue_title, ) if link_pr: render += ' [[PR{}]({})]'.format(self.pr_number, self.pr_url) return render
class TestCommentingGithubIssuesParser(unittest.TestCase, GithubApiTestMixin): def setUp(self): self.init_github() self.gh = get_github_api("TestUser", "TestPass") self.mock_util = MockUtil("TestOwner", "TestRepo") self.title = "Issues" self.issue_number_without_comments = 1 self.issue_number_with_beta_comment = 2 self.issue_number_without_beta_comment = 3 self.issue_number_with_prod_comment = 4 self.issue_number_without_prod_comment = 5 self.pr_number = 6 self.pr_url = "http://example.com/pulls/{}".format(self.pr_number) self.tag_prod = "release/1.2" self.tag_beta = "beta/1.2-Beta_3" self.tag_not_prod_or_beta = "foo" self.version_number_prod = "1.1" self.version_number_beta = "1.2 (Beta 3)" def _create_generator(self, tag): generator = GithubReleaseNotesGenerator(self.gh, self.github_info.copy(), PARSER_CONFIG, tag, publish=True) return generator @responses.activate def test_render_issue_without_comments(self): issue_number = self.issue_number_without_comments tag = self.tag_not_prod_or_beta self.mock_util.mock_get_repo() self.mock_util.mock_post_comment(issue_number) # Mock the issue api_url = "{}/issues/{}".format(self.repo_api_url, issue_number) expected_issue = self._get_expected_issue(issue_number) responses.add(method=responses.GET, url=api_url, json=expected_issue) # Mock the comments list api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) responses.add(method=responses.GET, url=api_url, body="", content_type="application/json") generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [{ "issue_number": issue_number, "pr_number": self.pr_number, "pr_url": self.pr_url, }] expected_render = self._create_expected_render(issue_number, expected_issue["title"], False) render = parser.render() self.assertEqual(render, expected_render) self.assertEqual(len(responses.calls._calls), 3) @responses.activate def test_render_issue_with_beta_comment(self): issue_number = self.issue_number_with_beta_comment tag = self.tag_beta self.mock_util.mock_get_repo() self.mock_util.mock_post_comment(issue_number) # Mock the issue api_url = "{}/issues/{}".format(self.repo_api_url, issue_number) expected_issue = self._get_expected_issue(issue_number) responses.add(method=responses.GET, url=api_url, json=expected_issue) # Mock the comments list api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) expected_comment_1 = self._get_expected_issue_comment( GithubIssuesParser.ISSUE_COMMENT["beta"]) expected_comments = [expected_comment_1] responses.add(method=responses.GET, url=api_url, json=expected_comments) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [{ "issue_number": issue_number, "pr_number": self.pr_number, "pr_url": self.pr_url, }] expected_render = self._create_expected_render(issue_number, expected_issue["title"], False) render = parser.render() self.assertEqual(render, expected_render) self.assertEqual(len(responses.calls._calls), 4) @responses.activate def test_render_issue_without_beta_comment(self): issue_number = self.issue_number_without_beta_comment tag = self.tag_beta self.mock_util.mock_get_repo() # Mock the issue api_url = "{}/issues/{}".format(self.repo_api_url, issue_number) expected_issue = self._get_expected_issue(issue_number) responses.add(method=responses.GET, url=api_url, json=expected_issue) # Mock the comments list api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) expected_comment_1 = self._get_expected_issue_comment( "Some other comment") expected_comments = [expected_comment_1] responses.add(method=responses.GET, url=api_url, body="", content_type="application/json") # Mock the comment post response api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) expected_comment_1 = self._get_expected_issue_comment("{} {}".format( GithubIssuesParser.ISSUE_COMMENT["beta"], self.version_number_beta)) responses.add(method=responses.POST, url=api_url, json=expected_comment_1) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [{ "issue_number": issue_number, "pr_number": self.pr_number, "pr_url": self.pr_url, }] expected_render = self._create_expected_render(issue_number, expected_issue["title"], False) self.assertEqual(parser.render(), expected_render) self.assertEqual(len(responses.calls._calls), 5) @responses.activate def test_render_issue_with_prod_comment(self): issue_number = self.issue_number_with_prod_comment tag = self.tag_prod self.mock_util.mock_get_repo() # Mock the issue api_url = "{}/issues/{}".format(self.repo_api_url, issue_number) expected_issue = self._get_expected_issue(issue_number) responses.add(method=responses.GET, url=api_url, json=expected_issue) # Mock the comments list api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) expected_comment_1 = self._get_expected_issue_comment( GithubIssuesParser.ISSUE_COMMENT["prod"]) expected_comments = [expected_comment_1] responses.add(method=responses.GET, url=api_url, json=expected_comments) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [{ "issue_number": issue_number, "pr_number": self.pr_number, "pr_url": self.pr_url, }] expected_render = self._create_expected_render(issue_number, expected_issue["title"], False) self.assertEqual(parser.render(), expected_render) self.assertEqual(len(responses.calls._calls), 4) @responses.activate def test_render_issue_without_prod_comment(self): issue_number = self.issue_number_without_prod_comment tag = self.tag_prod self.mock_util.mock_get_repo() # Mock the issue api_url = "{}/issues/{}".format(self.repo_api_url, issue_number) expected_issue = self._get_expected_issue(issue_number) responses.add(method=responses.GET, url=api_url, json=expected_issue) # Mock the comments list api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) expected_comment_1 = self._get_expected_issue_comment( "Some other comment") expected_comments = [expected_comment_1] responses.add(method=responses.GET, url=api_url, body="", content_type="application/json") # Mock the comment post response api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) expected_comment_1 = self._get_expected_issue_comment("{} {}".format( GithubIssuesParser.ISSUE_COMMENT["prod"], self.version_number_prod)) responses.add(method=responses.POST, url=api_url, json=expected_comment_1) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [{ "issue_number": issue_number, "pr_number": self.pr_number, "pr_url": self.pr_url, }] expected_render = self._create_expected_render(issue_number, expected_issue["title"], False) render = parser.render() self.assertEqual(render, expected_render) self.assertEqual(len(responses.calls._calls), 5) def _create_expected_render(self, issue_number, issue_title, link_pr): render = "# {}\r\n\r\n#{}: {}".format(self.title, issue_number, issue_title) if link_pr: render += " [[PR{}]({})]".format(self.pr_number, self.pr_url) return render
class TestCommentingGithubIssuesParser(unittest.TestCase, GithubApiTestMixin): def setUp(self): self.init_github() self.gh = get_github_api("TestUser", "TestPass") self.mock_util = MockUtil("TestOwner", "TestRepo") self.title = "Issues" self.issue_number_without_comments = 1 self.issue_number_with_beta_comment = 2 self.issue_number_without_beta_comment = 3 self.issue_number_with_prod_comment = 4 self.issue_number_without_prod_comment = 5 self.pr_number = 6 self.pr_url = "https://github.com/TestOwner/TestRepo/pulls/{}".format( self.pr_number ) self.tag_prod = "release/1.2" self.tag_beta = "beta/1.2-Beta_3" self.tag_not_prod_or_beta = "foo" self.version_number_prod = "1.1" self.version_number_beta = "1.2 (Beta 3)" def _create_generator(self, tag): generator = GithubReleaseNotesGenerator( self.gh, self.github_info.copy(), PARSER_CONFIG, tag, publish=True ) return generator @responses.activate def test_render_issue_without_comments(self): issue_number = self.issue_number_without_comments tag = self.tag_not_prod_or_beta self.mock_util.mock_get_repo() self.mock_util.mock_post_comment(issue_number) # Mock the issue api_url = "{}/issues/{}".format(self.repo_api_url, issue_number) expected_issue = self._get_expected_issue(issue_number) responses.add(method=responses.GET, url=api_url, json=expected_issue) # Mock the comments list api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) responses.add( method=responses.GET, url=api_url, json=[], content_type="application/json" ) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [ { "issue_number": issue_number, "pr_number": self.pr_number, "pr_url": self.pr_url, } ] expected_render = self._create_expected_render( issue_number, expected_issue["title"], False ) render = parser.render() self.assertEqual(render, expected_render) self.assertEqual(len(responses.calls._calls), 2) @responses.activate def test_render_issue_with_beta_comment(self): issue_number = self.issue_number_with_beta_comment tag = self.tag_beta self.mock_util.mock_get_repo() self.mock_util.mock_post_comment(issue_number) # Mock the issue api_url = "{}/issues/{}".format(self.repo_api_url, issue_number) expected_issue = self._get_expected_issue(issue_number) responses.add(method=responses.GET, url=api_url, json=expected_issue) # Mock the comments list api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) expected_comment_1 = self._get_expected_issue_comment( GithubIssuesParser.ISSUE_COMMENT["beta"] ) expected_comments = [expected_comment_1] responses.add(method=responses.GET, url=api_url, json=expected_comments) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [ { "issue_number": issue_number, "pr_number": self.pr_number, "pr_url": self.pr_url, } ] expected_render = self._create_expected_render( issue_number, expected_issue["title"], False ) render = parser.render() self.assertEqual(render, expected_render) self.assertEqual(len(responses.calls._calls), 3) @responses.activate def test_render_issue_without_beta_comment(self): issue_number = self.issue_number_without_beta_comment tag = self.tag_beta self.mock_util.mock_get_repo() # Mock the issue api_url = "{}/issues/{}".format(self.repo_api_url, issue_number) expected_issue = self._get_expected_issue(issue_number) responses.add(method=responses.GET, url=api_url, json=expected_issue) # Mock the comments list api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) expected_comment_1 = self._get_expected_issue_comment("Some other comment") responses.add( method=responses.GET, url=api_url, json=[], content_type="application/json" ) # Mock the comment post response api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) expected_comment_1 = self._get_expected_issue_comment( "{} {}".format( GithubIssuesParser.ISSUE_COMMENT["beta"], self.version_number_beta ) ) responses.add(method=responses.POST, url=api_url, json=expected_comment_1) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [ { "issue_number": issue_number, "pr_number": self.pr_number, "pr_url": self.pr_url, } ] expected_render = self._create_expected_render( issue_number, expected_issue["title"], False ) self.assertEqual(parser.render(), expected_render) self.assertEqual(len(responses.calls._calls), 4) @responses.activate def test_render_issue_with_prod_comment(self): issue_number = self.issue_number_with_prod_comment tag = self.tag_prod self.mock_util.mock_get_repo() # Mock the issue api_url = "{}/issues/{}".format(self.repo_api_url, issue_number) expected_issue = self._get_expected_issue(issue_number) responses.add(method=responses.GET, url=api_url, json=expected_issue) # Mock the comments list api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) expected_comment_1 = self._get_expected_issue_comment( GithubIssuesParser.ISSUE_COMMENT["prod"] ) expected_comments = [expected_comment_1] responses.add(method=responses.GET, url=api_url, json=expected_comments) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [ { "issue_number": issue_number, "pr_number": self.pr_number, "pr_url": self.pr_url, } ] expected_render = self._create_expected_render( issue_number, expected_issue["title"], False ) self.assertEqual(parser.render(), expected_render) self.assertEqual(len(responses.calls._calls), 3) @responses.activate def test_render_issue_without_prod_comment(self): issue_number = self.issue_number_without_prod_comment tag = self.tag_prod self.mock_util.mock_get_repo() # Mock the issue api_url = "{}/issues/{}".format(self.repo_api_url, issue_number) expected_issue = self._get_expected_issue(issue_number) responses.add(method=responses.GET, url=api_url, json=expected_issue) # Mock the comments list api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) expected_comment_1 = self._get_expected_issue_comment("Some other comment") responses.add( method=responses.GET, url=api_url, json=[], content_type="application/json" ) # Mock the comment post response api_url = "{}/issues/{}/comments".format(self.repo_api_url, issue_number) expected_comment_1 = self._get_expected_issue_comment( "{} {}".format( GithubIssuesParser.ISSUE_COMMENT["prod"], self.version_number_prod ) ) responses.add(method=responses.POST, url=api_url, json=expected_comment_1) generator = self._create_generator(tag) parser = GithubIssuesParser(generator, self.title) parser.content = [ { "issue_number": issue_number, "pr_number": self.pr_number, "pr_url": self.pr_url, } ] expected_render = self._create_expected_render( issue_number, expected_issue["title"], False ) render = parser.render() self.assertEqual(render, expected_render) self.assertEqual(len(responses.calls._calls), 4) def _create_expected_render(self, issue_number, issue_title, link_pr): render = "# {}\r\n\r\n#{}: {}".format(self.title, issue_number, issue_title) if link_pr: render += " [[PR{}]({})]".format(self.pr_number, self.pr_url) return render