Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
All tests passing for'test_api' and 'test_cli'. 2 missing on 'test_tr…
Browse files Browse the repository at this point in the history
…anslation'.
  • Loading branch information
why-not-try-calmer committed Feb 23, 2023
1 parent d50713e commit 3d62ca1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 52 deletions.
9 changes: 7 additions & 2 deletions pytransifex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
nose2
PyYAML
46 changes: 25 additions & 21 deletions tests/_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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,
)
Expand Down
10 changes: 6 additions & 4 deletions tests/data/.qgis-plugin-ci-test-changelog.yaml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 0 additions & 20 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
"""
13 changes: 8 additions & 5 deletions tests/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import unittest
from pathlib import Path

import yaml

from pytransifex.exceptions import PyTransifexException
Expand All @@ -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

Expand All @@ -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()

Expand Down

0 comments on commit 3d62ca1

Please sign in to comment.