d041ef6a54
* First commit marking mvp decorator * Minor code style enhancements * Fixing some mvp test * Fixing some mvp test * Fixing test_sync_execute_register_no_hid_tag_not_linked * First iteration with almost all mvp tests working correctly * Rollback models.pyi of lot and device resources * Changing Github action to execute tests with tag mvp
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
from unittest.mock import Mock
|
|
|
|
import pytest
|
|
|
|
from ereuse_devicehub.devicehub import Devicehub
|
|
from ereuse_devicehub.dispatchers import PathDispatcher
|
|
from tests.conftest import TestConfig
|
|
|
|
|
|
def noop():
|
|
pass
|
|
|
|
|
|
@pytest.mark.mvp
|
|
@pytest.fixture()
|
|
def dispatcher(app: Devicehub, config: TestConfig) -> PathDispatcher:
|
|
PathDispatcher.call = Mock(side_effect=lambda *args: args[0])
|
|
return PathDispatcher(config_cls=config)
|
|
|
|
|
|
@pytest.mark.mvp
|
|
def test_dispatcher_default(dispatcher: PathDispatcher):
|
|
"""The dispatcher returns not found for an URL that does not
|
|
route to an app.
|
|
"""
|
|
app = dispatcher({'SCRIPT_NAME:': '/', 'PATH_INFO': '/'}, noop)
|
|
assert app == PathDispatcher.NOT_FOUND
|
|
app = dispatcher({'SCRIPT_NAME:': '/', 'PATH_INFO': '/foo/foo'}, noop)
|
|
assert app == PathDispatcher.NOT_FOUND
|
|
|
|
|
|
@pytest.mark.mvp
|
|
def test_dispatcher_return_app(dispatcher: PathDispatcher):
|
|
"""The dispatcher returns the correct app for the URL."""
|
|
# Note that the dispatcher does not check if the URL points
|
|
# to a well-known endpoint for the app.
|
|
# Only if can route it to an app. And then the app checks
|
|
# if the path exists
|
|
app = dispatcher({'SCRIPT_NAME:': '/', 'PATH_INFO': '/test/foo/'}, noop)
|
|
assert isinstance(app, Devicehub)
|
|
assert app.id == 'test'
|
|
|
|
|
|
@pytest.mark.mvp
|
|
def test_dispatcher_users(dispatcher: PathDispatcher):
|
|
"""Users special endpoint returns an app."""
|
|
# For now returns the first app, as all apps
|
|
# can answer {}/users/login
|
|
app = dispatcher({'SCRIPT_NAME:': '/', 'PATH_INFO': '/users/'}, noop)
|
|
assert isinstance(app, Devicehub)
|
|
assert app.id == 'test'
|