11import pytest
22
33from elementary .messages .blocks import Icon
4+ from elementary .monitor .alerts .alert import OrchestratorInfo
45from elementary .monitor .alerts .model_alert import ModelAlertModel
56from elementary .monitor .alerts .source_freshness_alert import SourceFreshnessAlertModel
67from elementary .monitor .alerts .test_alert import TestAlertModel
@@ -15,12 +16,12 @@ class TestOrchestratorLinkCreation:
1516 """Test orchestrator link creation functionality."""
1617
1718 def test_create_orchestrator_link_with_valid_data (self ):
18- orchestrator_info = {
19- " job_name" : "nightly_load" ,
20- " run_id" : "12345" ,
21- " orchestrator" : "airflow" ,
22- " run_url" : "https://airflow.example.com/run/12345" ,
23- }
19+ orchestrator_info = OrchestratorInfo (
20+ job_name = "nightly_load" ,
21+ run_id = "12345" ,
22+ orchestrator = "airflow" ,
23+ run_url = "https://airflow.example.com/run/12345" ,
24+ )
2425
2526 link = create_orchestrator_link (orchestrator_info )
2627
@@ -30,25 +31,25 @@ def test_create_orchestrator_link_with_valid_data(self):
3031 assert link .icon == Icon .LINK
3132
3233 def test_create_orchestrator_link_without_url_returns_none (self ):
33- orchestrator_info = {
34- " job_name" : "nightly_load" ,
35- " orchestrator" : " airflow"
34+ orchestrator_info = OrchestratorInfo (
35+ job_name = "nightly_load" ,
36+ orchestrator = " airflow",
3637 # No run_url
37- }
38+ )
3839
3940 link = create_orchestrator_link (orchestrator_info )
4041 assert link is None
4142
4243 def test_create_orchestrator_link_with_empty_info_returns_none (self ):
43- link = create_orchestrator_link ({} )
44+ link = create_orchestrator_link (OrchestratorInfo () )
4445 assert link is None
4546
4647 def test_create_job_link_with_valid_data (self ):
47- orchestrator_info = {
48- " job_name" : "nightly_load" ,
49- " orchestrator" : "airflow" ,
50- " job_url" : "https://airflow.example.com/job/nightly_load" ,
51- }
48+ orchestrator_info = OrchestratorInfo (
49+ job_name = "nightly_load" ,
50+ orchestrator = "airflow" ,
51+ job_url = "https://airflow.example.com/job/nightly_load" ,
52+ )
5253
5354 link = create_job_link (orchestrator_info )
5455
@@ -59,11 +60,11 @@ def test_create_job_link_with_valid_data(self):
5960 assert link .icon == Icon .GEAR
6061
6162 def test_create_job_link_without_url_returns_none (self ):
62- orchestrator_info = {
63- " job_name" : "nightly_load" ,
64- " orchestrator" : " airflow"
63+ orchestrator_info = OrchestratorInfo (
64+ job_name = "nightly_load" ,
65+ orchestrator = " airflow",
6566 # No job_url
66- }
67+ )
6768
6869 link = create_job_link (orchestrator_info )
6970 assert link is None
@@ -92,11 +93,11 @@ def test_test_alert_orchestrator_info_with_complete_data(self):
9293
9394 info = alert .orchestrator_info
9495 assert info is not None
95- assert info [ " job_name" ] == "nightly_load"
96- assert info [ " run_id" ] == "12345"
97- assert info [ " orchestrator" ] == "airflow"
98- assert info [ " job_url" ] == "https://airflow.example.com/job/nightly_load"
99- assert info [ " run_url" ] == "https://airflow.example.com/run/12345"
96+ assert info . job_name == "nightly_load"
97+ assert info . run_id == "12345"
98+ assert info . orchestrator == "airflow"
99+ assert info . job_url == "https://airflow.example.com/job/nightly_load"
100+ assert info . run_url == "https://airflow.example.com/run/12345"
100101
101102 def test_test_alert_orchestrator_info_with_minimal_data (self ):
102103 alert = TestAlertModel (
@@ -115,8 +116,10 @@ def test_test_alert_orchestrator_info_with_minimal_data(self):
115116
116117 info = alert .orchestrator_info
117118 assert info is not None
118- assert info ["job_name" ] == "test_job"
119- assert len (info ) == 1
119+ assert info .job_name == "test_job"
120+ # Other fields should be None
121+ assert info .run_id is None
122+ assert info .orchestrator is None
120123
121124 def test_test_alert_orchestrator_info_with_no_data_returns_none (self ):
122125 alert = TestAlertModel (
@@ -152,10 +155,10 @@ def test_model_alert_orchestrator_info(self):
152155
153156 info = alert .orchestrator_info
154157 assert info is not None
155- assert info [ " job_name" ] == "nightly_build"
156- assert info [ " run_id" ] == "67890"
157- assert info [ " orchestrator" ] == "dbt_cloud"
158- assert info [ " run_url" ] == "https://cloud.getdbt.com/run/67890"
158+ assert info . job_name == "nightly_build"
159+ assert info . run_id == "67890"
160+ assert info . orchestrator == "dbt_cloud"
161+ assert info . run_url == "https://cloud.getdbt.com/run/67890"
159162
160163 def test_source_freshness_alert_orchestrator_info (self ):
161164 alert = SourceFreshnessAlertModel (
@@ -174,9 +177,9 @@ def test_source_freshness_alert_orchestrator_info(self):
174177
175178 info = alert .orchestrator_info
176179 assert info is not None
177- assert info [ " job_name" ] == "freshness_check"
178- assert info [ " orchestrator" ] == "airflow"
179- assert info [ " run_url" ] == "https://airflow.example.com/run/111"
180+ assert info . job_name == "freshness_check"
181+ assert info . orchestrator == "airflow"
182+ assert info . run_url == "https://airflow.example.com/run/111"
180183
181184
182185class TestOrchestratorInfoEdgeCases :
@@ -201,7 +204,7 @@ def test_orchestrator_info_with_empty_strings(self):
201204 info = alert .orchestrator_info
202205 assert info is None
203206
204- def test_orchestrator_info_filters_none_values (self ):
207+ def test_orchestrator_info_sets_none_for_empty_values (self ):
205208 alert = TestAlertModel (
206209 id = "test_id" ,
207210 test_unique_id = "test_unique_id" ,
@@ -219,10 +222,9 @@ def test_orchestrator_info_filters_none_values(self):
219222
220223 info = alert .orchestrator_info
221224 assert info is not None
222- assert "job_name" in info
223- assert "orchestrator" not in info
224- assert "run_url" not in info
225- assert len (info ) == 1
225+ assert info .job_name == "valid_job"
226+ assert info .orchestrator is None
227+ assert info .run_url is None
226228
227229 def test_orchestrator_info_with_only_run_id (self ):
228230 alert = TestAlertModel (
@@ -240,8 +242,9 @@ def test_orchestrator_info_with_only_run_id(self):
240242
241243 info = alert .orchestrator_info
242244 assert info is not None
243- assert info ["run_id" ] == "12345"
244- assert len (info ) == 1
245+ assert info .run_id == "12345"
246+ assert info .job_name is None
247+ assert info .orchestrator is None
245248
246249 def test_orchestrator_info_with_only_orchestrator (self ):
247250 alert = TestAlertModel (
@@ -259,8 +262,9 @@ def test_orchestrator_info_with_only_orchestrator(self):
259262
260263 info = alert .orchestrator_info
261264 assert info is not None
262- assert info ["orchestrator" ] == "dbt_cloud"
263- assert len (info ) == 1
265+ assert info .orchestrator == "dbt_cloud"
266+ assert info .job_name is None
267+ assert info .run_id is None
264268
265269
266270class TestOrchestratorLinkDataModel :
0 commit comments