From 24820c5fc4faf61008ee502aa2f24f92a04ef8b6 Mon Sep 17 00:00:00 2001 From: why-not-try-calmer Date: Mon, 20 Feb 2023 11:41:05 +0100 Subject: [PATCH] Added test for public transifex repositories --- tests/__init__.py | 9 +++-- tests/data/test_config.toml | 1 + tests/data/test_config_public.toml | 5 +++ tests/test_api.py | 10 +++--- tests/test_cli.py | 10 +++--- tests/test_public_project.py | 57 ++++++++++++++++++++++++++++++ 6 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 tests/data/test_config_public.toml create mode 100644 tests/test_public_project.py diff --git a/tests/__init__.py b/tests/__init__.py index c967a96..118e110 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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}") diff --git a/tests/data/test_config.toml b/tests/data/test_config.toml index 56f6796..f4324ed 100644 --- a/tests/data/test_config.toml +++ b/tests/data/test_config.toml @@ -1,5 +1,6 @@ organization_slug = "test_pytransifex" project_slug = "test_project_pytransifex" project_name = "Python Transifex API testing" +repository_url = "https://github.com/opengisch/pytransifex" resource_slug = "test_resource_fr" resource_name = "Test Resource FR" diff --git a/tests/data/test_config_public.toml b/tests/data/test_config_public.toml new file mode 100644 index 0000000..0d2da38 --- /dev/null +++ b/tests/data/test_config_public.toml @@ -0,0 +1,5 @@ +organization_slug = "test_pytransifex" +project_slug = "test_project_pytransifex_public" +project_name = "Python Transifex API testing (public)" +resource_slug = "test_resource_fr" +resource_name = "Test Resource FR" \ No newline at end of file diff --git a/tests/test_api.py b/tests/test_api.py index 33f073d..ce9a24e 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 +from tests import logging, test_config_public class TestNewApi(unittest.TestCase): @@ -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( diff --git a/tests/test_cli.py b/tests/test_cli.py index c9dd45e..b0a0498 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 +from tests import logging, test_config_public class TestCli(unittest.TestCase): @@ -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]), diff --git a/tests/test_public_project.py b/tests/test_public_project.py new file mode 100644 index 0000000..00ec364 --- /dev/null +++ b/tests/test_public_project.py @@ -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()