Skip to content

Commit 746cd4f

Browse files
preliminary tests for error handling
1 parent 99c0be8 commit 746cd4f

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

tests/detectors/builtIn/test_filetype.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,40 @@ def test_empty_detector_params(self, client: TestClient):
323323
resp = client.post("/api/v1/text/contents", json=payload)
324324
assert resp.status_code == 200
325325
# Should return empty list since no detectors are specified
326-
assert resp.json()[0] == []
326+
assert resp.json()[0] == []
327+
328+
def test_multiple_invalid_file_types(self, client: TestClient):
329+
"""Test multiple invalid file types to ensure all errors are handled"""
330+
payload = {
331+
"contents": ['test content'],
332+
"detector_params": {"file_type": ["invalid_type_1", "invalid_type_2"]}
333+
}
334+
resp = client.post("/api/v1/text/contents", json=payload)
335+
assert resp.status_code == 400
336+
data = resp.json()
337+
assert "message" in data
338+
assert "Unrecognized file type" in data["message"]
339+
340+
def test_mixed_valid_invalid_file_types(self, client: TestClient):
341+
"""Test mixing valid and invalid file types"""
342+
payload = {
343+
"contents": ['{a: 1, b: 2}'],
344+
"detector_params": {"file_type": ["json", "invalid_type"]}
345+
}
346+
resp = client.post("/api/v1/text/contents", json=payload)
347+
assert resp.status_code == 400
348+
data = resp.json()
349+
assert "message" in data
350+
assert "Unrecognized file type" in data["message"]
351+
352+
def test_case_sensitivity_file_types(self, client: TestClient):
353+
"""Test case sensitivity of file types"""
354+
payload = {
355+
"contents": ['{"a": 1}'],
356+
"detector_params": {"file_type": ["JSON"]} # uppercase
357+
}
358+
resp = client.post("/api/v1/text/contents", json=payload)
359+
assert resp.status_code == 400
360+
data = resp.json()
361+
assert "message" in data
362+
assert "Unrecognized file type" in data["message"]

tests/detectors/builtIn/test_regex.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,21 @@ def test_empty_detector_params(self, client):
236236
# Should return empty list since no detectors are specified
237237
assert resp.json()[0] == []
238238

239+
def test_null_regex_pattern(self, client):
240+
"""Test with null regex pattern"""
241+
payload = {
242+
"contents": ["[email protected]"],
243+
"detector_params": {"regex": [None]}
244+
}
245+
resp = client.post("/api/v1/text/contents", json=payload)
246+
assert resp.status_code == 500 # Should cause an error when processing None
247+
248+
def test_malformed_regex_groups(self, client):
249+
"""Test malformed regex with unmatched groups"""
250+
payload = {
251+
"contents": ["test content"],
252+
"detector_params": {"regex": ["(unclosed group"]}
253+
}
254+
resp = client.post("/api/v1/text/contents", json=payload)
255+
assert resp.status_code == 500 # Should cause regex compilation error
256+

0 commit comments

Comments
 (0)