mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-21 15:31:00 +00:00
add more tests for /translate
This commit is contained in:
parent
7113a30a0c
commit
8d602a80c3
1 changed files with 45 additions and 0 deletions
|
@ -14,3 +14,48 @@ def test_api_translate(client):
|
||||||
assert "translatedText" in response_json
|
assert "translatedText" in response_json
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_translate_batch(client):
|
||||||
|
|
||||||
|
response = client.post("/translate", json={
|
||||||
|
"q": ["Hello", "World"],
|
||||||
|
"source": "en",
|
||||||
|
"target": "es",
|
||||||
|
"format": "text"
|
||||||
|
})
|
||||||
|
|
||||||
|
response_json = json.loads(response.data)
|
||||||
|
|
||||||
|
assert "translatedText" in response_json
|
||||||
|
assert isinstance(response_json["translatedText"], list)
|
||||||
|
assert len(response_json["translatedText"]) == 2
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_translate_unsupported_language(client):
|
||||||
|
response = client.post("/translate", data={
|
||||||
|
"q": "Hello",
|
||||||
|
"source": "en",
|
||||||
|
"target": "zz",
|
||||||
|
"format": "text"
|
||||||
|
})
|
||||||
|
|
||||||
|
response_json = json.loads(response.data)
|
||||||
|
|
||||||
|
assert "error" in response_json
|
||||||
|
assert "zz is not supported" == response_json["error"]
|
||||||
|
assert response.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_translate_missing_parameter(client):
|
||||||
|
response = client.post("/translate", data={
|
||||||
|
"source": "en",
|
||||||
|
"target": "es",
|
||||||
|
"format": "text"
|
||||||
|
})
|
||||||
|
|
||||||
|
response_json = json.loads(response.data)
|
||||||
|
|
||||||
|
assert "error" in response_json
|
||||||
|
assert "Invalid request: missing q parameter" == response_json["error"]
|
||||||
|
assert response.status_code == 400
|
||||||
|
|
Loading…
Reference in a new issue