Add the validation for empty texts.
This commit is contained in:
@@ -82,6 +82,53 @@ class TestGeneralEndpoint:
|
||||
assert "error" in error
|
||||
assert error["error"]["code"] == "INVALID_INPUT"
|
||||
|
||||
def test_error_empty_text_provided(self, api_client):
|
||||
"""Test error when the text is empty"""
|
||||
payload = {
|
||||
"text": "",
|
||||
"entities": ["organization"]
|
||||
}
|
||||
response = api_client.post(f"{BASE_URL}/general", json=payload)
|
||||
assert response.status_code == 400
|
||||
|
||||
error = response.json()
|
||||
assert "error" in error
|
||||
assert error["error"]["code"] == "INVALID_INPUT"
|
||||
|
||||
def test_error_texts_has_empty_value(self, api_client):
|
||||
"""Test error when texts has an empty value"""
|
||||
payload = {
|
||||
"texts": [
|
||||
"Apple Inc. was founded by Steve Jobs in California.",
|
||||
"",
|
||||
"Elon Musk leads Tesla and SpaceX."
|
||||
],
|
||||
"entities": ["organization"]
|
||||
}
|
||||
response = api_client.post(f"{BASE_URL}/general", json=payload)
|
||||
assert response.status_code == 400
|
||||
|
||||
error = response.json()
|
||||
assert "error" in error
|
||||
assert error["error"]["code"] == "INVALID_INPUT"
|
||||
|
||||
def test_error_texts_has_empty_values(self, api_client):
|
||||
"""Test error when texts has empty values"""
|
||||
payload = {
|
||||
"texts": [
|
||||
"",
|
||||
"",
|
||||
""
|
||||
],
|
||||
"entities": ["organization"]
|
||||
}
|
||||
response = api_client.post(f"{BASE_URL}/general", json=payload)
|
||||
assert response.status_code == 400
|
||||
|
||||
error = response.json()
|
||||
assert "error" in error
|
||||
assert error["error"]["code"] == "INVALID_INPUT"
|
||||
|
||||
def test_error_empty_entities_list(self, api_client):
|
||||
"""Test error with an empty entities list"""
|
||||
payload = {
|
||||
|
||||
@@ -85,3 +85,63 @@ class TestRelationExtractionEndpoint:
|
||||
response = api_client.post(f"{BASE_URL}/relation-extraction", json=payload)
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_error_no_text_provided(self, api_client):
|
||||
"""Test error when neither text nor texts is provided"""
|
||||
payload = {
|
||||
"text": "",
|
||||
"relations": ["founded"]
|
||||
}
|
||||
response = api_client.post(f"{BASE_URL}/relation-extraction", json=payload)
|
||||
assert response.status_code == 400
|
||||
|
||||
error = response.json()
|
||||
assert "error" in error
|
||||
assert error["error"]["code"] == "INVALID_INPUT"
|
||||
|
||||
def test_error_empty_text_provided(self, api_client):
|
||||
"""Test error when the text is empty"""
|
||||
payload = {
|
||||
"relations": ["founded"]
|
||||
}
|
||||
response = api_client.post(f"{BASE_URL}/relation-extraction", json=payload)
|
||||
assert response.status_code == 400
|
||||
|
||||
error = response.json()
|
||||
assert "error" in error
|
||||
assert error["error"]["code"] == "INVALID_INPUT"
|
||||
|
||||
def test_error_texts_has_empty_value(self, api_client):
|
||||
"""Test error when texts has an empty value"""
|
||||
payload = {
|
||||
"texts": [
|
||||
"Bill Gates founded Microsoft.",
|
||||
"",
|
||||
"Apple is based in California."
|
||||
],
|
||||
"relations": ["founded", "founded_by", "based_in"],
|
||||
"threshold": 0.3
|
||||
}
|
||||
response = api_client.post(f"{BASE_URL}/relation-extraction", json=payload)
|
||||
assert response.status_code == 400
|
||||
|
||||
error = response.json()
|
||||
assert "error" in error
|
||||
assert error["error"]["code"] == "INVALID_INPUT"
|
||||
|
||||
def test_error_texts_has_empty_values(self, api_client):
|
||||
"""Test error when texts has empty values"""
|
||||
payload = {
|
||||
"texts": [
|
||||
"",
|
||||
"",
|
||||
""
|
||||
],
|
||||
"relations": ["founded", "founded_by", "based_in"],
|
||||
"threshold": 0.3
|
||||
}
|
||||
response = api_client.post(f"{BASE_URL}/relation-extraction", json=payload)
|
||||
assert response.status_code == 400
|
||||
|
||||
error = response.json()
|
||||
assert "error" in error
|
||||
assert error["error"]["code"] == "INVALID_INPUT"
|
||||
|
||||
@@ -57,3 +57,54 @@ class TestSummarizationEndpoint:
|
||||
}
|
||||
response = api_client.post(f"{BASE_URL}/summarization", json=payload)
|
||||
assert response.status_code == 400
|
||||
|
||||
error = response.json()
|
||||
assert "error" in error
|
||||
assert error["error"]["code"] == "INVALID_INPUT"
|
||||
|
||||
def test_error_empty_text(self, api_client):
|
||||
"""Test error when the text is empty"""
|
||||
payload = {
|
||||
"text": "",
|
||||
"threshold": 0.5
|
||||
}
|
||||
response = api_client.post(f"{BASE_URL}/summarization", json=payload)
|
||||
assert response.status_code == 400
|
||||
|
||||
error = response.json()
|
||||
assert "error" in error
|
||||
assert error["error"]["code"] == "INVALID_INPUT"
|
||||
|
||||
def test_error_texts_has_empty_value(self, api_client):
|
||||
"""Test error when texts has an empty value"""
|
||||
payload = {
|
||||
"texts": [
|
||||
"Python is a high-level programming language. It's known for its simplicity and readability.",
|
||||
"",
|
||||
"Rust is a systems programming language. It focuses on safety and performance."
|
||||
],
|
||||
"threshold": 0.3
|
||||
}
|
||||
response = api_client.post(f"{BASE_URL}/summarization", json=payload)
|
||||
assert response.status_code == 400
|
||||
|
||||
error = response.json()
|
||||
assert "error" in error
|
||||
assert error["error"]["code"] == "INVALID_INPUT"
|
||||
|
||||
def test_error_texts_has_empty_values(self, api_client):
|
||||
"""Test error when texts has empty values"""
|
||||
payload = {
|
||||
"texts": [
|
||||
"",
|
||||
"",
|
||||
""
|
||||
],
|
||||
"threshold": 0.3
|
||||
}
|
||||
response = api_client.post(f"{BASE_URL}/summarization", json=payload)
|
||||
assert response.status_code == 400
|
||||
|
||||
error = response.json()
|
||||
assert "error" in error
|
||||
assert error["error"]["code"] == "INVALID_INPUT"
|
||||
|
||||
Reference in New Issue
Block a user