|
|
|
|
@ -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"
|
|
|
|
|
|