Skip to content

Commit f2b093f

Browse files
committed
separating tests
1 parent eaa2ff2 commit f2b093f

File tree

2 files changed

+106
-32
lines changed

2 files changed

+106
-32
lines changed

services/web/server/tests/unit/with_dbs/02/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,19 @@ def with_enabled_rtc_collaboration(
508508
)
509509
},
510510
)
511+
512+
513+
@pytest.fixture
514+
def with_enabled_rtc_collaboration_limited_to_1_user(
515+
app_environment: EnvVarsDict,
516+
with_dev_features_enabled: None,
517+
monkeypatch: pytest.MonkeyPatch,
518+
) -> None:
519+
setenvs_from_dict(
520+
monkeypatch,
521+
{
522+
"WEBSERVER_REALTIME_COLLABORATION": json_dumps(
523+
{"RTC_MAX_NUMBER_OF_USERS": 1}
524+
)
525+
},
526+
)

services/web/server/tests/unit/with_dbs/02/test_projects_states_handlers.py

Lines changed: 90 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import asyncio
99
import contextlib
1010
import logging
11-
import secrets
1211
from collections.abc import AsyncIterator, Awaitable, Callable, Iterator
1312
from copy import deepcopy
1413
from datetime import UTC, datetime, timedelta
@@ -1423,6 +1422,7 @@ def clean_redis_table(redis_client) -> None:
14231422
"""this just ensures the redis table is cleaned up between test runs"""
14241423

14251424

1425+
@pytest.mark.acceptance_test
14261426
@pytest.mark.parametrize(*standard_user_role_response())
14271427
async def test_open_shared_project_multiple_users(
14281428
max_number_of_user_sessions: int,
@@ -1559,33 +1559,6 @@ async def test_open_shared_project_multiple_users(
15591559
sio_n_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT], shared_project, []
15601560
)
15611561

1562-
#
1563-
# TEST refreshing tab of some user shall work
1564-
#
1565-
refreshing_user_index = secrets.randbelow(len(other_users))
1566-
user_x, client_x, _, closed_sio_x, _ = other_users.pop(refreshing_user_index)
1567-
# close tab of user x
1568-
await closed_sio_x.disconnect()
1569-
await asyncio.sleep(5) # wait for the disconnect to be processed
1570-
(
1571-
new_sio_x,
1572-
new_client_x_tab_id,
1573-
new_sio_x_handlers,
1574-
) = await create_socketio_connection_with_handlers(client_x)
1575-
await _assert_project_state_updated(
1576-
new_sio_x_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1577-
shared_project,
1578-
[],
1579-
)
1580-
1581-
await _open_project(client_x, new_client_x_tab_id, shared_project, expected.ok)
1582-
1583-
await _assert_project_state_updated(
1584-
new_sio_x_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1585-
shared_project,
1586-
[opened_project_state],
1587-
)
1588-
15891562
# this triggers the new opening of the same users
15901563
for _user_j, client_j, _, _sio_j, sio_j_handlers in other_users:
15911564
# check already opened by other users which should also notify
@@ -1597,10 +1570,7 @@ async def test_open_shared_project_multiple_users(
15971570
await _state_project(
15981571
client_j, shared_project, expected.ok, opened_project_state
15991572
)
1600-
# put back the refreshed user in the list of other users
1601-
other_users.append(
1602-
(user_x, client_x, new_client_x_tab_id, new_sio_x, new_sio_x_handlers)
1603-
)
1573+
16041574
await _assert_project_state_updated(
16051575
sio_base_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
16061576
shared_project,
@@ -1643,6 +1613,94 @@ async def test_open_shared_project_multiple_users(
16431613
)
16441614

16451615

1616+
@pytest.mark.parametrize(*standard_user_role_response())
1617+
async def test_refreshing_tab_of_opened_project_multiple_users(
1618+
with_enabled_rtc_collaboration_limited_to_1_user: None,
1619+
client: TestClient,
1620+
client_on_running_server_factory: Callable[[], TestClient],
1621+
logged_user: dict,
1622+
shared_project: dict,
1623+
expected: ExpectedResponse,
1624+
exit_stack: contextlib.AsyncExitStack,
1625+
create_socketio_connection_with_handlers: Callable[
1626+
[TestClient], Awaitable[tuple[socketio.AsyncClient, str, _SocketHandlers]]
1627+
],
1628+
mocked_dynamic_services_interface: dict[str, mock.Mock],
1629+
mock_catalog_api: dict[str, mock.Mock],
1630+
):
1631+
# This test is a simplified version of the test_open_shared_project_multiple_users
1632+
# It only tests refreshing the tab of an already opened project
1633+
base_client = client
1634+
(
1635+
sio_base,
1636+
base_client_tab_id,
1637+
sio_base_handlers,
1638+
) = await create_socketio_connection_with_handlers(base_client)
1639+
1640+
# current state is closed and unlocked
1641+
closed_project_state = ProjectStateOutputSchema(
1642+
share_state=ProjectShareStateOutputSchema(
1643+
locked=False, status=ProjectStatus.CLOSED, current_user_groupids=[]
1644+
),
1645+
state=ProjectRunningState(value=RunningState.NOT_STARTED),
1646+
)
1647+
await _state_project(
1648+
base_client, shared_project, HTTPStatus.OK, closed_project_state
1649+
)
1650+
1651+
# now user opens the shared project
1652+
await _open_project(base_client, base_client_tab_id, shared_project, expected.ok)
1653+
opened_project_state = closed_project_state.model_copy(
1654+
update={
1655+
"share_state": ProjectShareStateOutputSchema(
1656+
locked=True,
1657+
status=ProjectStatus.OPENED,
1658+
current_user_groupids=[logged_user["primary_gid"]],
1659+
),
1660+
}
1661+
)
1662+
await _assert_project_state_updated(
1663+
sio_base_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1664+
shared_project,
1665+
[opened_project_state] * 2,
1666+
)
1667+
await _state_project(
1668+
base_client, shared_project, HTTPStatus.OK, opened_project_state
1669+
)
1670+
1671+
#
1672+
# TEST refreshing tab of some user shall work
1673+
#
1674+
# refreshing_user_index = secrets.randbelow(len(other_users))
1675+
# user_x, client_x, _, closed_sio_x, _ = other_users.pop(refreshing_user_index)
1676+
# # close tab of user x
1677+
# await closed_sio_x.disconnect()
1678+
# await asyncio.sleep(5) # wait for the disconnect to be processed
1679+
# (
1680+
# new_sio_x,
1681+
# new_client_x_tab_id,
1682+
# new_sio_x_handlers,
1683+
# ) = await create_socketio_connection_with_handlers(client_x)
1684+
# await _assert_project_state_updated(
1685+
# new_sio_x_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1686+
# shared_project,
1687+
# [],
1688+
# )
1689+
1690+
# await _open_project(client_x, new_client_x_tab_id, shared_project, expected.ok)
1691+
1692+
# await _assert_project_state_updated(
1693+
# new_sio_x_handlers[SOCKET_IO_PROJECT_UPDATED_EVENT],
1694+
# shared_project,
1695+
# [opened_project_state],
1696+
# )
1697+
1698+
# # put back the refreshed user in the list of other users
1699+
# other_users.append(
1700+
# (user_x, client_x, new_client_x_tab_id, new_sio_x, new_sio_x_handlers)
1701+
# )
1702+
1703+
16461704
@pytest.mark.parametrize(*standard_user_role_response())
16471705
async def test_open_shared_project_2_users_locked_remove_once_rtc_collaboration_is_defaulted(
16481706
client: TestClient,

0 commit comments

Comments
 (0)