Skip to content

Commit

Permalink
Add test workflow (#8)
Browse files Browse the repository at this point in the history
* add test workflow

---------

Co-authored-by: tr4nt0r <manni@zapto.de>
  • Loading branch information
miaucl and tr4nt0r authored Feb 14, 2024
1 parent 4ef19df commit 4774c1c
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ test/
.venv
__pycache__
.ruff_cache
.mypy_cache
.mypy_cache
.env
24 changes: 24 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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}"
}
}
]
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.1.4

Add test workflow.

## 0.1.3

Add mypy for type-checking.
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
59 changes: 59 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -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())

0 comments on commit 4774c1c

Please sign in to comment.