Skip to content

Commit eacf74c

Browse files
committed
update unit test code for test_connection
1 parent 905c20d commit eacf74c

File tree

2 files changed

+51
-26
lines changed

2 files changed

+51
-26
lines changed

.github/workflows/python-unit-tests.yml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Python Unit Tests
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88

99
jobs:
1010
test:
@@ -14,28 +14,26 @@ jobs:
1414
python-version: ["3.9", "3.10", "3.11"]
1515

1616
steps:
17-
- name: Checkout code
18-
uses: actions/checkout@v4
17+
- name: Checkout code
18+
uses: actions/checkout@v4
1919

20-
- name: Set up Python ${{ matrix.python-version }}
21-
uses: actions/setup-python@v5
22-
with:
23-
python-version: ${{ matrix.python-version }}
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
2424

25-
- name: Install uv
26-
run: curl -LsSf https://astral.sh/uv/install.sh | sh
25+
- name: Install uv
26+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
2727

28-
- name: Install dependencies
29-
run: |
30-
uv venv .venv
31-
source .venv/bin/activate
32-
uv sync --extra test --extra eval
28+
- name: Install dependencies
29+
run: |
30+
uv venv .venv
31+
source .venv/bin/activate
32+
uv sync --extra test --extra eval
3333
34-
- name: Run unit tests with pytest
35-
run: |
36-
source .venv/bin/activate
37-
pytest tests/unittests \
38-
--ignore=tests/unittests/artifacts/test_artifact_service.py \
39-
--ignore=tests/unittests/tools/application_integration_tool/clients/test_connections_client.py \
40-
--ignore=tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py
41-
34+
- name: Run unit tests with pytest
35+
run: |
36+
source .venv/bin/activate
37+
pytest tests/unittests \
38+
--ignore=tests/unittests/artifacts/test_artifact_service.py \
39+
--ignore=tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py

tests/unittests/tools/application_integration_tool/clients/test_connections_client.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def test_get_connection_details_success_with_host(
169169
mock_response = mock.MagicMock()
170170
mock_response.status_code = 200
171171
mock_response.json.return_value = {
172+
"name": "test-connection",
172173
"serviceDirectory": "test_service",
173174
"host": "test.host",
174175
"tlsServiceDirectory": "tls_test_service",
@@ -180,6 +181,7 @@ def test_get_connection_details_success_with_host(
180181
):
181182
details = client.get_connection_details()
182183
assert details == {
184+
"name": "test-connection",
183185
"serviceName": "tls_test_service",
184186
"host": "test.host",
185187
"authOverrideEnabled": True,
@@ -193,6 +195,7 @@ def test_get_connection_details_success_without_host(
193195
mock_response = mock.MagicMock()
194196
mock_response.status_code = 200
195197
mock_response.json.return_value = {
198+
"name": "test-connection",
196199
"serviceDirectory": "test_service",
197200
"authOverrideEnabled": False,
198201
}
@@ -202,11 +205,35 @@ def test_get_connection_details_success_without_host(
202205
):
203206
details = client.get_connection_details()
204207
assert details == {
208+
"name": "test-connection",
205209
"serviceName": "test_service",
206210
"host": "",
207211
"authOverrideEnabled": False,
208212
}
213+
214+
def test_get_connection_details_without_name(
215+
self, project, location, connection_name, mock_credentials
216+
):
217+
credentials = {"email": "[email protected]"}
218+
client = ConnectionsClient(project, location, connection_name, credentials)
219+
mock_response = mock.MagicMock()
220+
mock_response.status_code = 200
221+
mock_response.json.return_value = {
222+
"serviceDirectory": "test_service",
223+
"authOverrideEnabled": False,
224+
}
209225

226+
with mock.patch.object(
227+
client, "_execute_api_call", return_value=mock_response
228+
):
229+
details = client.get_connection_details()
230+
assert details == {
231+
"name": "",
232+
"serviceName": "test_service",
233+
"host": "",
234+
"authOverrideEnabled": False,
235+
}
236+
210237
def test_get_connection_details_error(
211238
self, project, location, connection_name
212239
):
@@ -419,21 +446,21 @@ def test_get_operation_static(self):
419446
def test_create_operation(self):
420447
operation = ConnectionsClient.create_operation("Entity1", "test_tool")
421448
assert "post" in operation
422-
assert operation["post"]["summary"] == "Create Entity1"
449+
assert operation["post"]["summary"] == "Creates a new Entity1"
423450
assert "operationId" in operation["post"]
424451
assert operation["post"]["operationId"] == "test_tool_create_Entity1"
425452

426453
def test_update_operation(self):
427454
operation = ConnectionsClient.update_operation("Entity1", "test_tool")
428455
assert "post" in operation
429-
assert operation["post"]["summary"] == "Update Entity1"
456+
assert operation["post"]["summary"] == "Updates the Entity1"
430457
assert "operationId" in operation["post"]
431458
assert operation["post"]["operationId"] == "test_tool_update_Entity1"
432459

433460
def test_delete_operation(self):
434461
operation = ConnectionsClient.delete_operation("Entity1", "test_tool")
435462
assert "post" in operation
436-
assert operation["post"]["summary"] == "Delete Entity1"
463+
assert operation["post"]["summary"] == "Delete the Entity1"
437464
assert operation["post"]["operationId"] == "test_tool_delete_Entity1"
438465

439466
def test_create_operation_request(self):

0 commit comments

Comments
 (0)