forked from ITISFoundation/osparc-simcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ subscribe to socketio room based on the user_id (ITISFoundation#5270)
Co-authored-by: Andrei Neagu <[email protected]>
- Loading branch information
Showing
8 changed files
with
78 additions
and
43 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/models-library/src/models_library/api_schemas_webserver/socketio.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from ..users import GroupID, UserID | ||
|
||
|
||
class SocketIORoom(str): | ||
__slots__ = () | ||
|
||
@classmethod | ||
def from_socket_id(cls, socket_id: str) -> "SocketIORoom": | ||
return cls(socket_id) | ||
|
||
@classmethod | ||
def from_group_id(cls, group_id: GroupID) -> "SocketIORoom": | ||
return cls(f"group:{group_id}") | ||
|
||
@classmethod | ||
def from_user_id(cls, user_id: UserID) -> "SocketIORoom": | ||
return cls(f"user:{user_id}") |
27 changes: 27 additions & 0 deletions
27
packages/models-library/tests/test_api_schemas_webserver_socketio.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# pylint:disable=redefined-outer-name | ||
|
||
import pytest | ||
from faker import Faker | ||
from models_library.api_schemas_webserver.socketio import SocketIORoom | ||
from models_library.users import GroupID, UserID | ||
|
||
|
||
@pytest.fixture | ||
def user_id(faker: Faker) -> UserID: | ||
return UserID(faker.pyint()) | ||
|
||
|
||
@pytest.fixture | ||
def group_id(faker: Faker) -> GroupID: | ||
return GroupID(faker.pyint()) | ||
|
||
|
||
@pytest.fixture | ||
def socket_id(faker: Faker) -> str: | ||
return faker.pystr() | ||
|
||
|
||
def test_socketio_room(user_id: UserID, group_id: GroupID, socket_id: str): | ||
assert SocketIORoom.from_user_id(user_id) == f"user:{user_id}" | ||
assert SocketIORoom.from_group_id(group_id) == f"group:{group_id}" | ||
assert SocketIORoom.from_socket_id(socket_id) == socket_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters