Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify the dict representation of a message has an isoformatted timestamp #2355

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions tests/_test_mscolab/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,9 @@

from fs.tempfs import TempFS
from mslib.mscolab.conf import mscolab_settings
from mslib.mscolab.models import Operation, MessageType
from mslib.mscolab.models import Operation
from mslib.mscolab.seed import add_user, get_user
from mslib.mscolab.utils import (get_recent_op_id, get_session_id,
get_message_dict, create_files,
os_fs_create_dir)


class Message:
id = 1 # noqa: A003
u_id = 2

class user:
username = "name"
text = "Moin"
message_type = MessageType.TEXT
reply_id = 0
replies = []

class created_at:
@staticmethod
def isoformat():
pass
from mslib.mscolab.utils import get_recent_op_id, get_session_id, create_files, os_fs_create_dir


class Test_Utils:
Expand Down Expand Up @@ -79,10 +60,6 @@ def test_get_session_id(self):
sockets = [{"u_id": 5, "s_id": 100}]
assert get_session_id(sockets, 5) == 100

def test_get_message_dict(self):
result = get_message_dict(Message())
assert result["message_type"] == MessageType.TEXT

def test_os_fs_create_dir(self):
_fs = TempFS(identifier="msui")
_dir = _fs.getsyspath("")
Expand Down
8 changes: 7 additions & 1 deletion tests/_test_msui/test_mscolab_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
limitations under the License.
"""
import pytest
import datetime

from mslib.mscolab.conf import mscolab_settings
from mslib.mscolab.models import Message
from mslib.mscolab.models import Message, MessageType
from PyQt5 import QtCore, QtTest, QtWidgets
from mslib.msui import mscolab
from mslib.msui import msui
from mslib.mscolab.seed import add_user, get_user, add_operation, add_user_to_operation
from mslib.utils.config import modify_config_file
from mslib.mscolab.utils import get_message_dict


class Actions:
Expand Down Expand Up @@ -79,6 +81,10 @@ def test_send_message(self, qtbot):
self._send_message(qtbot, "**test message**")
with self.app.app_context():
assert Message.query.filter_by(text='**test message**').count() == 2
message = Message.query.filter_by(text='**test message**').first()
result = get_message_dict(message)
assert result["message_type"] == MessageType.TEXT
assert datetime.datetime.fromisoformat(result["time"]).year == datetime.datetime.now().year
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was missing for the isoformat change.

ReimarBauer marked this conversation as resolved.
Show resolved Hide resolved

def test_search_message(self, qtbot):
self._send_message(qtbot, "**test message**")
Expand Down