From 4774c1ce8745b1dd026541982ca3ad8b3031886d Mon Sep 17 00:00:00 2001 From: Cyrill Raccaud Date: Wed, 14 Feb 2024 19:56:12 +0100 Subject: [PATCH] Add test workflow (#8) * add test workflow --------- Co-authored-by: tr4nt0r --- .github/workflows/test.yaml | 24 +++++++++++++++ .gitignore | 3 +- .vscode/tasks.json | 24 +++++++++++++++ CHANGELOG.md | 4 +++ README.md | 6 ++++ requirements_dev.txt | 1 + setup.cfg | 2 +- test.py | 59 +++++++++++++++++++++++++++++++++++++ 8 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test.yaml create mode 100644 .vscode/tasks.json create mode 100644 test.py diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..62b5875 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,24 @@ +name: Test + +on: [ push, pull_request ] + +env: + DEFAULT_PYTHON: "3.12" + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.1 + - uses: actions/setup-python@v5.0.0 + with: + python-version: ${{ env.DEFAULT_PYTHON }} + check-latest: true + - run: pip install -r requirements.txt + - run: pip install python-dotenv + - run: python test.py + env: + EMAIL: ${{ vars.EMAIL }} + PASSWORD: ${{ secrets.PASSWORD }} + LIST: ${{ vars.LIST }} + \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4a75fd1..7b6b86b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ test/ .venv __pycache__ .ruff_cache -.mypy_cache \ No newline at end of file +.mypy_cache +.env \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..4c5313c --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,24 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Python: Run Test", + "type": "shell", + "command": "${command:python.interpreterPath} test.py", + "problemMatcher": [], + "group": { + "kind": "test", + "isDefault": true + }, + "presentation": { + "focus": true, + "reveal": "always" + }, + "options": { + "cwd": "${workspaceFolder}" + } + } + ] +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b595ab..73a0b09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.1.4 + +Add test workflow. + ## 0.1.3 Add mypy for type-checking. diff --git a/README.md b/README.md index 06094e3..dfad13e 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,12 @@ pre-commit install # Run the commit hooks manually pre-commit run --all-files + +# Run tests locally (using a .env file is supported and recommended) +export EMAIL=... +export PASSWORD=... +export LIST=... +python test.py ``` Following VSCode integrations may be helpful: diff --git a/requirements_dev.txt b/requirements_dev.txt index c4c6c02..3e3dd89 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -14,6 +14,7 @@ mypy-extensions==1.0.0 nodeenv==1.8.0 platformdirs==4.2.0 pre-commit==3.6.1 +python-dotenv==1.0.1 PyYAML==6.0.1 ruff==0.2.1 tomli==2.0.1 diff --git a/setup.cfg b/setup.cfg index 357aa7e..93212f0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = bring-api -version = 0.1.3 +version = 0.1.4 author = Cyrill Raccaud author_email = cyrill.raccaud+pypi@gmail.com description = Unofficial package to access Bring! shopping lists API. diff --git a/test.py b/test.py new file mode 100644 index 0000000..8d36d9b --- /dev/null +++ b/test.py @@ -0,0 +1,59 @@ +"""Test script for Bring API.""" +import asyncio +import logging +import os +import sys + +import aiohttp +from dotenv import load_dotenv + +from bring_api.bring import Bring +from bring_api.types import BringList + +logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) + +load_dotenv() + + +async def test_add_complete_remove(bring: Bring, lst: BringList): + """Test add-complete-remove for an item.""" + + # Save an item with specifications to a certain shopping list + await bring.saveItem(lst["listUuid"], "Äpfel", "low fat") + + # Get all the pending items of a list + items = await bring.getItems(lst["listUuid"]) + logging.info("List purchase items: %s", items["purchase"]) + + # Check of an item + await bring.completeItem(lst["listUuid"], items["purchase"][0]["itemId"]) + + # Get all the recent items of a list + items = await bring.getItems(lst["listUuid"]) + logging.info("List recently items: %s", items["recently"]) + + # Remove an item from a list + await bring.removeItem(lst["listUuid"], "Äpfel") + + # Get all the items of a list + items = await bring.getItems(lst["listUuid"]) + logging.info("List all items: %s / %s", items["purchase"], items["recently"]) + + +async def main(): + """Test Bring API.""" + async with aiohttp.ClientSession() as session: + # Create Bring instance with email and password + bring = Bring(session, os.environ["EMAIL"], os.environ["PASSWORD"]) + # Login + await bring.login() + + # Get information about all available shopping list and select one to test with + lists = (await bring.loadLists())["lists"] + lst = next(lst for lst in lists if lst["name"] == os.environ["LIST"]) + logging.info("Selected list: %s (%s)", lst["name"], lst["listUuid"]) + + await test_add_complete_remove(bring, lst) + + +asyncio.run(main())