Skip to content

Commit

Permalink
Add test case, apply fix in the fixture too
Browse files Browse the repository at this point in the history
Co-authored-by: asteppke <[email protected]>
  • Loading branch information
krassowski and asteppke committed Jul 9, 2024
1 parent 7591bca commit 5bb041f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,9 @@ async def _inner(format: str, type: str, path: str) -> None:
return _inner


@pytest.fixture
def rtc_create_SQLite_store(jp_serverapp):
for k, v in jp_serverapp.config.get("SQLiteYStore").items():
setattr(SQLiteYStore, k, v)

def rtc_create_SQLite_store_factory(jp_serverapp):
async def _inner(type: str, path: str, content: str) -> DocumentRoom:
db = SQLiteYStore(path=f"{type}:{path}")
db = SQLiteYStore(path=f"{type}:{path}", config=jp_serverapp.config)
task = create_task(db.start())
await db.started.wait()

Expand All @@ -192,6 +188,11 @@ async def _inner(type: str, path: str, content: str) -> DocumentRoom:
return _inner


@pytest.fixture
def rtc_create_SQLite_store(jp_serverapp):
return rtc_create_SQLite_store_factory(jp_serverapp)


@pytest.fixture
def rtc_create_mock_document_room():
def _inner(
Expand Down
15 changes: 15 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import pytest
from jupyter_server_ydoc.stores import SQLiteYStore, TempFileYStore

from .conftest import rtc_create_SQLite_store_factory


def test_default_settings(jp_serverapp):
settings = jp_serverapp.web_app.settings["jupyter_server_ydoc_config"]
Expand Down Expand Up @@ -62,6 +64,19 @@ def test_settings_should_change_ystore_class(jp_configurable_serverapp):
assert settings["ystore_class"] == TempFileYStore


async def test_document_ttl_from_settings(rtc_create_mock_document_room, jp_configurable_serverapp):
argv = ["--SQLiteYStore.document_ttl=3600"]

app = jp_configurable_serverapp(argv=argv)

id = "test-id"
content = "test_ttl"
rtc_create_SQLite_store = rtc_create_SQLite_store_factory(app)
store = await rtc_create_SQLite_store("file", id, content)

assert store.document_ttl == 3600


@pytest.mark.parametrize("copy", [True, False])
async def test_get_document_file(rtc_create_file, jp_serverapp, copy):
path, content = await rtc_create_file("test.txt", "test", store=True)
Expand Down

0 comments on commit 5bb041f

Please sign in to comment.