mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2025-05-05 04:40:41 +00:00
app->libretranslate; mv tests/ inside libretranslate/
This commit is contained in:
parent
40a1141eac
commit
a23a9fbd75
47 changed files with 24 additions and 25 deletions
0
libretranslate/tests/test_api/__init__.py
Normal file
0
libretranslate/tests/test_api/__init__.py
Normal file
20
libretranslate/tests/test_api/conftest.py
Normal file
20
libretranslate/tests/test_api/conftest.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import sys
|
||||
import pytest
|
||||
|
||||
from libretranslate.app import create_app
|
||||
from libretranslate.default_values import DEFAULT_ARGUMENTS
|
||||
from libretranslate.main import get_args
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def app():
|
||||
sys.argv = ['']
|
||||
DEFAULT_ARGUMENTS['LOAD_ONLY'] = "en,es"
|
||||
app = create_app(get_args())
|
||||
|
||||
yield app
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(app):
|
||||
return app.test_client()
|
26
libretranslate/tests/test_api/test_api_detect_language.py
Normal file
26
libretranslate/tests/test_api/test_api_detect_language.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
import json
|
||||
|
||||
|
||||
def test_api_detect_language(client):
|
||||
response = client.post("/detect", data={
|
||||
"q": "Hello"
|
||||
})
|
||||
response_json = json.loads(response.data)
|
||||
|
||||
assert "confidence" in response_json[0] and "language" in response_json[0]
|
||||
assert len(response_json) >= 1
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_api_detect_language_must_fail_without_parameters(client):
|
||||
response = client.post("/detect")
|
||||
response_json = json.loads(response.data)
|
||||
|
||||
assert "error" in response_json
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_api_detect_language_must_fail_bad_request_type(client):
|
||||
response = client.get("/detect")
|
||||
|
||||
assert response.status_code == 405
|
|
@ -0,0 +1,4 @@
|
|||
def test_api_get_frontend_settings(client):
|
||||
response = client.get("/frontend/settings")
|
||||
|
||||
assert response.status_code == 200
|
16
libretranslate/tests/test_api/test_api_get_languages.py
Normal file
16
libretranslate/tests/test_api/test_api_get_languages.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import json
|
||||
|
||||
|
||||
def test_api_get_languages(client):
|
||||
response = client.get("/languages")
|
||||
response_json = json.loads(response.data)
|
||||
|
||||
assert "code" in response_json[0] and "name" in response_json[0]
|
||||
assert len(response_json) >= 1
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_api_get_languages_must_fail_bad_request_type(client):
|
||||
response = client.post("/languages")
|
||||
|
||||
assert response.status_code == 405
|
10
libretranslate/tests/test_api/test_api_spec.py
Normal file
10
libretranslate/tests/test_api/test_api_spec.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
def test_api_get_spec(client):
|
||||
response = client.get("/spec")
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_api_get_spec_must_fail_bad_request_type(client):
|
||||
response = client.post("/spec")
|
||||
|
||||
assert response.status_code == 405
|
61
libretranslate/tests/test_api/test_api_translate.py
Normal file
61
libretranslate/tests/test_api/test_api_translate.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
import json
|
||||
|
||||
|
||||
def test_api_translate(client):
|
||||
response = client.post("/translate", data={
|
||||
"q": "Hello",
|
||||
"source": "en",
|
||||
"target": "es",
|
||||
"format": "text"
|
||||
})
|
||||
|
||||
response_json = json.loads(response.data)
|
||||
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue