Files
OpenMensa-Parsers/tests/test_webspeiseplan_api.py
2026-05-21 08:21:49 +00:00

44 lines
1.3 KiB
Python

# -*- encoding: utf-8 -*-
import httpretty
import pytest
from openmensa_parsers.webspeiseplan_api import WebspeiseplanAPI
# pytest fixtures are linked via parameter names of test methods
# pragma pylint: disable=unused-import,unused-argument,redefined-outer-name
from tests.stub_api import api_offline
def test_api_init_does_not_fetch(api_offline):
"""Creating the API client does not perform network requests."""
WebspeiseplanAPI("https://menus.example.test")
def test_api_init_requires_valid_base_url():
"""Creating the API client validates the base URL."""
with pytest.raises(ValueError):
WebspeiseplanAPI("menus.example.test")
def test_parse_token_uses_configured_base_url():
"""The API client uses the configured Webspeiseplan host."""
httpretty.enable(allow_net_connect=False)
try:
httpretty.register_uri(
httpretty.GET,
"https://menus.example.test",
body='<script src="/main.abc123.js"></script>',
)
httpretty.register_uri(
httpretty.GET,
"https://menus.example.test/main.abc123.js",
body='PROXY_TOKEN: "0123456789abcdef"',
)
token = WebspeiseplanAPI("https://menus.example.test/").parse_token()
finally:
httpretty.disable()
httpretty.reset()
assert token == "0123456789abcdef"