modular parser framework
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
# -*- 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"
|
||||
Reference in New Issue
Block a user