From fdaa27270ed7f246588507ce1da8e94740c666b2 Mon Sep 17 00:00:00 2001 From: why-not-try-calmer Date: Tue, 21 Feb 2023 15:57:23 +0100 Subject: [PATCH] Not catching exceptions when creating a project. Fixing typo swapping 'public' and 'private' in root __init__.py. --- pytransifex/api.py | 32 ++++++++++++-------------------- tests/__init__.py | 2 +- tests/test_api.py | 10 +++++----- tests/test_cli.py | 10 +++++----- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/pytransifex/api.py b/pytransifex/api.py index 3d71c54..73bb833 100644 --- a/pytransifex/api.py +++ b/pytransifex/api.py @@ -4,7 +4,6 @@ import requests from transifex.api import transifex_api as tx_api -from transifex.api.jsonapi import JsonApiException from transifex.api.jsonapi.exceptions import DoesNotExist from transifex.api.jsonapi.resources import Resource @@ -57,28 +56,21 @@ def create_project( source_language_code: str = "en_GB", private: bool = False, **kwargs, - ) -> None | Resource: + ): """Create a project.""" source_language = tx_api.Language.get(code=source_language_code) project_name = project_name or project_slug - try: - proj = tx_api.Project.create( - name=project_name, - slug=project_slug, - source_language=source_language, - private=private, - organization=self.organization, - **kwargs, - ) - logger.info(f"Project created with name '{project_name}' !") - return proj + tx_api.Project.create( + name=project_name, + slug=project_slug, + source_language=source_language, + private=private, + organization=self.organization, + **kwargs, + ) - except JsonApiException as error: - if hasattr(error, "detail") and "already exists" in error.detail: # type: ignore - return self.get_project(project_slug=project_slug) - else: - logger.error(f"Unable to create project; API replied with {error}") + logger.info(f"Project created with name '{project_name}' !") @ensure_login def delete_project(self, project_slug: str): @@ -270,7 +262,7 @@ def project_exists(self, project_slug: str) -> bool: try: if not self.projects: return False - elif self.projects.get(slug=project_slug): + elif self.get_project(project_slug=project_slug): return True else: return False @@ -283,7 +275,7 @@ def ping(self) -> bool: Exposing this just for the sake of satisfying qgis-plugin-cli's expectations There is no need to ping the server on the current implementation, as connection is handled by the SDK """ - logger.info("'ping' is deprecated!") + logger.warning("'ping' is deprecated!") return True @ensure_login diff --git a/tests/__init__.py b/tests/__init__.py index 1599bf8..26b43eb 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -13,5 +13,5 @@ test_config_public = toml.load(public) logging.info( - f"Running tests with this test_config: {test_config} and test_config_public: {test_config_public}" + f"Running tests with this test_config: {test_config_public} and test_config_public: {test_config_public}" ) diff --git a/tests/test_api.py b/tests/test_api.py index 3c661cc..6a3c385 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -4,7 +4,7 @@ from pytransifex.api import Transifex from pytransifex.interfaces import Tx -from tests import logging, test_config_public +from tests import logging, test_config logger = logging.getLogger(__name__) @@ -21,10 +21,10 @@ def setUpClass(cls): cls.output_file = cls.output_dir.joinpath("test_resource_fr_DOWNLOADED.po") cls.tx = client - cls.project_slug = test_config_public["project_slug"] - cls.project_name = test_config_public["project_name"] - cls.resource_slug = test_config_public["resource_slug"] - cls.resource_name = test_config_public["resource_name"] + cls.project_slug = test_config["project_slug"] + cls.project_name = test_config["project_name"] + cls.resource_slug = test_config["resource_slug"] + cls.resource_name = test_config["resource_name"] if missing := next(filter(lambda p: not p.exists(), [cls.path_to_file]), None): raise ValueError( diff --git a/tests/test_cli.py b/tests/test_cli.py index 4960f36..99ddcaa 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -6,7 +6,7 @@ from pytransifex.api import Transifex from pytransifex.cli import cli -from tests import logging, test_config_public +from tests import logging, test_config logger = logging.getLogger(__name__) @@ -22,10 +22,10 @@ def setUpClass(cls): cls.output_dir = Path.cwd().joinpath("tests", "output") cls.tx = client - cls.project_slug = test_config_public["project_slug"] - cls.project_name = test_config_public["project_name"] - cls.resource_slug = test_config_public["resource_slug"] - cls.resource_name = test_config_public["resource_name"] + cls.project_slug = test_config["project_slug"] + cls.project_name = test_config["project_name"] + cls.resource_slug = test_config["resource_slug"] + cls.resource_name = test_config["resource_name"] if missing := next( filter(lambda p: not p.exists(), [cls.path_to_file, cls.path_to_input_dir]),