class TestGithub: """Tests bot communication with Github""" def setup_method(self): """ setup any state tied to the execution of the given method in a class. setup_method is invoked for every test method of a class. """ configuration = prepare_conf() self.g_utils = GithubUtils() self.g_utils.create_repo() self.g_utils.setup_repo() # set conf configuration.repository_name = self.g_utils.repo configuration.github_username = self.g_utils.github_user configuration.clone_url = f"https://github.com/{self.g_utils.github_user}/{self.g_utils.repo}.git" configuration.refresh_interval = 1 configuration.project = configuration.get_project() repo_url = f"https://github.com/{self.g_utils.github_user}/{self.g_utils.repo}" git = Git(repo_url, configuration) self.github = Github(configuration, git) def teardown_method(self): """ teardown any state that was previously setup with a setup_method call. """ if self.g_utils.repo: try: self.g_utils.delete_repo() except Exception as ex: # no need to fail the test, just warn warnings.warn(f"Could not delete repository {self.g_utils.repo}: {ex!r}") self.g_utils.repo = None @pytest.fixture() def open_issue(self): """Opens issue in a repository""" return self.g_utils.open_issue() @pytest.fixture() def open_issue_graphql(self): """Opens issue and returns it's GraphQL id""" number = self.g_utils.open_issue() query = f"issue(number: {number}) {{id}}" response = self.github.query_repository(query).json() self.github.detect_api_errors(response) return number, response['data']['repository']['issue']['id'] def test_get_file(self): """Tests fetching release-conf from Github""" assert self.github.get_file("release-conf.yaml") == RELEASE_CONF def test_latest_rls_not_existing(self): """Tests version number when there is no latest release""" assert self.github.latest_release() == '0.0.0' def test_branch_exists_true(self): """Tests if branch exists""" assert self.github.branch_exists('master') def test_branch_exists_false(self): """Tests if branch doesn't exist""" assert not self.github.branch_exists('not-master')
class TestGithub: """Tests bot communication with Github""" def setup_method(self): """ setup any state tied to the execution of the given method in a class. setup_method is invoked for every test method of a class. """ configuration = prepare_conf() self.g_utils = GithubUtils() self.g_utils.create_repo() self.g_utils.setup_repo() # set conf configuration.repository_name = self.g_utils.repo configuration.github_username = self.g_utils.github_user configuration.refresh_interval = 1 repo_url = f"https://github.com/{self.g_utils.github_user}/{self.g_utils.repo}" git = Git(repo_url, configuration) self.github = Github(configuration, git) def teardown_method(self): """ teardown any state that was previously setup with a setup_method call. """ if self.g_utils.repo: self.g_utils.delete_repo() self.g_utils.repo = None @pytest.fixture() def open_issue(self): """Opens issue in a repository""" return self.g_utils.open_issue() @pytest.fixture() def open_issue_graphql(self): """Opens issue and returns it's GraphQL id""" number = self.g_utils.open_issue() query = f"issue(number: {number}) {{id}}" response = self.github.query_repository(query).json() self.github.detect_api_errors(response) return number, response['data']['repository']['issue']['id'] def test_get_configuration(self): """Tests fetching release-conf from Github""" assert self.github.get_configuration() == RELEASE_CONF def test_close_issue(self, open_issue): """Tests closing issue""" assert self.github.close_issue(open_issue) def test_latest_rls_not_existing(self): """Tests version number when there is no latest release""" assert self.github.latest_release() == '0.0.0' def test_branch_exists_true(self): """Tests if branch exists""" assert self.github.branch_exists('master') def test_branch_exists_false(self): """Tests if branch doesn't exist""" assert not self.github.branch_exists('not-master') def test_add_comment(self, open_issue_graphql): """Tests adding comment on issue""" number, graphql_id = open_issue_graphql comments_count = self.g_utils.count_comments(number) self.github.comment = "Test comment" self.github.add_comment(graphql_id) assert self.g_utils.count_comments(number) == comments_count + 1