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

Commit

Permalink
Not catching exceptions when creating a project.
Browse files Browse the repository at this point in the history
Fixing typo swapping 'public' and 'private' in root __init__.py.
  • Loading branch information
why-not-try-calmer committed Feb 21, 2023
1 parent fd42a8d commit fdaa272
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
32 changes: 12 additions & 20 deletions pytransifex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
10 changes: 5 additions & 5 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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]),
Expand Down

0 comments on commit fdaa272

Please sign in to comment.