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

Commit

Permalink
Merge pull request #24 from opengisch/integrated-qgisplugci-test
Browse files Browse the repository at this point in the history
Integrated qgisplugci initialization test
  • Loading branch information
why-not-try-calmer authored Feb 23, 2023
2 parents e1af44c + fb04aa0 commit 27a2fc2
Show file tree
Hide file tree
Showing 8 changed files with 375 additions and 65 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: test pytransifex

concurrency: testing_environment

on:
pull_request:
branches:
- master
push:
branches:
- master
workflow_dispatch:
workflow_call:


jobs:
tests:
runs-on: ubuntu-latest
steps:
# Not using strategy.matrix to create multiple jobs
# as we do NOT want to test with any form of concurrency
# to avoid 'race conditions' against Transifex

- name: Check out repository code
uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
cache-dependency-path: "requirements/*.txt"

- name: Install project requirements
run: |
python -m pip install -U -r requirements/base.txt
python -m pip install -U -r requirements/dev.txt
- name: Test API
env:
organization: ${{ secrets.ORGANIZATION }}
tx_token: ${{ secrets.TX_TOKEN }}
run: |
TX_TOKEN=$tx_token ORGANIZATION=$organization \
python -m unittest ./tests/test_api.py
- name: Test CLI
env:
organization: ${{ secrets.ORGANIZATION }}
tx_token: ${{ secrets.TX_TOKEN }}
run: |
TX_TOKEN=$tx_token ORGANIZATION=$organization \
python -m unittest ./tests/test_cli.py
- name: Test with a public project
env:
organization: ${{ secrets.ORGANIZATION }}
tx_token: ${{ secrets.TX_TOKEN }}
run: |
TX_TOKEN=$tx_token ORGANIZATION=$organization \
python -m unittest ./tests/test_public_project.py
- name: Test with Qgisplugin's 'test_translation'
env:
organization: ${{ secrets.ORGANIZATION }}
tx_token: ${{ secrets.TX_TOKEN }}
run: |
TX_TOKEN=$tx_token ORGANIZATION=$organization \
python -m unittest ./tests/test_translation.py
38 changes: 0 additions & 38 deletions .github/workflows/test_pytx.yml

This file was deleted.

23 changes: 16 additions & 7 deletions pytransifex/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ def create_project(
*,
project_slug: str,
project_name: str | None = None,
source_language_code: str = "en_GB",
source_language_code: str = "en",
private: bool = False,
**kwargs,
):
"""Create a project."""
logger.info(
f"Trying to create project from these arguments: project_slug = {project_slug}, "
)
source_language = tx_api.Language.get(code=source_language_code)
project_name = project_name or project_slug

Expand All @@ -82,12 +85,19 @@ def delete_project(self, project_slug: str):
def get_project(self, project_slug: str) -> None | Resource:
"""Fetches the project matching the given slug"""
if self.projects:
logger.info(
f"Attempting to get 'o:{self.organization_name}:p:{project_slug}'"
)
try:
res = self.projects.get(slug=project_slug)
logger.info("Got the project!")
return res
except DoesNotExist:
return None
"""
except MultipleObjectsReturned:
pass
"""

@ensure_login
def list_resources(self, project_slug: str) -> list[Any]:
Expand Down Expand Up @@ -247,7 +257,9 @@ def create_language(
):
"""Create a new language resource in the remote Transifex repository"""
if project := self.get_project(project_slug=project_slug):
project.add("languages", [tx_api.Language.get(code=language_code)])
if language := tx_api.Language.get(code=language_code):
logger.debug(f"Adding {language.code} to {project_slug}")
project.add("languages", [language])

if coordinators:
project.add("coordinators", coordinators)
Expand All @@ -260,12 +272,9 @@ def create_language(
def project_exists(self, project_slug: str) -> bool:
"""Check if the project exists in the remote Transifex repository"""
try:
if not self.projects:
return False
elif self.get_project(project_slug=project_slug):
if self.get_project(project_slug=project_slug):
return True
else:
return False
return False
except DoesNotExist:
return False

Expand Down
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
nose2
PyYAML
Loading

0 comments on commit 27a2fc2

Please sign in to comment.