From 2fdb0633785afec31265ebe680b3d551e0fda638 Mon Sep 17 00:00:00 2001 From: Danil Akhtarov Date: Mon, 16 Dec 2024 23:20:58 +0400 Subject: [PATCH] test: test jinja --- .github/workflows/check.yml | 4 +++- .github/workflows/release.yml | 4 +++- sportorg/libs/template/template.py | 3 +-- tests/test_templates.py | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 tests/test_templates.py diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 75daf56c..6bb90bca 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -75,7 +75,9 @@ jobs: - name: Install python dependencies run: pip install poetry && poetry install -E win - name: Generate mo files - run: poetry run poe generate-mo generate-version + run: poetry run poe generate-mo + - name: Generate version file + run: poetry run poe generate-version - name: Build run: poetry run python builder.py build - name: Generate installer diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d8c72b7d..1fa611e5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,7 +26,9 @@ jobs: - name: Install python dependencies run: pip install poetry && poetry install -E win - name: Generate mo files - run: poetry run poe generate-mo generate-version + run: poetry run poe generate-mo + - name: Generate version file + run: poetry run poe generate-version - name: Build run: poetry run python builder.py build - name: Generate installer diff --git a/sportorg/libs/template/template.py b/sportorg/libs/template/template.py index bbdba0dd..d0ce2721 100644 --- a/sportorg/libs/template/template.py +++ b/sportorg/libs/template/template.py @@ -36,8 +36,7 @@ def finalize(thing): def get_text_from_path(path, **kwargs): - custom_encoding = locale.getdefaultlocale()[1] - # custom_encoding = 'cp1251' + custom_encoding = locale.getdefaultlocale()[1] or "utf-8" with open(path, errors="ignore") as f: html = f.read().encode(custom_encoding, "ignore").decode(errors="ignore") diff --git a/tests/test_templates.py b/tests/test_templates.py new file mode 100644 index 00000000..9f695301 --- /dev/null +++ b/tests/test_templates.py @@ -0,0 +1,20 @@ +from sportorg.common.template import get_text_from_file +from sportorg.models.constant import RentCards +from sportorg.models.memory import get_current_race_index, races +from sportorg.modules.backup.file import File + + +def test_generate_report(): + File("tests/data/test.json").open() + races_dict = [r.to_dict() for r in races()] + + result = get_text_from_file( + "reports/1_results.html", + race=races_dict[get_current_race_index()], + races=races_dict, + rent_cards=list(RentCards().get()), + current_race=get_current_race_index(), + selected={"persons": []}, + ) + + assert result