Skip to content

Commit 8d753f1

Browse files
committed
ci: Create some tests finally
1 parent 2f4cbf5 commit 8d753f1

File tree

8 files changed

+1147
-0
lines changed

8 files changed

+1147
-0
lines changed

.github/workflows/pytest.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: pytest
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
pytest:
13+
name: pytest
14+
runs-on: ubuntu-latest
15+
16+
services:
17+
babybuddy:
18+
image: linuxserver/babybuddy
19+
ports:
20+
- 8000:8000
21+
options: >- # Set health checks to wait until babybuddy has started
22+
--health-cmd "curl --fail http://localhost:8000"
23+
--health-interval 10s
24+
--health-timeout 5s
25+
--health-retries 5
26+
27+
steps:
28+
- name: Retrieve API Key
29+
run: |
30+
# Retrieve CSRF token
31+
csrf_token=$(curl -s -c cookies.txt 'http://localhost:8000/login/' | grep -oP 'name="csrfmiddlewaretoken" value="\K[^"]+')
32+
if [ -z "$csrf_token" ]; then
33+
echo "Failed to retrieve CSRF Token."
34+
exit 1
35+
fi
36+
37+
# Login and get session
38+
login_response=$(curl -s 'http://localhost:8000/login/' \
39+
-b cookies.txt \
40+
-c cookies.txt \
41+
--data-raw "csrfmiddlewaretoken=${csrf_token}&username=admin&password=admin&login=")
42+
43+
# Retrieve API key
44+
api_key=$(curl -s 'http://localhost:8000/api/profile' \
45+
-b cookies.txt \
46+
| jq -r '.api_key')
47+
48+
if [ -z "$api_key" ]; then
49+
echo "Failed to retrieve API Key."
50+
exit 1
51+
fi
52+
53+
# Set API key in GitHub environment
54+
echo "api_key=$api_key" >> $GITHUB_ENV
55+
56+
- name: Checkout the repository
57+
uses: actions/checkout@v4
58+
59+
- name: Set up Python
60+
uses: actions/setup-python@v5
61+
with:
62+
python-version: '3.x'
63+
cache: pip
64+
65+
- name: Install requirements
66+
run: python3 -m pip install -r requirements-test.txt
67+
68+
- name: Run tests
69+
env:
70+
BABY_BUDDY_HOST: http://localhost
71+
BABY_BUDDY_PORT: 8000
72+
API_KEY: ${{ env.api_key }}
73+
run: |
74+
pytest --maxfail=1 --disable-warnings -v

0 commit comments

Comments
 (0)