diff --git a/pytransifex/api.py b/pytransifex/api.py index 1970f67..368a842 100644 --- a/pytransifex/api.py +++ b/pytransifex/api.py @@ -53,11 +53,14 @@ def create_project( *, project_slug: str, project_name: str | None = None, - source_language_code: str = "en_GB", + source_language_code: str = "en", private: bool = False, **kwargs, ): """Create a project.""" + logger.info( + f"Trying to create project from these arguments: project_slug = {project_slug}, " + ) source_language = tx_api.Language.get(code=source_language_code) project_name = project_name or project_slug @@ -247,7 +250,9 @@ def create_language( ): """Create a new language resource in the remote Transifex repository""" if project := self.get_project(project_slug=project_slug): - project.add("languages", [tx_api.Language.get(code=language_code)]) + if language := tx_api.Language.get(code=language_code): + logger.debug(f"Adding {language.code} to {project_slug}") + project.add("languages", [language]) if coordinators: project.add("coordinators", coordinators) diff --git a/requirements/dev.txt b/requirements/dev.txt index cafd3e0..38eb3a7 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1 +1,2 @@ nose2 +PyYAML diff --git a/tests/_translation.py b/tests/_translation.py index bcce577..dc1c109 100644 --- a/tests/_translation.py +++ b/tests/_translation.py @@ -4,8 +4,9 @@ import subprocess import sys from dataclasses import dataclass -from datetime import date +from datetime import date, datetime from pathlib import Path +from typing import Optional from pytransifex.api import Transifex @@ -14,23 +15,23 @@ @dataclass class Parameters: - changelog_include: bool - changelog_path: str - changelog_number_of_entries: int - create_date: date - github_organization_slug: str - lrelease_path: str - plugin_name: str - plugin_path: str - project_slug: str - pylupdate5_path: str - repository_url: str - transifex_coordinator: str - transifex_organization: str - transifex_project: str - transifex_resource: str - translation_source_language: str - translation_languages: str + changelog_include: Optional[bool] = False + changelog_path: Optional[str] = None + changelog_number_of_entries: Optional[int] = None + create_date: Optional[date] = datetime.now() + github_organization_slug: Optional[str] = None + lrelease_path: Optional[str] = None + plugin_name: Optional[str] = None + plugin_path: Optional[str] = None + project_slug: Optional[str] = None + pylupdate5_path: Optional[str] = None + repository_url: Optional[str] = None + transifex_coordinator: Optional[str] = None + transifex_organization: Optional[str] = None + transifex_project: Optional[str] = None + transifex_resource: Optional[str] = None + translation_source_language: Optional[str] = None + translation_languages: Optional[str] = None def touch_file(path, update_time: bool = False, create_dir: bool = True): @@ -48,6 +49,7 @@ class Translation: def __init__( self, parameters: Parameters, transifex_token: str, create_project: bool = True ): + logger.info(f"Overriding test config with: {parameters}") client = Transifex( api_token=transifex_token, organization_name=parameters.transifex_organization, @@ -177,9 +179,11 @@ def pull(self): existing_langs = self.tx_client.list_languages( project_slug=self.parameters.transifex_project ) - existing_langs.remove(self.parameters.translation_source_language) + lang = self.parameters.translation_source_language + if lang in existing_langs: + existing_langs.remove(lang) logger.info( - f"{len(existing_langs)} languages found for resource {resource.get('slug')}:" + f"{len(existing_langs)} languages found for resource :" f" ({existing_langs})" ) for lang in self.parameters.translation_languages: @@ -196,7 +200,7 @@ def pull(self): logger.debug(f"Downloading translation file: {ts_file}") self.tx_client.get_translation( project_slug=self.parameters.transifex_project, - resource_slug=resource["slug"], + resource_slug=resource.slug, language_code=lang, path_to_output_file=ts_file, ) diff --git a/tests/data/.qgis-plugin-ci-test-changelog.yaml b/tests/data/.qgis-plugin-ci-test-changelog.yaml index d00a409..b04246e 100644 --- a/tests/data/.qgis-plugin-ci-test-changelog.yaml +++ b/tests/data/.qgis-plugin-ci-test-changelog.yaml @@ -1,4 +1,6 @@ -plugin_path: qgis_plugin_CI_testing -github_organization_slug: opengisch -project_slug: qgis-plugin-ci-changelog -create_date: 1985-07-21 +project_slug: test_project_pytransifex_public_translation_test +transifex_organization: test_pytransifex +transifex_coordinator: john_doe +translation_languages: + - fr + - en diff --git a/tests/test_api.py b/tests/test_api.py index 6a3c385..b96f5bd 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -117,26 +117,6 @@ def test11_stats(self): logger.info(str(stats)) assert stats - def test12_stats(self): - self.tx.get_project_stats(project_slug=self.project_slug) - - def test13_stats(self): - self.tx.get_project_stats(project_slug=self.project_slug) - if __name__ == "__main__": unittest.main() - -""" -# Don't remove this! -curl -g \ - --request GET --url "https://rest.api.transifex.com/resource_language_stats?filter[project]=o%3Aopengisch%3Ap%3Aqfield-documentation" \ - --header 'accept: application/vnd.api+json' \ - --header 'authorization: Bearer TOKEN' - -curl -g \ - --request GET \ - --url "https://rest.api.transifex.com/resource_language_stats?filter[project]=o%3Atest_pytransifex%3Ap%3Atest_project_pytransifex" \ - --header 'accept: application/vnd.api+json' \ - --header 'authorization: Bearer TOKEN' -""" diff --git a/tests/test_translation.py b/tests/test_translation.py index da9c955..b0bcad5 100644 --- a/tests/test_translation.py +++ b/tests/test_translation.py @@ -2,6 +2,7 @@ import os import unittest from pathlib import Path + import yaml from pytransifex.exceptions import PyTransifexException @@ -14,11 +15,13 @@ class TestTranslation(unittest.TestCase): @classmethod def setUpClass(cls): """Initialize the test case""" - config_yaml = Path.cwd().joinpath("tests", "data", ".qgis-plugin-ci-test-changelog.yaml") + config_yaml = Path.cwd().joinpath( + "tests", "data", ".qgis-plugin-ci-test-changelog.yaml" + ) print(config_yaml) with open(config_yaml) as f: arg_dict = yaml.safe_load(f) - transifex_token = os.getenv("transifex_token") + transifex_token = os.getenv("TX_TOKEN") assert transifex_token cls.transifex_token = transifex_token @@ -37,15 +40,15 @@ def tearDown(self): logger.debug(error) """ - def test_creation(self): + def test1_creation(self): self.tearDown() self.t = Translation(self.parameters, transifex_token=self.transifex_token) # type: ignore - def test_push(self): + def test2_push(self): self.t.update_strings() self.t.push() - def test_pull(self): + def test3_pull(self): self.t.pull() self.t.compile_strings()