Skip to content

Commit 774a778

Browse files
committed
chore: added client integration tests
1 parent a05c672 commit 774a778

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
"""Integration tests for Chronicle log type and parser validation functions.
16+
17+
These tests require valid credentials and API access.
18+
They interact with real Chronicle API endpoints.
19+
"""
20+
21+
import pytest
22+
23+
from secops import SecOpsClient
24+
from secops.exceptions import APIError
25+
from ..config import CHRONICLE_CONFIG, SERVICE_ACCOUNT_JSON
26+
27+
28+
@pytest.mark.integration
29+
def test_log_type_lifecycle_integration():
30+
"""Test the complete log-type lifecycle."""
31+
client = SecOpsClient(service_account_info=SERVICE_ACCOUNT_JSON)
32+
33+
# 5. Testing parser validation workflow
34+
dummy_project_id = "140410331797"
35+
dummy_customer_id = "ebdc4bb9-878b-11e7-8455-10604b7cb5c1"
36+
37+
dummy_chronicle = client.chronicle(
38+
project_id=dummy_project_id,
39+
customer_id=dummy_customer_id,
40+
region=CHRONICLE_CONFIG.get("region", "us"),
41+
)
42+
43+
print("\nTesting trigger_github_checks with dummy data")
44+
try:
45+
# Trigger checks for a dummy PR and log type
46+
result = dummy_chronicle.trigger_github_checks(
47+
associated_pr="google/secops-wrapper/pull/617",
48+
log_type="DUMMY_LOGTYPE",
49+
)
50+
assert isinstance(result, dict)
51+
print("Successfully triggered checks (or received valid JSON response)")
52+
except (APIError, Exception) as e:
53+
# We expect a failure due to dummy data, but we want to confirm
54+
# it reached the server or handled the routing correctly.
55+
error_msg = str(e)
56+
assert (
57+
"api error" in error_msg.lower()
58+
or "error" in error_msg.lower()
59+
or "failed" in error_msg.lower()
60+
)
61+
print(
62+
f"Server gracefully handled the dummy trigger data: {error_msg.strip()}"
63+
)
64+
65+
print("\nTesting get_analysis_report with dummy data")
66+
try:
67+
# Request a report for dummy resource names
68+
report = dummy_chronicle.get_analysis_report(
69+
log_type="DUMMY_LOGTYPE", parser_id="xyz", report_id="123"
70+
)
71+
assert isinstance(report, dict)
72+
print("Successfully retrieved report")
73+
except (APIError, Exception) as e:
74+
# We expect a 404 or similar since the report is dummy
75+
error_msg = str(e)
76+
assert (
77+
"api error" in error_msg.lower()
78+
or "error" in error_msg.lower()
79+
or "not found" in error_msg.lower()
80+
)
81+
print(
82+
f"Server gracefully handled dummy report request: {error_msg.strip()}"
83+
)
84+
85+
86+
if __name__ == "__main__":
87+
pytest.main(["-v", __file__, "-m", "integration"])

0 commit comments

Comments
 (0)