@@ -172,7 +172,6 @@ async def test_register_resource_success(self, resource_service, mock_db, sample
172
172
173
173
# Mock validation and notification
174
174
with (
175
- patch .object (resource_service , "_is_valid_uri" , return_value = True ),
176
175
patch .object (resource_service , "_detect_mime_type" , return_value = "text/plain" ),
177
176
patch .object (resource_service , "_notify_resource_added" , new_callable = AsyncMock ),
178
177
patch .object (resource_service , "_convert_resource_to_read" ) as mock_convert ,
@@ -238,19 +237,12 @@ async def test_register_resource_uri_conflict_inactive(self, resource_service, m
238
237
assert "inactive" in str (exc_info .value )
239
238
240
239
@pytest .mark .asyncio
241
- async def test_register_resource_invalid_uri (self , resource_service , mock_db , sample_resource_create ):
242
- """Test registration with invalid URI."""
243
- # Mock no existing resource
244
- mock_scalar = MagicMock ()
245
- mock_scalar .scalar_one_or_none .return_value = None
246
- mock_db .execute .return_value = mock_scalar
247
-
248
- # Mock invalid URI validation
249
- with patch .object (resource_service , "_is_valid_uri" , return_value = False ):
250
- with pytest .raises (ResourceError ) as exc_info : # Changed to ResourceError as that's what's actually raised
251
- await resource_service .register_resource (mock_db , sample_resource_create )
240
+ async def test_resource_create_with_invalid_uri (self ):
241
+ """Test resource creation with invalid URI."""
242
+ with pytest .raises (ValueError ) as exc_info :
243
+ ResourceCreate (uri = "../invalid/uri" , name = "Bad URI" , content = "data" )
252
244
253
- assert "Invalid URI " in str (exc_info .value )
245
+ assert "cannot contain directory traversal sequences " in str (exc_info .value )
254
246
255
247
@pytest .mark .asyncio
256
248
async def test_register_resource_integrity_error (self , resource_service , mock_db , sample_resource_create ):
@@ -261,7 +253,7 @@ async def test_register_resource_integrity_error(self, resource_service, mock_db
261
253
mock_db .execute .return_value = mock_scalar
262
254
263
255
# Mock validation success
264
- with patch .object (resource_service , "_is_valid_uri" , return_value = True ), patch . object ( resource_service , " _detect_mime_type" , return_value = "text/plain" ):
256
+ with patch .object (resource_service , "_detect_mime_type" , return_value = "text/plain" ):
265
257
# Mock IntegrityError on commit
266
258
mock_db .commit .side_effect = IntegrityError ("" , "" , "" )
267
259
@@ -283,7 +275,6 @@ async def test_register_resource_binary_content(self, resource_service, mock_db)
283
275
284
276
# Mock validation
285
277
with (
286
- patch .object (resource_service , "_is_valid_uri" , return_value = True ),
287
278
patch .object (resource_service , "_detect_mime_type" , return_value = "application/octet-stream" ),
288
279
patch .object (resource_service , "_notify_resource_added" , new_callable = AsyncMock ),
289
280
patch .object (resource_service , "_convert_resource_to_read" ) as mock_convert ,
@@ -1069,23 +1060,6 @@ async def test_reset_metrics(self, resource_service, mock_db):
1069
1060
class TestUtilityMethods :
1070
1061
"""Test utility methods."""
1071
1062
1072
- @pytest .mark .parametrize (
1073
- "uri, expected" ,
1074
- [
1075
- ("http://example.com/test" , True ),
1076
- ("https://example.com/test" , True ),
1077
- ("file:///path/to/resource" , True ),
1078
- ("ftp://example.com/file" , True ),
1079
- ("invalid-uri" , False ),
1080
- ("" , False ),
1081
- ("http://" , False ),
1082
- ],
1083
- )
1084
- def test_is_valid_uri (self , resource_service , uri , expected ):
1085
- """Test URI validation."""
1086
- result = resource_service ._is_valid_uri (uri )
1087
- assert result == expected
1088
-
1089
1063
@pytest .mark .parametrize (
1090
1064
"uri, content, expected" ,
1091
1065
[
@@ -1247,7 +1221,7 @@ async def test_register_resource_generic_error(self, resource_service, mock_db,
1247
1221
mock_db .execute .return_value = mock_scalar
1248
1222
1249
1223
# Mock validation success
1250
- with patch .object (resource_service , "_is_valid_uri" , return_value = True ), patch . object ( resource_service , " _detect_mime_type" , return_value = "text/plain" ):
1224
+ with patch .object (resource_service , "_detect_mime_type" , return_value = "text/plain" ):
1251
1225
# Mock generic error on add
1252
1226
mock_db .add .side_effect = Exception ("Generic error" )
1253
1227
0 commit comments