Skip to content

Commit 95a1a33

Browse files
authored
[ENG-18631] track test runs against staging (#48)
* update test deps * adds ddtrace * adds test_verified_translate * fix action triggers
1 parent d67ab26 commit 95a1a33

File tree

3 files changed

+120
-5
lines changed

3 files changed

+120
-5
lines changed

.github/workflows/pythonapp.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ name: Pytest Tests
22
env:
33
API_HOST: ${{ vars.API_HOST }}
44
API_KEY: ${{ secrets.API_KEY }}
5+
DD_API_KEY: ${{ secrets.DD_API_KEY }}
6+
DD_SITE: us5.datadoghq.com
7+
DD_ENV: staging
8+
DD_SERVICE: lilt-python
9+
DD_CIVISIBILITY_AGENTLESS_ENABLED: true
510

611
on:
712
push:
8-
branches: [ master, openapi-bindings ]
13+
branches: [ master ]
914
pull_request:
1015
branches: [ master, openapi-bindings ]
1116

@@ -25,14 +30,15 @@ jobs:
2530
python -m pip install --upgrade pip
2631
pip install -r requirements.txt
2732
pip install -r test-requirements.txt
33+
- name: Install datadog tracing library
34+
run: |
35+
pip install -U ddtrace
2836
- name: Lint with flake8
2937
run: |
30-
pip install flake8
3138
# stop the build if there are Python syntax errors or undefined names
3239
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
3340
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
3441
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
3542
- name: Test with pytest
3643
run: |
37-
pip install pytest
38-
pytest workflow_tests
44+
pytest workflow_tests --ddtrace

test-requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
pytest~=7.1.2
1+
pytest~=8.3.3
22
pytest-cov>=2.8.1
33
pytest-randomly==1.2.3 # needed for python 2.7+3.4
44
python-dotenv==1.0.1
55
tenacity==8.5.0
6+
flake8
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
from dotenv import load_dotenv
2+
3+
import os
4+
from io import BytesIO
5+
from zipfile import ZipFile
6+
7+
import pytest
8+
import lilt
9+
10+
from tenacity import (
11+
retry,
12+
stop_after_delay,
13+
wait_exponential,
14+
retry_if_result,
15+
)
16+
17+
load_dotenv()
18+
19+
20+
@pytest.fixture(scope="module")
21+
def client():
22+
configuration = lilt.Configuration(
23+
host=os.environ["API_HOST"], api_key={"key": os.environ["API_KEY"]}
24+
)
25+
api_client = lilt.ApiClient(configuration)
26+
commit = os.environ.get("GIT_COMMIT_SHA", "no_version_available")
27+
api_client.user_agent = f"lilt-python-e2e-tests/{commit}"
28+
return api_client
29+
30+
31+
@pytest.fixture(scope="module")
32+
def api(client):
33+
return lilt.JobsApi(client)
34+
35+
36+
@pytest.fixture(scope="module")
37+
def uploaded_file(client):
38+
api = lilt.FilesApi(client)
39+
name = "test_file.txt"
40+
body = b"hello world"
41+
response = api.upload_file(name, body)
42+
yield response
43+
api.delete_file(response.id)
44+
45+
46+
@pytest.fixture(scope="module")
47+
def memory(client):
48+
api = lilt.MemoriesApi(client)
49+
body = lilt.MemoryCreateParameters(
50+
name="test_memory",
51+
srclang="en",
52+
srclocale="US",
53+
trglang="de",
54+
trglocale="DE",
55+
)
56+
response = api.create_memory(body)
57+
yield response
58+
api.delete_memory(response.id)
59+
60+
61+
@pytest.fixture(scope="module")
62+
def job(api, memory, uploaded_file):
63+
lang = lilt.LanguagePair(trg_lang=memory.trglang, memory_id=memory.id)
64+
body = lilt.JobCreateParameters(
65+
name="test_job",
66+
src_lang="en",
67+
src_locale="US",
68+
language_pairs=[lang],
69+
file_ids=[uploaded_file.id],
70+
)
71+
response = api.create_job(body)
72+
yield response
73+
api.delete_job(response.id)
74+
75+
76+
def test_verified_translate_monitor_job_status(api, job):
77+
api.deliver_job(job.id)
78+
jobs = api.retrieve_all_jobs(is_delivered="true", is_archived="false")
79+
assert len(jobs) > 0
80+
81+
82+
@retry(
83+
retry=retry_if_result(lambda is_processing: is_processing != 0),
84+
stop=stop_after_delay(2 * 60),
85+
wait=wait_exponential(),
86+
)
87+
def wait_for_job_export(api, job_id):
88+
job = api.get_job(job_id)
89+
return job.is_processing
90+
91+
92+
def test_verified_translate_download_job(api, job):
93+
api.export_job(job.id, type="files")
94+
wait_for_job_export(api, job.id)
95+
response = api.download_job(job.id, _preload_content=False)
96+
zip_file = BytesIO(response.data)
97+
with ZipFile(zip_file) as zip_ref:
98+
contents = zip_ref.infolist()
99+
assert len(contents) == 2
100+
translated_file = contents[1]
101+
with zip_ref.open(translated_file) as tf:
102+
assert tf.read() == b"hello world"
103+
104+
105+
def test_verified_translate_archive_job(api, job):
106+
api.archive_job(job.id)
107+
updated_job = api.get_job(job.id)
108+
assert updated_job.status == "archived"

0 commit comments

Comments
 (0)