Skip to content

Commit

Permalink
ci: Create some tests finally
Browse files Browse the repository at this point in the history
  • Loading branch information
jcgoette committed Oct 18, 2024
1 parent 2f4cbf5 commit 4cb066d
Show file tree
Hide file tree
Showing 8 changed files with 1,086 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: pytest

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
pytest:
name: pytest
runs-on: ubuntu-latest

services:
babybuddy:
image: linuxserver/babybuddy
ports:
- 8000:8000
options: >- # Set health checks to wait until babybuddy has started
--health-cmd "curl --fail http://localhost:8000"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Retrieve API Key
run: |
# Retrieve CSRF token
csrf_token=$(curl -s -c cookies.txt 'http://localhost:8000/login/' | grep -oP 'name="csrfmiddlewaretoken" value="\K[^"]+')
if [ -z "$csrf_token" ]; then
echo "Failed to retrieve CSRF Token."
exit 1
fi
# Login and get session
login_response=$(curl -s 'http://localhost:8000/login/' \
-b cookies.txt \
-c cookies.txt \
--data-raw "csrfmiddlewaretoken=${csrf_token}&username=admin&password=admin&login=")
# Retrieve API key
api_key=$(curl -s 'http://localhost:8000/api/profile' \
-b cookies.txt \
| jq -r '.api_key')
if [ -z "$api_key" ]; then
echo "Failed to retrieve API Key."
exit 1
fi
# Set API key in GitHub environment
echo "api_key=$api_key" >> $GITHUB_ENV
- name: Checkout the repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: pip

- name: Install requirements
run: python3 -m pip install -r requirements-test.txt

- name: Run tests
env:
BABY_BUDDY_HOST: http://localhost
BABY_BUDDY_PORT: 8000
API_KEY: ${{ env.api_key }}
run: |
pytest --maxfail=1 --disable-warnings -v
Loading

0 comments on commit 4cb066d

Please sign in to comment.