Skip to content

Commit

Permalink
test: generate json schemas on-demand (#450)
Browse files Browse the repository at this point in the history
* test: remove json schemas test cases

* test: remove json schemas test cases

* chore: apply linters

* ci: Workflow dispatch on generating json schema

* chore: Generate JSON Schemas from API
  • Loading branch information
germainlefebvre4 authored Jan 27, 2025
1 parent 7e55e71 commit c2ff1aa
Show file tree
Hide file tree
Showing 40 changed files with 2,620 additions and 791 deletions.
30 changes: 19 additions & 11 deletions .github/workflows/check_json_schemas.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
---
name: JSON Schemas
on:
- pull_request
- workflow_dispatch

jobs:
generate:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
poetry-version: ["main"]

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.10
- name: Set up Python version ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: ${{ matrix.python-version }}
- name: Setup poetry version ${{ matrix.poetry-version }}
uses: abatilo/actions-poetry@v4
with:
poetry-version: ${{ matrix.poetry-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry tox
poetry export --with=test --without-hashes --format=requirements.txt > requirements.txt
poetry install
- name: Generate JSON Schemas
run:
tox -e generate_json_schemas
run: |
export TADO_PASSWORD=$(echo $TADO_PASSWORD_B64 | base64 -d)
python generate_json_schemas.py
env:
TADO_USERNAME: ${{ secrets.TADO_USERNAME }}
TADO_PASSWORD: ${{ secrets.TADO_PASSWORD }}
TADO_PASSWORD_B64: ${{ secrets.TADO_PASSWORD_B64 }}
TADO_CLIENT_SECRET: ${{ secrets.TADO_CLIENT_SECRET }}
TADO_BRIDGE_AUTHKEY: ${{ secrets.TADO_BRIDGE_AUTHKEY }}

- name: Verify Changed files
uses: tj-actions/verify-changed-files@v20
id: verify-changed-files
with:
files: 'schemas/*.json'

- name: List all changed tracked and untracked files
env:
CHANGED_FILES: ${{ steps.verify-changed-files.outputs.changed_files }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/conventional-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ jobs:
- name: Conventional commit check
uses: cocogitto/cocogitto-action@v3
with:
check-latest-tag-only: true

check-latest-tag-only: true
4 changes: 2 additions & 2 deletions .github/workflows/release-feat-dryrun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
ci: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Write in summary
run: |
echo "## Semantic Release" >> $GITHUB_STEP_SUMMARY
Expand All @@ -51,7 +51,7 @@ jobs:
env:
NEW_RELEASE_VERSION: ${{ steps.semantic.outputs.new_release_version }}
NEW_RELEASE_PUBLISHED: ${{ steps.semantic.outputs.new_release_published }}

- name: Write in outputs
id: version
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
dry_run: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Write in summary
run: |
echo "## Semantic Release" >> $GITHUB_STEP_SUMMARY
Expand All @@ -51,7 +51,7 @@ jobs:
env:
NEW_RELEASE_VERSION: ${{ steps.semantic.outputs.new_release_version }}
NEW_RELEASE_PUBLISHED: ${{ steps.semantic.outputs.new_release_published }}

- name: Write in outputs
id: version
run: |
Expand Down
22 changes: 14 additions & 8 deletions .github/workflows/template_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@ jobs:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
poetry-version: ["main"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- name: Set up Python version ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Setup poetry version ${{ matrix.poetry-version }}
uses: abatilo/actions-poetry@v4
with:
poetry-version: ${{ matrix.poetry-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry tox
poetry export --with=test --without-hashes --format=requirements.txt > requirements.txt
poetry install --with=test
- name: Test with pytest
- name: Run pytest
run: |
tox -e py${{ matrix.python-version }},unittest
export TADO_PASSWORD=$(echo $TADO_PASSWORD_B64 | base64 -d)
poetry run pytest tests/api/test_api.py tests/api/test_tado.py
env:
TADO_USERNAME: ${{ secrets.TADO_USERNAME }}
TADO_PASSWORD: ${{ secrets.TADO_PASSWORD }}
TADO_PASSWORD_B64: ${{ secrets.TADO_PASSWORD_B64 }}
TADO_CLIENT_SECRET: ${{ secrets.TADO_CLIENT_SECRET }}
TADO_BRIDGE_AUTHKEY: ${{ secrets.TADO_BRIDGE_AUTHKEY }}
27 changes: 23 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v4.4.0
rev: v5.0.0
hooks:
- id: mixed-line-ending
args:
Expand All @@ -14,19 +14,38 @@ repos:
- id: check-added-large-files

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.30.0
rev: v1.35.1
hooks:
- id: yamllint
args:
- --strict
- --config-file=./.yamllint

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.284
rev: v0.9.3
hooks:
- id: ruff

- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.8.1
rev: v0.17.2
hooks:
- id: markdownlint-cli2

- repo: https://github.com/python-poetry/poetry
rev: 2.0.1
hooks:
- id: poetry-lock
- id: poetry-check

# - repo: https://github.com/python-poetry/poetry-plugin-export
# rev: 1.9.0
# hooks:
# - id: poetry-export

- repo: local
hooks:
- id: generate-json-schemas
name: Check JSON Schemas
language: system
types: [python]
entry: python generate_json_schemas.py
2 changes: 1 addition & 1 deletion generate_json_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def generate_jsonschema_file(filename: str, data: object):


tado_methods = inspect.getmembers(utils.TestApi, predicate=inspect.isfunction)
tado_methods = [method[0] for method in tado_methods if method[0].startswith('get_')]
tado_methods = [method[0] for method in tado_methods if method[0].startswith('get_') or method[0].startswith('set_')]

for method in tado_methods:
print(f"Calling {method}")
Expand Down
8 changes: 4 additions & 4 deletions libtado/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,10 @@ def set_invitation(self, email):
Parameters:
email (str): The email of the user to invite.
Returns:
(dict): The invitation information.
??? info "Result example"
```json
{
Expand Down Expand Up @@ -719,10 +719,10 @@ def set_invitation(self, email):
def delete_invitation(self, token):
"""
Delete an invitation.
Parameters:
token (str): The token of the invitation to delete.
Returns:
(None): None.
"""
Expand Down
Loading

0 comments on commit c2ff1aa

Please sign in to comment.