diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py index 3c7c905a0..0fcec6ab2 100644 --- a/tests/helpers/fixtures.py +++ b/tests/helpers/fixtures.py @@ -225,6 +225,15 @@ def web_history_stub(stubs): objreg.delete('web-history') +@pytest.yield_fixture +def session_manager_stub(stubs): + """Fixture which provides a fake web-history object.""" + stub = stubs.SessionManagerStub() + objreg.register('session-manager', stub) + yield stub + objreg.delete('session-manager') + + @pytest.fixture(scope='session') def stubs(): """Provide access to stub objects useful for testing.""" diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index 5bff97c09..2d27406d4 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -469,3 +469,14 @@ class HostBlockerStub: def __init__(self): self.blocked_hosts = set() + + +class SessionManagerStub: + + """Stub for the session-manager object.""" + + def __init__(self): + self.sessions = [] + + def list_sessions(self): + return self.sessions diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 45e17ab52..6d0de25be 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -176,6 +176,14 @@ def test_url_completion(config_stub, web_history, quickmarks, bookmarks): ] +def test_session_completion(session_manager_stub): + session_manager_stub.sessions = ['default', '1', '2'] + actual = _get_completions(miscmodels.SessionCompletionModel()) + assert actual == [ + ("Sessions", [('default', '', ''), ('1', '', ''), ('2', '', '')]) + ] + + def _get_completions(model): """Collect all the completion entries of a model, organized by category.