From c1e499102bdbc188c7b4ba1b5cd40fa3e8cb2790 Mon Sep 17 00:00:00 2001 From: Carlos Herrero <26092748+hbcarlos@users.noreply.github.com> Date: Fri, 13 Oct 2023 12:03:48 +0200 Subject: [PATCH] Fix tests --- tests/conftest.py | 18 +++++++++--------- tests/test_rooms.py | 27 +++++++++++++++++---------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index dd323d42..3e9bf5ca 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,7 @@ import json from asyncio import Event, sleep from datetime import datetime +from logging import getLogger from typing import Any import nbformat @@ -170,9 +171,7 @@ def rtc_create_SQLite_store(jp_serverapp): setattr(SQLiteYStore, k, v) async def _inner(type: str, path: str, content: str) -> DocumentRoom: - room_id = f"{type}:{path}" - db = SQLiteYStore() - await db.start() + db = SQLiteYStore(log=getLogger(__name__)) await db.initialize() if type == "notebook": @@ -182,8 +181,8 @@ async def _inner(type: str, path: str, content: str) -> DocumentRoom: doc.source = content - await db.create(room_id, 0) - await db.encode_state_as_update(room_id, doc.ydoc) + await db.create(path, 0) + await db.encode_state_as_update(path, doc.ydoc) return db @@ -193,14 +192,15 @@ async def _inner(type: str, path: str, content: str) -> DocumentRoom: @pytest.fixture def rtc_create_mock_document_room(): def _inner( - id: str, + room_id: str, + path_id: str, path: str, content: str, last_modified: datetime | None = None, save_delay: float | None = None, store: SQLiteYStore | None = None, ) -> tuple[FakeContentsManager, FileLoader, DocumentRoom]: - paths = {id: path} + paths = {path_id: path} if last_modified is None: cm = FakeContentsManager({"content": content}) @@ -208,7 +208,7 @@ def _inner( cm = FakeContentsManager({"last_modified": datetime.now(), "content": content}) loader = FileLoader( - id, + path_id, FakeFileIDManager(paths), cm, poll_interval=0.1, @@ -218,7 +218,7 @@ def _inner( cm, loader, DocumentRoom( - "test-room", "text", "file", loader, FakeEventLogger(), store, None, save_delay + room_id, "text", "file", loader, FakeEventLogger(), store, None, save_delay ), ) diff --git a/tests/test_rooms.py b/tests/test_rooms.py index 7ecc5ccd..9f4669bb 100644 --- a/tests/test_rooms.py +++ b/tests/test_rooms.py @@ -15,7 +15,7 @@ @pytest.mark.asyncio async def test_should_initialize_document_room_without_store(rtc_create_mock_document_room): content = "test" - _, _, room = rtc_create_mock_document_room("test-id", "test.txt", content) + _, _, room = rtc_create_mock_document_room("test-id", "test_path", "test.txt", content) await room.initialize() assert room._document.source == content @@ -29,10 +29,11 @@ async def test_should_initialize_document_room_from_store( # If the content from the store is different than the content from disk, # the room will initialize with the content from disk and overwrite the document - id = "test-id" + room_id = "test-id" + path_id = "test_path" content = "test" - store = await rtc_create_SQLite_store("file", id, content) - _, _, room = rtc_create_mock_document_room("test-id", "test.txt", content, store=store) + store = await rtc_create_SQLite_store("file", room_id, content) + _, _, room = rtc_create_mock_document_room(room_id, path_id, "test.txt", content, store=store) await room.initialize() assert room._document.source == content @@ -43,13 +44,13 @@ async def test_should_overwrite_the_store(rtc_create_SQLite_store, rtc_create_mo id = "test-id" content = "test" store = await rtc_create_SQLite_store("file", id, "whatever") - _, _, room = rtc_create_mock_document_room("test-id", "test.txt", content, store=store) + _, _, room = rtc_create_mock_document_room(id, "test_path", "test.txt", content, store=store) await room.initialize() assert room._document.source == content doc = YUnicode() - await store.apply_updates(doc.ydoc) + await store.apply_updates(id, doc.ydoc) assert doc.source == content @@ -59,7 +60,9 @@ async def test_defined_save_delay_should_save_content_after_document_change( rtc_create_mock_document_room, ): content = "test" - cm, _, room = rtc_create_mock_document_room("test-id", "test.txt", content, save_delay=0.01) + cm, _, room = rtc_create_mock_document_room( + "test-id", "test_path", "test.txt", content, save_delay=0.01 + ) await room.initialize() room._document.source = "Test 2" @@ -75,7 +78,9 @@ async def test_undefined_save_delay_should_not_save_content_after_document_chang rtc_create_mock_document_room, ): content = "test" - cm, _, room = rtc_create_mock_document_room("test-id", "test.txt", content, save_delay=None) + cm, _, room = rtc_create_mock_document_room( + "test-id", "test_path", "test.txt", content, save_delay=None + ) await room.initialize() room._document.source = "Test 2" @@ -92,7 +97,7 @@ async def test_should_reload_content_from_disk(rtc_create_mock_document_room): last_modified = datetime.now() cm, loader, room = rtc_create_mock_document_room( - "test-id", "test.txt", "whatever", last_modified + "test-id", "test_path", "test.txt", "whatever", last_modified ) await room.initialize() @@ -114,7 +119,9 @@ async def test_should_not_reload_content_from_disk(rtc_create_mock_document_room content = "test" last_modified = datetime.now() - cm, loader, room = rtc_create_mock_document_room("test-id", "test.txt", content, last_modified) + cm, loader, room = rtc_create_mock_document_room( + "test-id", "test_path", "test.txt", content, last_modified + ) await room.initialize()