@@ -127,7 +127,7 @@ def test_cog_not_available_falls_back_to_env(self):
127
127
with mock .patch .dict (os .environ , {"REPLICATE_API_TOKEN" : "env-token" }):
128
128
with mock .patch .dict (sys .modules , {"cog" : None }):
129
129
token = _get_api_token_from_environment ()
130
- assert token == "env-token"
130
+ assert token == "env-token" # noqa: S105
131
131
132
132
def test_cog_import_error_falls_back_to_env (self ):
133
133
"""Test fallback to environment when cog import raises exception."""
@@ -137,7 +137,7 @@ def test_cog_import_error_falls_back_to_env(self):
137
137
side_effect = ModuleNotFoundError ("No module named 'cog'" ),
138
138
):
139
139
token = _get_api_token_from_environment ()
140
- assert token == "env-token"
140
+ assert token == "env-token" # noqa: S105
141
141
142
142
def test_cog_no_current_scope_method_falls_back_to_env (self ):
143
143
"""Test fallback when cog exists but has no current_scope method."""
@@ -147,7 +147,7 @@ def test_cog_no_current_scope_method_falls_back_to_env(self):
147
147
with mock .patch .dict (os .environ , {"REPLICATE_API_TOKEN" : "env-token" }):
148
148
with mock .patch .dict (sys .modules , {"cog" : mock_cog }):
149
149
token = _get_api_token_from_environment ()
150
- assert token == "env-token"
150
+ assert token == "env-token" # noqa: S105
151
151
152
152
def test_cog_current_scope_returns_none_falls_back_to_env (self ):
153
153
"""Test fallback when current_scope() returns None."""
@@ -157,64 +157,77 @@ def test_cog_current_scope_returns_none_falls_back_to_env(self):
157
157
with mock .patch .dict (os .environ , {"REPLICATE_API_TOKEN" : "env-token" }):
158
158
with mock .patch .dict (sys .modules , {"cog" : mock_cog }):
159
159
token = _get_api_token_from_environment ()
160
- assert token == "env-token"
160
+ assert token == "env-token" # noqa: S105
161
161
162
- def test_cog_scope_no_content_attr_falls_back_to_env (self ):
163
- """Test fallback when scope has no content attribute."""
162
+ def test_cog_scope_no_context_attr_falls_back_to_env (self ):
163
+ """Test fallback when scope has no context attribute."""
164
164
mock_scope = mock .MagicMock ()
165
- del mock_scope .content # Remove the content attribute
165
+ del mock_scope .context # Remove the context attribute
166
166
167
167
mock_cog = mock .MagicMock ()
168
168
mock_cog .current_scope .return_value = mock_scope
169
169
170
170
with mock .patch .dict (os .environ , {"REPLICATE_API_TOKEN" : "env-token" }):
171
171
with mock .patch .dict (sys .modules , {"cog" : mock_cog }):
172
172
token = _get_api_token_from_environment ()
173
- assert token == "env-token"
173
+ assert token == "env-token" # noqa: S105
174
174
175
- def test_cog_scope_content_not_dict_falls_back_to_env (self ):
176
- """Test fallback when scope.content is not a dictionary."""
175
+ def test_cog_scope_context_not_dict_falls_back_to_env (self ):
176
+ """Test fallback when scope.context is not a dictionary."""
177
177
mock_scope = mock .MagicMock ()
178
- mock_scope .content = "not a dict"
178
+ mock_scope .context = "not a dict"
179
179
180
180
mock_cog = mock .MagicMock ()
181
181
mock_cog .current_scope .return_value = mock_scope
182
182
183
183
with mock .patch .dict (os .environ , {"REPLICATE_API_TOKEN" : "env-token" }):
184
184
with mock .patch .dict (sys .modules , {"cog" : mock_cog }):
185
185
token = _get_api_token_from_environment ()
186
- assert token == "env-token"
186
+ assert token == "env-token" # noqa: S105
187
187
188
188
def test_cog_scope_no_replicate_api_token_key_falls_back_to_env (self ):
189
- """Test fallback when replicate_api_token key is missing from content ."""
189
+ """Test fallback when replicate_api_token key is missing from context ."""
190
190
mock_scope = mock .MagicMock ()
191
- mock_scope .content = {"other_key" : "other_value" } # Missing replicate_api_token
191
+ mock_scope .context = {"other_key" : "other_value" } # Missing replicate_api_token
192
192
193
193
mock_cog = mock .MagicMock ()
194
194
mock_cog .current_scope .return_value = mock_scope
195
195
196
196
with mock .patch .dict (os .environ , {"REPLICATE_API_TOKEN" : "env-token" }):
197
197
with mock .patch .dict (sys .modules , {"cog" : mock_cog }):
198
198
token = _get_api_token_from_environment ()
199
- assert token == "env-token"
199
+ assert token == "env-token" # noqa: S105
200
200
201
201
def test_cog_scope_replicate_api_token_valid_string (self ):
202
202
"""Test successful retrieval of non-empty token from cog."""
203
203
mock_scope = mock .MagicMock ()
204
- mock_scope .content = {"replicate_api_token " : "cog-token" }
204
+ mock_scope .context = {"REPLICATE_API_TOKEN " : "cog-token" }
205
205
206
206
mock_cog = mock .MagicMock ()
207
207
mock_cog .current_scope .return_value = mock_scope
208
208
209
209
with mock .patch .dict (os .environ , {"REPLICATE_API_TOKEN" : "env-token" }):
210
210
with mock .patch .dict (sys .modules , {"cog" : mock_cog }):
211
211
token = _get_api_token_from_environment ()
212
- assert token == "cog-token"
212
+ assert token == "cog-token" # noqa: S105
213
+
214
+ def test_cog_scope_replicate_api_token_case_insensitive (self ):
215
+ """Test successful retrieval of non-empty token from cog ignoring case."""
216
+ mock_scope = mock .MagicMock ()
217
+ mock_scope .context = {"replicate_api_token" : "cog-token" }
218
+
219
+ mock_cog = mock .MagicMock ()
220
+ mock_cog .current_scope .return_value = mock_scope
221
+
222
+ with mock .patch .dict (os .environ , {"REPLICATE_API_TOKEN" : "env-token" }):
223
+ with mock .patch .dict (sys .modules , {"cog" : mock_cog }):
224
+ token = _get_api_token_from_environment ()
225
+ assert token == "cog-token" # noqa: S105
213
226
214
227
def test_cog_scope_replicate_api_token_empty_string (self ):
215
228
"""Test that empty string from cog is returned (not falling back to env)."""
216
229
mock_scope = mock .MagicMock ()
217
- mock_scope .content = {"replicate_api_token" : "" } # Empty string
230
+ mock_scope .context = {"replicate_api_token" : "" } # Empty string
218
231
219
232
mock_cog = mock .MagicMock ()
220
233
mock_cog .current_scope .return_value = mock_scope
@@ -227,7 +240,7 @@ def test_cog_scope_replicate_api_token_empty_string(self):
227
240
def test_cog_scope_replicate_api_token_none (self ):
228
241
"""Test that None from cog is returned (not falling back to env)."""
229
242
mock_scope = mock .MagicMock ()
230
- mock_scope .content = {"replicate_api_token" : None }
243
+ mock_scope .context = {"replicate_api_token" : None }
231
244
232
245
mock_cog = mock .MagicMock ()
233
246
mock_cog .current_scope .return_value = mock_scope
@@ -245,7 +258,7 @@ def test_cog_current_scope_raises_exception_falls_back_to_env(self):
245
258
with mock .patch .dict (os .environ , {"REPLICATE_API_TOKEN" : "env-token" }):
246
259
with mock .patch .dict (sys .modules , {"cog" : mock_cog }):
247
260
token = _get_api_token_from_environment ()
248
- assert token == "env-token"
261
+ assert token == "env-token" # noqa: S105
249
262
250
263
def test_no_env_token_returns_none (self ):
251
264
"""Test that None is returned when no environment token is set and cog unavailable."""
0 commit comments