Skip to content

Commit

Permalink
wip: use django channels in playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yohanboniface committed Dec 26, 2024
1 parent a5db415 commit 4cc9540
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions umap/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from .websocket_server import (
JoinRequest,
JoinResponse,
ListPeersResponse,
OperationMessage,
PeerMessage,
Request,
ValidationError,
PeerMessage,
ListPeersResponse,
)


Expand Down
2 changes: 1 addition & 1 deletion umap/static/umap/js/modules/sync/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class SyncEngine {

start(authToken) {
this.transport = new WebSocketTransport(
this._umap.properties.websocketURI,
Utils.template(this._umap.properties.websocketURI, { id: this._umap.id }),
authToken,
this
)
Expand Down
13 changes: 13 additions & 0 deletions umap/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path

import pytest
from channels.testing import ChannelsLiveServerTestCase
from playwright.sync_api import expect

from ..base import mock_tiles
Expand Down Expand Up @@ -87,3 +88,15 @@ def websocket_server():
yield ds_proc
# Shut it down at the end of the pytest session
ds_proc.terminate()


@pytest.fixture(scope="function")
def channels_live_server(request, settings):
server = ChannelsLiveServerTestCase()
server.serve_static = False
server._pre_setup()
settings.WEBSOCKET_FRONT_URI = f"{server.live_server_ws_url}/ws/sync/{{id}}/"

yield server

server._post_teardown()
16 changes: 8 additions & 8 deletions umap/tests/integration/test_websocket_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@pytest.mark.xdist_group(name="websockets")
def test_websocket_connection_can_sync_markers(
new_page, live_server, websocket_server, tilelayer
new_page, live_server, channels_live_server, tilelayer
):
map = MapFactory(name="sync", edit_status=Map.ANONYMOUS)
map.settings["properties"]["syncEnabled"] = True
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_websocket_connection_can_sync_markers(

@pytest.mark.xdist_group(name="websockets")
def test_websocket_connection_can_sync_polygons(
context, live_server, websocket_server, tilelayer
context, live_server, channels_live_server, tilelayer
):
map = MapFactory(name="sync", edit_status=Map.ANONYMOUS)
map.settings["properties"]["syncEnabled"] = True
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_websocket_connection_can_sync_polygons(

@pytest.mark.xdist_group(name="websockets")
def test_websocket_connection_can_sync_map_properties(
new_page, live_server, websocket_server, tilelayer
new_page, live_server, channels_live_server, tilelayer
):
map = MapFactory(name="sync", edit_status=Map.ANONYMOUS)
map.settings["properties"]["syncEnabled"] = True
Expand Down Expand Up @@ -196,7 +196,7 @@ def test_websocket_connection_can_sync_map_properties(

@pytest.mark.xdist_group(name="websockets")
def test_websocket_connection_can_sync_datalayer_properties(
new_page, live_server, websocket_server, tilelayer
new_page, live_server, channels_live_server, tilelayer
):
map = MapFactory(name="sync", edit_status=Map.ANONYMOUS)
map.settings["properties"]["syncEnabled"] = True
Expand Down Expand Up @@ -225,7 +225,7 @@ def test_websocket_connection_can_sync_datalayer_properties(

@pytest.mark.xdist_group(name="websockets")
def test_websocket_connection_can_sync_cloned_polygons(
context, live_server, websocket_server, tilelayer
context, live_server, channels_live_server, tilelayer
):
map = MapFactory(name="sync", edit_status=Map.ANONYMOUS)
map.settings["properties"]["syncEnabled"] = True
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_websocket_connection_can_sync_cloned_polygons(

@pytest.mark.xdist_group(name="websockets")
def test_websocket_connection_can_sync_late_joining_peer(
new_page, live_server, websocket_server, tilelayer
new_page, live_server, channels_live_server, tilelayer
):
map = MapFactory(name="sync", edit_status=Map.ANONYMOUS)
map.settings["properties"]["syncEnabled"] = True
Expand Down Expand Up @@ -349,7 +349,7 @@ def test_websocket_connection_can_sync_late_joining_peer(


@pytest.mark.xdist_group(name="websockets")
def test_should_sync_datalayers(new_page, live_server, websocket_server, tilelayer):
def test_should_sync_datalayers(new_page, live_server, channels_live_server, tilelayer):
map = MapFactory(name="sync", edit_status=Map.ANONYMOUS)
map.settings["properties"]["syncEnabled"] = True
map.save()
Expand Down Expand Up @@ -422,7 +422,7 @@ def test_should_sync_datalayers(new_page, live_server, websocket_server, tilelay

@pytest.mark.xdist_group(name="websockets")
def test_create_and_sync_map(
new_page, live_server, websocket_server, tilelayer, login, user
new_page, live_server, channels_live_server, tilelayer, login, user
):
# Create a syncable map with peerA
peerA = login(user, prefix="Page A")
Expand Down

0 comments on commit 4cc9540

Please sign in to comment.