From 54bf74996d538e0d02e67960739d435a168fa390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Behrendt?= Date: Wed, 11 Oct 2023 16:30:18 +0200 Subject: [PATCH] test: Add Python tests --- .github/workflows/test-python.yml | 21 ++++ .gitignore | 5 +- clients/python/test/test_locales_api.py | 102 ++++++++++++++++++ clients/python/test/test_uploads_api.py | 71 ++++++++++++ .../templates/python/gitlab-ci.mustache | 38 ------- .../templates/python/model_test.mustache | 3 + 6 files changed, 201 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/test-python.yml create mode 100644 clients/python/test/test_locales_api.py create mode 100644 clients/python/test/test_uploads_api.py delete mode 100644 openapi-generator/templates/python/gitlab-ci.mustache diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml new file mode 100644 index 000000000..2e8b2b82b --- /dev/null +++ b/.github/workflows/test-python.yml @@ -0,0 +1,21 @@ +name: Run Python Tests +on: [push] +jobs: + unittest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build + run: | + npm install + npm run generate.python + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + working-directory: ./clients/python + - name: Run tests + run: | + cd ./clients/python + pip install -r requirements.txt -r test-requirements.txt + python -m unittest diff --git a/.gitignore b/.gitignore index ac751fe2a..7fce24e94 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ clients/go/ clients/php/ -clients/python/ + +clients/python/* +!clients/python/test/test_locales_api.py +!clients/python/test/test_uploads_api.py clients/ruby/.* clients/ruby/Gemfile* diff --git a/clients/python/test/test_locales_api.py b/clients/python/test/test_locales_api.py new file mode 100644 index 000000000..fe2ddb7b5 --- /dev/null +++ b/clients/python/test/test_locales_api.py @@ -0,0 +1,102 @@ +# coding: utf-8 + +""" + Phrase Strings API Reference + + The version of the OpenAPI document: 2.0.0 + Contact: support@phrase.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest +from unittest.mock import Mock, patch + + +import phrase_api +from phrase_api.api.locales_api import LocalesApi # noqa: E501 +from phrase_api.rest import ApiException + + +class TestLocalesApi(unittest.TestCase): + """LocalesApi unit test stubs""" + + def setUp(self): + self.configuration = phrase_api.Configuration() + self.configuration.api_key['Authorization'] = 'YOUR_API_KEY' + self.configuration.api_key_prefix['Authorization'] = 'token' + + def tearDown(self): + pass + + def test_account_locales(self): + """Test case for account_locales + + List locales used in account # noqa: E501 + """ + pass + + + + def test_locale_create(self): + """Test case for locale_create + + Create a locale # noqa: E501 + """ + pass + + def test_locale_delete(self): + """Test case for locale_delete + + Delete a locale # noqa: E501 + """ + pass + + def test_locale_download(self): + """Test case for locale_download + + Download a locale # noqa: E501 + """ + pass + + def test_locale_show(self): + """Test case for locale_show + + Get a single locale # noqa: E501 + """ + pass + + def test_locale_update(self): + """Test case for locale_update + + Update a locale # noqa: E501 + """ + pass + + @patch('phrase_api.ApiClient.request') + def test_locales_list(self, mock_get): + """Test case for locales_list + + List locales # noqa: E501 + """ + mock_get.return_value = Mock(ok=True) + mock_get.return_value.data = '[{"id":"locale_id","name":"locale_name","code":"locale_code","default":true,"main":true,"rtl":true,"plural_forms":["plural_forms"]}]' + + project_id = "project_id_example" + with phrase_api.ApiClient(self.configuration) as api_client: + api_instance = phrase_api.api.locales_api.LocalesApi(api_client) + api_response = api_instance.locales_list(project_id) + + self.assertIsNotNone(api_response) + self.assertEqual(1, len(api_response)) + self.assertIsInstance(api_response[0], phrase_api.models.locale.Locale) + self.assertEqual("locale_id", api_response[0].id) + self.assertEqual("locale_id", api_response[0].id) + self.assertEqual("locale_name", api_response[0].name) + + + +if __name__ == '__main__': + unittest.main() diff --git a/clients/python/test/test_uploads_api.py b/clients/python/test/test_uploads_api.py new file mode 100644 index 000000000..bf09ddacd --- /dev/null +++ b/clients/python/test/test_uploads_api.py @@ -0,0 +1,71 @@ +# coding: utf-8 + +""" + Phrase Strings API Reference + + The version of the OpenAPI document: 2.0.0 + Contact: support@phrase.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest +from unittest.mock import Mock, patch + +import phrase_api +from phrase_api.api.uploads_api import UploadsApi # noqa: E501 +from phrase_api.rest import ApiException + + +class TestUploadsApi(unittest.TestCase): + """UploadsApi unit test stubs""" + + def setUp(self): + self.configuration = phrase_api.Configuration() + self.configuration.api_key['Authorization'] = 'YOUR_API_KEY' + self.configuration.api_key_prefix['Authorization'] = 'token' + + def tearDown(self): + pass + + @patch('phrase_api.ApiClient.request') + def test_upload_create(self, mock_post): + """Test case for upload_create + + Upload a new file # noqa: E501 + """ + mock_post.return_value = Mock(ok=True) + mock_post.return_value.data = '{"id": "upload_id", "format": "simple_json"}' + + project_id = "project_id_example" + with phrase_api.ApiClient(self.configuration) as api_client: + api_instance = phrase_api.UploadsApi(api_client) + api_response = api_instance.upload_create(project_id, file="./README.md", file_format="simple_json") + + self.assertEqual("POST", mock_post.call_args_list[0].args[0]) + self.assertEqual("https://api.phrase.com/v2/projects/project_id_example/uploads", mock_post.call_args_list[0].args[1]) + + self.assertIsNotNone(api_response) + self.assertIsInstance(api_response, phrase_api.models.upload.Upload) + self.assertEqual("upload_id", api_response.id) + self.assertEqual("simple_json", api_response.format) + + def test_upload_show(self): + """Test case for upload_show + + Get a single upload # noqa: E501 + """ + pass + + def test_uploads_list(self): + """Test case for uploads_list + + List uploads # noqa: E501 + """ + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/openapi-generator/templates/python/gitlab-ci.mustache b/openapi-generator/templates/python/gitlab-ci.mustache deleted file mode 100644 index 2cabff63c..000000000 --- a/openapi-generator/templates/python/gitlab-ci.mustache +++ /dev/null @@ -1,38 +0,0 @@ -# ref: https://docs.gitlab.com/ee/ci/README.html - -stages: - - test - -.nosetest: - stage: test - script: - - pip install -r requirements.txt - - pip install -r test-requirements.txt - {{#useNose}} - - nosetests - {{/useNose}} - {{^useNose}} - - pytest --cov={{{packageName}}} - {{/useNose}} - -nosetest-2.7: - extends: .nosetest - image: python:2.7-alpine -nosetest-3.3: - extends: .nosetest - image: python:3.3-alpine -nosetest-3.4: - extends: .nosetest - image: python:3.4-alpine -nosetest-3.5: - extends: .nosetest - image: python:3.5-alpine -nosetest-3.6: - extends: .nosetest - image: python:3.6-alpine -nosetest-3.7: - extends: .nosetest - image: python:3.7-alpine -nosetest-3.8: - extends: .nosetest - image: python:3.8-alpine diff --git a/openapi-generator/templates/python/model_test.mustache b/openapi-generator/templates/python/model_test.mustache index b69f13f74..098d8b086 100644 --- a/openapi-generator/templates/python/model_test.mustache +++ b/openapi-generator/templates/python/model_test.mustache @@ -28,6 +28,8 @@ class Test{{classname}}(unittest.TestCase): params are included, when True both required and optional params are included """ # model = {{packageName}}.models.{{classFilename}}.{{classname}}() # noqa: E501 + + """ if include_optional : return {{classname}}( {{#vars}} @@ -42,6 +44,7 @@ class Test{{classname}}(unittest.TestCase): {{/required}} {{/vars}} ) + """ def test{{classname}}(self): """Test {{classname}}"""