Skip to content

Add offline fixture-based testing framework#105

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/add-testing-framework-for-edupage
Draft

Add offline fixture-based testing framework#105
Copilot wants to merge 2 commits intomasterfrom
copilot/add-testing-framework-for-edupage

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 11, 2026

Edupage has no REST API, so the library parses HTML/JS responses that can change without notice. There's currently no way to test parsing logic without live credentials and a real Edupage session.

New module: edupage_api/testing.py

  • EduRecorder — context manager that wraps session.send to intercept a live session and serialise every HTTP exchange plus edupage.data to a JSON fixture file. Accepts an optional anonymiser callback to scrub personal data before writing.
  • MockSessionrequests.Session subclass that replays responses from a fixture keyed by (method, url). Raises UnexpectedRequestError for any unmapped request, keeping tests deterministic. Multiple responses for the same URL are consumed in order.
  • EdupageTestCaseunittest.TestCase base class with a get_edupage(fixture_path) factory that hydrates a fresh Edupage instance from a fixture and swaps in MockSession — no login flow, no network.

Fixture format

{
  "meta": { "subdomain": "myschool", "username": "student", "gsec_hash": "" },
  "data": { /* full userhome payload */ },
  "requests": [
    {
      "method": "GET",
      "url": "https://myschool.edupage.org/znamky/",
      "response": { "status_code": 200, "text": "" }
    }
  ]
}

Multiple fixture variants per feature (grades_school_a.json, grades_school_b.json) let you assert that parsers handle both old and new server response shapes simultaneously.

Usage

Record once (requires a real account):

from edupage_api import Edupage
from edupage_api.testing import EduRecorder

edupage = Edupage()
with EduRecorder(edupage, "tests/fixtures/grades.json", anonymiser=scrub):
    edupage.login("user", "pass", "myschool")
    edupage.get_grades()

Replay in CI (no credentials):

from edupage_api.testing import EdupageTestCase

class GradesTest(EdupageTestCase):
    def test_grade_count(self):
        edupage = self.get_edupage("tests/fixtures/grades.json")
        self.assertEqual(len(edupage.get_grades()), 5)

Initial tests

Adds tests/fixtures/notifications.json (synthetic, anonymised) and tests/test_notifications.py (19 tests) covering timeline item parsing, userProps state (starred/done), and MockSession error behaviour — all without network access.

Copilot AI and others added 2 commits April 11, 2026 23:23
…e) with fixtures and tests

Agent-Logs-Url: https://github.com/EdupageAPI/edupage-api/sessions/1fc8f639-eed6-483a-8126-1555e642ba88

Co-authored-by: ivanhrabcak <39710116+ivanhrabcak@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants