Skip to content

test: update unit test code for test_connection #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/python-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,4 @@ jobs:
source .venv/bin/activate
pytest tests/unittests \
--ignore=tests/unittests/artifacts/test_artifact_service.py \
--ignore=tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py

--ignore=tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def test_get_connection_details_success_with_host(
mock_response = mock.MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {
"name": "test-connection",
"serviceDirectory": "test_service",
"host": "test.host",
"tlsServiceDirectory": "tls_test_service",
Expand All @@ -192,10 +193,10 @@ def test_get_connection_details_success_with_host(
):
details = client.get_connection_details()
assert details == {
"name": "test-connection",
"serviceName": "tls_test_service",
"host": "test.host",
"authOverrideEnabled": True,
"name": "",
}

def test_get_connection_details_success_without_host(
Expand All @@ -206,6 +207,7 @@ def test_get_connection_details_success_without_host(
mock_response = mock.MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {
"name": "test-connection",
"serviceDirectory": "test_service",
"authOverrideEnabled": False,
}
Expand All @@ -215,12 +217,35 @@ def test_get_connection_details_success_without_host(
):
details = client.get_connection_details()
assert details == {
"name": "test-connection",
"serviceName": "test_service",
"host": "",
"authOverrideEnabled": False,
"name": "",
}

def test_get_connection_details_without_name(
self, project, location, connection_name, mock_credentials
):
credentials = {"email": "[email protected]"}
client = ConnectionsClient(project, location, connection_name, credentials)
mock_response = mock.MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = {
"serviceDirectory": "test_service",
"authOverrideEnabled": False,
}

with mock.patch.object(
client, "_execute_api_call", return_value=mock_response
):
details = client.get_connection_details()
assert details == {
"name": "",
"serviceName": "test_service",
"host": "",
"authOverrideEnabled": False,
}

def test_get_connection_details_error(
self, project, location, connection_name
):
Expand Down