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

Commit

Permalink
Added test for public transifex repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer committed Feb 20, 2023
1 parent a4dff86 commit 652d0d2
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 13 deletions.
9 changes: 6 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

logging.basicConfig(level=logging.INFO)

p = Path.cwd().joinpath("./tests/data/test_config.toml")
test_config = toml.load(p)
private = Path.cwd().joinpath("./tests/data/test_config.toml")
test_config_public = toml.load(private)

logging.info(f"Running tests with this test_config: {test_config}")
public = Path.cwd().joinpath("./tests/data/test_config_public.toml")
test_config_public = toml.load(public)

logging.info(f"Running tests with this test_config: {test_config_public}")
6 changes: 6 additions & 0 deletions tests/data/test_config_public.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
organization_slug = "test_pytransifex"
project_slug = "test_project_pytransifex_public"
project_name = "Python Transifex API testing (public)"
repository_url = "https://github.com/opengisch/pytransifex"
resource_slug = "test_resource_fr"
resource_name = "Test Resource FR"
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
from tests import logging, test_config_public


class TestNewApi(unittest.TestCase):
Expand All @@ -19,10 +19,10 @@ def setUpClass(cls):
cls.output_file = cls.output_dir.joinpath("test_resource_fr_DOWNLOADED.po")

cls.tx = client
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"]
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"]

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
from tests import logging, test_config_public


class TestCli(unittest.TestCase):
Expand All @@ -20,10 +20,10 @@ def setUpClass(cls):
cls.output_dir = Path.cwd().joinpath("tests", "output")

cls.tx = client
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"]
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"]

if missing := next(
filter(lambda p: not p.exists(), [cls.path_to_file, cls.path_to_input_dir]),
Expand Down
57 changes: 57 additions & 0 deletions tests/test_public_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import unittest
from os import remove
from pathlib import Path

from pytransifex.api import Transifex
from tests import logging, test_config_public


class TestCli(unittest.TestCase):
@classmethod
def setUpClass(cls):
client = Transifex(defer_login=True)
assert client

cls.path_to_input_dir = Path.cwd().joinpath("tests", "data", "resources")
cls.path_to_file = cls.path_to_input_dir.joinpath("test_resource_fr.po")
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"]
repository_url = test_config_public["repository_url"]

if missing := next(
filter(lambda p: not p.exists(), [cls.path_to_file, cls.path_to_input_dir]),
None,
):
raise ValueError(
f"Unable to complete test with broken tests inputs. Found missing: {missing}"
)

if project := cls.tx.get_project(project_slug=cls.project_slug):
logging.info("Found old project, removing.")
project.delete()

logging.info("Creating a brand new project")
cls.tx.create_project(
project_name=cls.project_name,
project_slug=cls.project_slug,
private=False,
repository_url=repository_url,
)

@classmethod
def tearDownClass(cls):
if Path.exists(cls.output_dir):
remove(cls.output_dir)

def test1_project_exists(self):
verdict = self.tx.project_exists(project_slug=self.project_slug)
assert verdict


if __name__ == "__main__":
unittest.main()

0 comments on commit 652d0d2

Please sign in to comment.