44
55import pytest
66
7- from wildedge import config
7+ from wildedge import constants
88
99
1010@pytest .fixture (autouse = True )
@@ -15,6 +15,7 @@ def mock_dependencies():
1515 patch ("wildedge.client.Transmitter" ),
1616 patch ("wildedge.client.Consumer" ),
1717 patch ("wildedge.client.EventQueue" ),
18+ patch ("wildedge.client.DeadLetterStore" ),
1819 patch ("wildedge.client.ModelRegistry" ),
1920 ):
2021 yield
@@ -25,7 +26,7 @@ def test_batch_size_too_low():
2526
2627 with pytest .raises (
2728 ValueError ,
28- match = f"batch_size must be between { config .BATCH_SIZE_MIN } and { config .BATCH_SIZE_MAX } " ,
29+ match = f"batch_size must be between { constants .BATCH_SIZE_MIN } and { constants .BATCH_SIZE_MAX } " ,
2930 ):
3031 WildEdge (dsn = "https://test@test.com/key" , batch_size = 0 )
3132
@@ -35,7 +36,7 @@ def test_batch_size_too_high():
3536
3637 with pytest .raises (
3738 ValueError ,
38- match = f"batch_size must be between { config .BATCH_SIZE_MIN } and { config .BATCH_SIZE_MAX } " ,
39+ match = f"batch_size must be between { constants .BATCH_SIZE_MIN } and { constants .BATCH_SIZE_MAX } " ,
3940 ):
4041 WildEdge (dsn = "https://test@test.com/key" , batch_size = 101 )
4142
@@ -45,7 +46,7 @@ def test_flush_interval_too_low():
4546
4647 with pytest .raises (
4748 ValueError ,
48- match = f"flush_interval_sec must be between { config .FLUSH_INTERVAL_MIN } and { config .FLUSH_INTERVAL_MAX } " ,
49+ match = f"flush_interval_sec must be between { constants .FLUSH_INTERVAL_MIN } and { constants .FLUSH_INTERVAL_MAX } " ,
4950 ):
5051 WildEdge (dsn = "https://test@test.com/key" , flush_interval_sec = 0 )
5152
@@ -55,7 +56,7 @@ def test_flush_interval_too_high():
5556
5657 with pytest .raises (
5758 ValueError ,
58- match = f"flush_interval_sec must be between { config .FLUSH_INTERVAL_MIN } and { config .FLUSH_INTERVAL_MAX } " ,
59+ match = f"flush_interval_sec must be between { constants .FLUSH_INTERVAL_MIN } and { constants .FLUSH_INTERVAL_MAX } " ,
5960 ):
6061 WildEdge (dsn = "https://test@test.com/key" , flush_interval_sec = 3601 )
6162
@@ -65,7 +66,7 @@ def test_max_queue_size_too_low():
6566
6667 with pytest .raises (
6768 ValueError ,
68- match = f"max_queue_size must be between { config .MAX_QUEUE_SIZE_MIN } and { config .MAX_QUEUE_SIZE_MAX } " ,
69+ match = f"max_queue_size must be between { constants .MAX_QUEUE_SIZE_MIN } and { constants .MAX_QUEUE_SIZE_MAX } " ,
6970 ):
7071 WildEdge (dsn = "https://test@test.com/key" , max_queue_size = 9 )
7172
@@ -75,7 +76,7 @@ def test_max_queue_size_too_high():
7576
7677 with pytest .raises (
7778 ValueError ,
78- match = f"max_queue_size must be between { config .MAX_QUEUE_SIZE_MIN } and { config .MAX_QUEUE_SIZE_MAX } " ,
79+ match = f"max_queue_size must be between { constants .MAX_QUEUE_SIZE_MIN } and { constants .MAX_QUEUE_SIZE_MAX } " ,
7980 ):
8081 WildEdge (dsn = "https://test@test.com/key" , max_queue_size = 10001 )
8182
@@ -91,3 +92,72 @@ def test_valid_values():
9192 max_queue_size = 500 ,
9293 )
9394 assert client is not None
95+
96+
97+ def test_max_event_age_must_be_positive ():
98+ from wildedge .client import WildEdge
99+
100+ with pytest .raises (ValueError , match = "max_event_age_sec must be greater than 0" ):
101+ WildEdge (dsn = "https://test@test.com/key" , max_event_age_sec = 0 )
102+
103+
104+ def test_max_dead_letter_batches_must_be_non_negative ():
105+ from wildedge .client import WildEdge
106+
107+ with pytest .raises (ValueError , match = "max_dead_letter_batches must be >= 0" ):
108+ WildEdge (dsn = "https://test@test.com/key" , max_dead_letter_batches = - 1 )
109+
110+
111+ def test_app_identity_defaults_to_project_key ():
112+ from wildedge .client import WildEdge
113+
114+ with (
115+ patch (
116+ "wildedge.client.default_pending_queue_dir" , return_value = "pending-dir"
117+ ) as p ,
118+ patch ("wildedge.client.default_dead_letter_dir" , return_value = "dead-dir" ) as d ,
119+ patch (
120+ "wildedge.client.default_model_registry_path" , return_value = "registry-path"
121+ ) as r ,
122+ ):
123+ WildEdge (dsn = "https://test@test.com/proj-key" )
124+ p .assert_called_once_with ("proj-key" )
125+ d .assert_called_once_with ("proj-key" )
126+ r .assert_called_once_with ("proj-key" )
127+
128+
129+ def test_app_identity_override_used_for_paths ():
130+ from wildedge .client import WildEdge
131+
132+ with (
133+ patch (
134+ "wildedge.client.default_pending_queue_dir" , return_value = "pending-dir"
135+ ) as p ,
136+ patch ("wildedge.client.default_dead_letter_dir" , return_value = "dead-dir" ) as d ,
137+ patch (
138+ "wildedge.client.default_model_registry_path" , return_value = "registry-path"
139+ ) as r ,
140+ ):
141+ WildEdge (dsn = "https://test@test.com/proj-key" , app_identity = "app-a" )
142+ p .assert_called_once_with ("app-a" )
143+ d .assert_called_once_with ("app-a" )
144+ r .assert_called_once_with ("app-a" )
145+
146+
147+ def test_app_identity_env_override_used_for_paths (monkeypatch ):
148+ from wildedge .client import WildEdge
149+
150+ monkeypatch .setenv (constants .ENV_APP_IDENTITY , "env-app" )
151+ with (
152+ patch (
153+ "wildedge.client.default_pending_queue_dir" , return_value = "pending-dir"
154+ ) as p ,
155+ patch ("wildedge.client.default_dead_letter_dir" , return_value = "dead-dir" ) as d ,
156+ patch (
157+ "wildedge.client.default_model_registry_path" , return_value = "registry-path"
158+ ) as r ,
159+ ):
160+ WildEdge (dsn = "https://test@test.com/proj-key" )
161+ p .assert_called_once_with ("env-app" )
162+ d .assert_called_once_with ("env-app" )
163+ r .assert_called_once_with ("env-app" )
0 commit comments