Skip to content

Commit d0f21e7

Browse files
author
Rolf Erik Normann
committed
Switch integration tests to username/password auth
Cookie-based auth expires; username/password secrets do not. Also remove server response echoing on login failure to avoid leaking any response content in CI logs.
1 parent 72a4dc1 commit d0f21e7

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ jobs:
4545

4646
- name: Run integration tests
4747
env:
48-
KIDPLAN_COOKIE: ${{ secrets.KIDPLAN_COOKIE }}
48+
KIDPLAN_USERNAME: ${{ secrets.KIDPLAN_USERNAME }}
49+
KIDPLAN_PASSWORD: ${{ secrets.KIDPLAN_PASSWORD }}
4950
run: pytest tests/test_integration.py -v

kidplan_fetcher/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def login(session: requests.Session, username: str, password: str) -> bool:
2727
try:
2828
data = resp.json()
2929
except Exception:
30-
print("ERROR: Unexpected response:", resp.text[:200])
30+
print("ERROR: Unexpected response from server.")
3131
return False
3232
if not data:
3333
print("ERROR: No kindergartens found.")

tests/test_integration.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""
2-
Integration tests — require a valid KIDPLAN_COOKIE environment variable.
2+
Integration tests — require KIDPLAN_USERNAME and KIDPLAN_PASSWORD environment variables.
33
44
These tests hit the real Kidplan API to verify that:
5+
- Authentication still works
56
- The album listing endpoint still returns data
67
- Album pages still contain parseable image links
78
- Image URLs are reachable and serve valid image content
89
910
Run locally:
10-
KIDPLAN_COOKIE=<value> pytest tests/test_integration.py -v
11+
KIDPLAN_USERNAME=your@email.com KIDPLAN_PASSWORD=secret pytest tests/test_integration.py -v
1112
"""
1213

1314
import imghdr
@@ -17,20 +18,22 @@
1718
import pytest
1819
import requests
1920

20-
from kidplan_fetcher.cli import get_all_albums, get_fullsize_urls
21+
from kidplan_fetcher.cli import get_all_albums, get_fullsize_urls, login
22+
23+
USERNAME = os.getenv("KIDPLAN_USERNAME")
24+
PASSWORD = os.getenv("KIDPLAN_PASSWORD")
2125

22-
COOKIE = os.getenv("KIDPLAN_COOKIE")
2326
pytestmark = pytest.mark.skipif(
24-
not COOKIE,
25-
reason="KIDPLAN_COOKIE environment variable not set",
27+
not USERNAME or not PASSWORD,
28+
reason="KIDPLAN_USERNAME and KIDPLAN_PASSWORD environment variables not set",
2629
)
2730

2831

2932
@pytest.fixture(scope="module")
3033
def session():
3134
s = requests.Session()
3235
s.headers["User-Agent"] = "Mozilla/5.0 (kidplan-fetcher-test)"
33-
s.cookies.set(".ASPXAUTH", COOKIE, domain="app.kidplan.com")
36+
assert login(s, USERNAME, PASSWORD), "Login failed — check credentials"
3437
return s
3538

3639

@@ -50,7 +53,6 @@ def test_album_list_has_required_fields(albums):
5053

5154

5255
def test_album_list_modified_timestamp(albums):
53-
"""Modified field must be parseable as /Date(ms)/."""
5456
import re
5557
for album in albums[:5]:
5658
assert re.search(r"\d+", album.get("Modified", "")), (
@@ -59,7 +61,6 @@ def test_album_list_modified_timestamp(albums):
5961

6062

6163
def test_first_album_with_pictures_has_image_urls(session, albums):
62-
"""Find the first non-empty album and verify image URLs are returned."""
6364
target = next((a for a in albums if a.get("PictureCount", 0) > 0), None)
6465
assert target is not None, "No album with pictures found"
6566

@@ -75,10 +76,9 @@ def test_image_urls_have_no_size_param(session, albums):
7576

7677

7778
def test_first_image_is_downloadable_jpeg(session, albums):
78-
"""Download the first image from the first non-empty album and verify it's a valid image."""
7979
target = next((a for a in albums if a.get("PictureCount", 0) > 0), None)
8080
pictures = get_fullsize_urls(session, target["AlbumId"])
81-
assert pictures, "No pictures to test"
81+
assert pictures
8282

8383
_guid, url = pictures[0]
8484
resp = session.get(url, stream=True, timeout=30)

0 commit comments

Comments
 (0)