def setUp(self): self.repo_name = "some-name" self.public_key = "1PjwOt4yg9yZsEQLUOCPqZRigVMPA4g+6cuGc2ssS1c=" self.public_key_id = "09835109" self.secret_name = "A_SECRET" self.secret_value = "AKDJFLS" self.valid_github_config = GithubConfig({ "organization": "some_org", "login": "******", "password": "******", }) self.create_repo_args = ("some name", "some description", "true") self.mock_create_repo = Mock() self.mock_get_user = Mock() self.mock_get_user.create_repo = self.mock_create_repo self.mock_response_return = { "key": self.public_key, "key_id": self.public_key_id, } self.mock_requests_get = Mock() self.mock_requests_get.return_value = MockResponse( 200, self.mock_response_return) github.requests.get = self.mock_requests_get self.mock_requests_put = Mock() self.mock_requests_put.return_value = MockResponse( 204, self.mock_response_return) github.requests.put = self.mock_requests_put self.rli_github = RLIGithub(self.valid_github_config)
def test_get_public_key_unsuccessful(self): self.mock_requests_get.return_value = MockResponse( 403, self.mock_requests_get) with self.assertRaises(GithubException) as context: self.rli_github.get_public_key(self.repo_name) self.assertEqual(403, context.exception.status) self.assertEqual(self.mock_requests_get, context.exception.data) self.mock_requests_get.assert_called_once_with( url= f"{GITHUB_URL}/repos/{self.valid_github_config.organization}/{self.repo_name}/actions/secrets/public-key", auth=(self.valid_github_config.login, self.valid_github_config.password), )
def test_add_secrets_error_request(self): self.mock_requests_put.return_value = MockResponse( 400, self.mock_response_return) with self.assertRaises(GithubException) as context: self.rli_github.add_secrets( self.repo_name, [self.secret_name], {self.secret_name: self.secret_value}, ) self.mock_requests_get.assert_called_once_with( url= f"{GITHUB_URL}/repos/{self.valid_github_config.organization}/{self.repo_name}/actions/secrets/public-key", auth=(self.valid_github_config.login, self.valid_github_config.password), ) self.mock_requests_put.assert_called_once() self.assertEqual(400, context.exception.status)
def mock_request(self, status=200, content=None): return MockResponse(status=status, content=content)