def test_bitbucket(bitbucket_data, env_vars, mocker, patches): mocker.patch('cloud_build_status.credentials.get_ciphertext', return_value='FALKJFLKN') mocker.patch('cloud_build_status.credentials.decrypt', return_value='{"username":"******", "password":"******"}') main.build_status(bitbucket_data, None) cloud_build_status.credentials.get_ciphertext.assert_called_once_with( 'my-secrets-bucket', 'bitbucket') cloud_build_status.credentials.decrypt.assert_called_once_with( 'projects/my-project/locations/global/keyRings/secrets/cryptoKeys/build-status', 'FALKJFLKN') provider.requests.post.assert_called_once_with( 'https://api.bitbucket.org/2.0/repositories/garman/webapp/commit/65ca6a99a2573f0f1ff5dc93f78a77966248ea2d/statuses/build', auth=('lg', '12345678'), json={ 'description': 'SUCCESS', 'state': 'SUCCESSFUL', 'name': 'Google Cloud Build', 'url': 'https://console.cloud.google.com/gcr/builds/aeccd2ef-f51a-4a44-8e2e-0de2609ce367?project=292927648743', 'key': '2bceb582-3141-44bf-b444-5640cbcaecc5' })
def test_github(github_data, env_vars, mocker, patches): mocker.patch('cloud_build_status.credentials.get_ciphertext', return_value='FALKJFLKN') mocker.patch('cloud_build_status.credentials.decrypt', return_value='{"username":"******", "password":"******"}') main.build_status(github_data, None) cloud_build_status.credentials.get_ciphertext.assert_called_once_with( 'my-secrets-bucket', 'github') cloud_build_status.credentials.decrypt.assert_called_once_with( 'projects/my-project/locations/global/keyRings/secrets/cryptoKeys/build-status', 'FALKJFLKN') provider.requests.post.assert_called_once_with( 'https://api.github.com/repos/leg100/webapp/statuses/d985a61daddbcd9c05a06d199efc2aeca55e4a19', auth=('leg100', 'password1'), json={ 'description': 'SUCCESS', 'state': 'success', 'context': 'Google Cloud Build', 'target_url': 'https://console.cloud.google.com/gcr/builds/aeccd2ef-f51a-4a44-8e2e-0de2609ce367?project=292927648743', })
def test_github_invalid_password(github_data, env_vars, mocker, patches): credentials.Credentials._data = {} mocker.patch('cloud_build_status.credentials.get_ciphertext', return_value='FALKJFLKN') mocker.patch('cloud_build_status.credentials.decrypt', return_value='{"username":"******", "password":"******"}') with pytest.raises(RuntimeError, match="403"): main.build_status(github_data, None)
def test_ignore_event(github_app_data, env_vars, mocker, patches): main.build_status(github_app_data, None) provider.requests.post.assert_not_called()
def test_bitbucket_second_invocation(bitbucket_data, env_vars, patches): main.build_status(bitbucket_data, None) cloud_build_status.credentials.get_ciphertext.assert_not_called() cloud_build_status.credentials.decrypt.assert_not_called()