From 8d602a80c377ad850995c6af1a7b88e3e03e7d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Thuret?= Date: Tue, 5 Apr 2022 17:12:15 +0200 Subject: [PATCH] add more tests for /translate --- tests/test_api/test_api_translate.py | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/test_api/test_api_translate.py b/tests/test_api/test_api_translate.py index 4f3e30f..96f8632 100644 --- a/tests/test_api/test_api_translate.py +++ b/tests/test_api/test_api_translate.py @@ -14,3 +14,48 @@ def test_api_translate(client): assert "translatedText" in response_json 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