Skip to content

Commit

Permalink
Adding github action test automation (#44)
Browse files Browse the repository at this point in the history
* More linting fixes

* Adding openapi-bindings branch to testfile

* Reverting to match case, upgrading python version

* Continuing revert, upgrading github action setup-python and checkout versions

* Fixing python setup

* Adding test-requirements.txt install

* Changing runner to allow staging connection, updating pytest version

* Adding env vars

* Updating test to new sections type definition

* Reverting sections type

* Restricting test to workflow_tests dir, fixing bug

* Added polling to file import
  • Loading branch information
nicholas-chiu authored Oct 10, 2024
1 parent 374052a commit b215ea7
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 18 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Pytest
env:
API_HOST: ${{ vars.API_HOST }}
API_KEY: ${{ secrets.API_KEY }}

on:
push:
branches: [ master ]
branches: [ master, openapi-bindings ]
pull_request:
branches: [ master ]
branches: [ master, openapi-bindings ]

jobs:
build:

runs-on: ubuntu-latest
runs-on: gcp-runner

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r test-requirements.txt
- name: Lint with flake8
run: |
pip install flake8
Expand All @@ -34,4 +35,4 @@ jobs:
- name: Test with pytest
run: |
pip install pytest
pytest
pytest workflow_tests
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pytest~=4.6.7 # needed for python 2.7+3.4
pytest~=7.1.2
pytest-cov>=2.8.1
pytest-randomly==1.2.3 # needed for python 2.7+3.4
python-dotenv==1.0.1
Expand Down
4 changes: 2 additions & 2 deletions test/test_get_lilt_create_content_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def make_instance(self, include_optional):
lilt.models.lilt_create_content.LiltCreateContent(
language = '0',
template = '0',
template_params = lilt.models.lilt_create_content_template_params.LiltCreateContent_templateParams(
template_params = lilt.models.lilt_create_content_template_params.LiltCreateContentTemplateParams(
content_length = 56,
language = '0',
sections = '0',
summary = '0', ),
preferences = lilt.models.lilt_create_content_preferences.LiltCreateContent_preferences(
preferences = lilt.models.lilt_create_content_preferences.LiltCreateContentPreferences(
tone = '0',
styleguide = '0', ), )
]
Expand Down
6 changes: 3 additions & 3 deletions test/test_lilt_create_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ def make_instance(self, include_optional):
return LiltCreateContent(
language = '0',
template = '0',
template_params = lilt.models.lilt_create_content_template_params.LiltCreateContent_templateParams(
template_params = lilt.models.lilt_create_content_template_params.LiltCreateContentTemplateParams(
content_length = 56,
language = '0',
sections = '0',
summary = '0', ),
preferences = lilt.models.lilt_create_content_preferences.LiltCreateContent_preferences(
preferences = lilt.models.lilt_create_content_preferences.LiltCreateContentPreferences(
tone = '0',
styleguide = '0', )
)
else :
return LiltCreateContent(
language = '0',
template = '0',
template_params = lilt.models.lilt_create_content_template_params.LiltCreateContent_templateParams(
template_params = lilt.models.lilt_create_content_template_params.LiltCreateContentTemplateParams(
content_length = 56,
language = '0',
sections = '0',
Expand Down
3 changes: 3 additions & 0 deletions workflow_tests/test_create_content.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from __future__ import print_function
from dotenv import load_dotenv

import os
import pytest
import time
import lilt

load_dotenv()

configuration = lilt.Configuration(
host=os.environ["API_HOST"],
api_key={
Expand Down
20 changes: 19 additions & 1 deletion workflow_tests/test_data_source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from dotenv import load_dotenv

import os
import pytest
Expand All @@ -7,6 +8,9 @@

from lilt.rest import ApiException
from pprint import pprint
from tenacity import retry, stop_after_delay, wait_exponential, retry_if_result, RetryError

load_dotenv()


configuration = lilt.Configuration(
Expand Down Expand Up @@ -202,6 +206,18 @@ def assert_query_response(query_object, expected):
assert query_object.target == expected["target"]


@retry(
retry=retry_if_result(lambda is_processing: is_processing == 1),
stop=stop_after_delay(2 * 60),
wait=wait_exponential()
)
def monitor_file_import(api_instance, memory_id):
api_response = api_instance.get_memory()
is_processing = api_response[0].is_processing
print(f"is_processing: {is_processing}")
return is_processing


@pytest.mark.parametrize("data_source_case", create_data_source_cases)
def test_create_data_source_workflow(data_source_case):
api_client = lilt.ApiClient(configuration)
Expand Down Expand Up @@ -272,7 +288,9 @@ def test_upload_tmx_file_workflow(tmx_file_case):
pprint(api_response)
assert api_response.id == memory_id
assert api_response.is_processing == 1
time.sleep(10)

# Monitor file import
is_processing = monitor_file_import(api_instance, memory_id)

# Query memory
query = "chatte"
Expand Down
2 changes: 2 additions & 0 deletions workflow_tests/test_instant_translate.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import print_function
from dotenv import load_dotenv

import os
import pytest
import lilt

from tenacity import retry, stop_after_delay, wait_exponential, retry_if_result, RetryError

load_dotenv()

configuration = lilt.Configuration(
host=os.environ["API_HOST"],
Expand Down

0 comments on commit b215ea7

Please sign in to comment.