diff --git a/pytransifex/api.py b/pytransifex/api.py index 11546a2..eb29918 100644 --- a/pytransifex/api.py +++ b/pytransifex/api.py @@ -237,16 +237,30 @@ def get_translation( ) @ensure_login - def list_languages(self, project_slug: str, resource_slug: str) -> list[Any]: + def list_languages(self, project_slug: str, resource_slug: str) -> list[str]: """ List languages for which there exist translations under the given resource. """ if self.projects: if project := self.projects.get(slug=project_slug): if resource := project.fetch("resources").get(slug=resource_slug): - logging.info(f"Obtained these languages") - # FIXME: Extract a list[str] mapping to resource languages - return resource + it = tx_api.ResourceLanguageStats.filter( + project=project, resource=resource + ).all() + + language_codes = [] + for tr in it: + """ + FIXME + This is hideous and probably unsound for some language_codes. + Couldn't find a more direct accessor to language codes. + """ + code = str(tr).rsplit("_", 1)[-1][:-1] + language_codes.append(code) + + logging.info(f"Obtained these languages: {language_codes}") + return language_codes + raise ValueError( f"Unable to find any resource with this slug: '{resource_slug}'" ) @@ -263,7 +277,7 @@ def create_language( *, project_slug: str, language_code: str, - coordinators: None | list[Any] = None, + coordinators: None | list[str] = None, ): """Create a new language resource in the remote Transifex repository""" if project := self.get_project(project_slug=project_slug): diff --git a/tests/test_api.py b/tests/test_api.py index fd23740..33f073d 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -107,7 +107,7 @@ def test8_get_translation(self): def test9_project_exists(self): verdict = self.tx.project_exists(project_slug=self.project_slug) - assert verdict is not None + assert verdict def test10_ping(self): self.tx.ping() diff --git a/tests/test_cli.py b/tests/test_cli.py index 0dc5d4b..c9dd45e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -58,7 +58,7 @@ def test1_init(self): assert passed def test2_push(self): - result = self.runner.invoke(cli, ["push", "-in", str(self.path_to_file)]) + result = self.runner.invoke(cli, ["push", "-in", str(self.path_to_input_dir)]) passed = result.exit_code == 0 logging.info(result.output) assert passed diff --git a/tests/test_utils.py b/tests/test_utils.py index b5d4b35..b9edcb5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -26,3 +26,7 @@ def test1_map_async(self): def test2_map_async(self): res = concurrently(fn=fn, args=self.args) assert res == self.res + + +if __name__ == "__main__": + unittest.main()