From 6c142533b13aca0a2f4be789eff122194b0ade85 Mon Sep 17 00:00:00 2001 From: tcezard Date: Tue, 24 Feb 2026 15:12:46 +0000 Subject: [PATCH 1/2] Ensure that the call home payload matches the schema --- eva_sub_cli/call_home.py | 2 +- tests/test_call_home.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/eva_sub_cli/call_home.py b/eva_sub_cli/call_home.py index b4ab60c..fd0d2cf 100644 --- a/eva_sub_cli/call_home.py +++ b/eva_sub_cli/call_home.py @@ -99,7 +99,7 @@ def _send_event(self, event_type, **kwargs): def send_start(self): self._send_event(EVENT_START) - def send_validation_completed(self, validation_result): + def send_validation_completed(self, validation_result: dict): self._send_event(EVENT_VALIDATION_COMPLETED, validation_result=validation_result) def send_end(self): diff --git a/tests/test_call_home.py b/tests/test_call_home.py index cb1801b..92b0143 100644 --- a/tests/test_call_home.py +++ b/tests/test_call_home.py @@ -1,3 +1,4 @@ +import json import os import shutil import time @@ -5,12 +6,15 @@ from unittest import TestCase from unittest.mock import patch +import jsonschema + from ebi_eva_common_pyutils.config import Configuration, WritableConfig from requests.exceptions import ConnectionError, Timeout from eva_sub_cli import SUB_CLI_CONFIG_FILE, ROOT_DIR from eva_sub_cli.call_home import _get_or_create_deployment_id, _get_or_create_run_id, \ CallHomeClient, EVENT_START, EVENT_FAILURE, EVENT_END +from tests.test_report import common_validation_results class TestDeploymentId(TestCase): @@ -163,12 +167,22 @@ def test_generic_exception_swallowed(self, mock_post): @patch('eva_sub_cli.call_home.requests.post') def test_send_all_event_types(self, mock_post): + schema_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), + '..', 'eva_sub_cli', 'etc', 'call_home_payload_schema.json') + with open(schema_path) as f: + schema = json.load(f) + client = self._create_client() client.send_start() - client.send_validation_completed('PASS') + client.send_validation_completed({'Results': common_validation_results}) client.send_end() self.assertEqual(mock_post.call_count, 3) + for call in mock_post.call_args_list: + payload = call.kwargs['json'] + jsonschema.validate(instance=payload, schema=schema) + + @patch('eva_sub_cli.call_home.requests.post') def test_send_failure_event(self, mock_post): client = self._create_client() From 8291d40d43330fa9951a6949bd7ff54897223f57 Mon Sep 17 00:00:00 2001 From: tcezard Date: Tue, 24 Feb 2026 15:21:35 +0000 Subject: [PATCH 2/2] Simplify the test --- tests/test_call_home.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_call_home.py b/tests/test_call_home.py index 92b0143..f41a933 100644 --- a/tests/test_call_home.py +++ b/tests/test_call_home.py @@ -174,7 +174,7 @@ def test_send_all_event_types(self, mock_post): client = self._create_client() client.send_start() - client.send_validation_completed({'Results': common_validation_results}) + client.send_validation_completed(common_validation_results) client.send_end() self.assertEqual(mock_post.call_count, 3)