diff --git a/mslib/mscolab/chat_manager.py b/mslib/mscolab/chat_manager.py index a5580c5af..2663cbaca 100644 --- a/mslib/mscolab/chat_manager.py +++ b/mslib/mscolab/chat_manager.py @@ -64,7 +64,7 @@ def get_messages(self, op_id, timestamp=None): if timestamp is None: timestamp = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc) else: - timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d, %H:%M:%S %z") + timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d, %H:%M:%S.%f %z") messages = Message.query \ .filter(Message.op_id == op_id) \ .filter(Message.reply_id.is_(None)) \ diff --git a/mslib/mscolab/file_manager.py b/mslib/mscolab/file_manager.py index 523e90e29..c4877dc97 100644 --- a/mslib/mscolab/file_manager.py +++ b/mslib/mscolab/file_manager.py @@ -399,7 +399,7 @@ def get_all_changes(self, op_id, user, named_version=False): 'comment': change.comment, 'version_name': change.version_name, 'username': change.user.username, - 'created_at': change.created_at.strftime("%Y-%m-%d, %H:%M:%S %z") + 'created_at': change.created_at.strftime("%Y-%m-%d, %H:%M:%S.%f %z") }, changes)) def get_change_content(self, ch_id, user): diff --git a/mslib/mscolab/server.py b/mslib/mscolab/server.py index 27803c0d0..a55694e66 100644 --- a/mslib/mscolab/server.py +++ b/mslib/mscolab/server.py @@ -369,7 +369,7 @@ def messages(): user = g.user op_id = request.args.get("op_id", request.form.get("op_id", None)) if fm.is_member(user.id, op_id): - timestamp = request.args.get("timestamp", request.form.get("timestamp", "1970-01-01, 00:00:00 +00:00")) + timestamp = request.args.get("timestamp", request.form.get("timestamp", "1970-01-01, 00:00:00.000000 +00:00")) chat_messages = cm.get_messages(op_id, timestamp) return jsonify({"messages": chat_messages}) return "False" diff --git a/mslib/mscolab/utils.py b/mslib/mscolab/utils.py index 98f6ae530..09626c178 100644 --- a/mslib/mscolab/utils.py +++ b/mslib/mscolab/utils.py @@ -55,7 +55,7 @@ def get_message_dict(message): "message_type": message.message_type, "reply_id": message.reply_id, "replies": [], - "time": message.created_at.strftime("%Y-%m-%d, %H:%M:%S %z") + "time": message.created_at.strftime("%Y-%m-%d, %H:%M:%S.%f %z") } diff --git a/mslib/msui/mscolab_chat.py b/mslib/msui/mscolab_chat.py index bcf765b23..ba3d1ea11 100644 --- a/mslib/msui/mscolab_chat.py +++ b/mslib/msui/mscolab_chat.py @@ -349,7 +349,8 @@ def load_all_messages(self): data = { "token": self.token, "op_id": self.op_id, - "timestamp": datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S %z") + "timestamp": datetime.datetime(1970, 1, 1, + tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z") } # returns an array of messages url = urljoin(self.mscolab_server_url, "messages") diff --git a/mslib/msui/mscolab_version_history.py b/mslib/msui/mscolab_version_history.py index 40175facf..9a083e91d 100644 --- a/mslib/msui/mscolab_version_history.py +++ b/mslib/msui/mscolab_version_history.py @@ -144,7 +144,7 @@ def load_all_changes(self): changes = json.loads(r.text)["changes"] self.changes.clear() for change in changes: - created_at = datetime.strptime(change["created_at"], "%Y-%m-%d, %H:%M:%S %z") + created_at = datetime.strptime(change["created_at"], "%Y-%m-%d, %H:%M:%S.%f %z") local_time = utc_to_local_datetime(created_at) date = local_time.strftime('%d/%m/%Y') time = local_time.strftime('%I:%M %p') diff --git a/tests/_test_mscolab/test_files_api.py b/tests/_test_mscolab/test_files_api.py index 748eb9382..497ad384a 100644 --- a/tests/_test_mscolab/test_files_api.py +++ b/tests/_test_mscolab/test_files_api.py @@ -24,7 +24,6 @@ See the License for the specific language governing permissions and limitations under the License. """ -import time import fs import pytest @@ -172,8 +171,6 @@ def test_get_all_changes(self): with self.app.test_client(): flight_path, operation = self._create_operation(flight_path="V11") assert self.fm.save_file(operation.id, "content1", self.user) - # we need to wait to get an updated created_at - time.sleep(1) assert self.fm.save_file(operation.id, "content2", self.user) all_changes = self.fm.get_all_changes(operation.id, self.user) # the newest change is on index 0, because it has a recent created_at time @@ -186,9 +183,7 @@ def test_get_change_content(self): with self.app.test_client(): flight_path, operation = self._create_operation(flight_path="V12", content='initial') assert self.fm.save_file(operation.id, "content1", self.user) - time.sleep(1) assert self.fm.save_file(operation.id, "content2", self.user) - time.sleep(1) assert self.fm.save_file(operation.id, "content3", self.user) all_changes = self.fm.get_all_changes(operation.id, self.user) previous_change = self.fm.get_change_content(all_changes[2]["id"], self.user) diff --git a/tests/_test_mscolab/test_server.py b/tests/_test_mscolab/test_server.py index a77d49fa5..ad22ee9d2 100644 --- a/tests/_test_mscolab/test_server.py +++ b/tests/_test_mscolab/test_server.py @@ -24,7 +24,6 @@ See the License for the specific language governing permissions and limitations under the License. """ -import time import pytest import json import io @@ -234,7 +233,6 @@ def test_get_all_changes(self): with self.app.test_client() as test_client: operation, token = self._create_operation(test_client, self.userdata) fm, user = self._save_content(operation, self.userdata) - time.sleep(1) fm.save_file(operation.id, "content2", user) # the newest change is on index 0, because it has a recent created_at time response = test_client.get('/get_all_changes', data={"token": token, @@ -252,8 +250,6 @@ def test_get_change_content(self): with self.app.test_client() as test_client: operation, token = self._create_operation(test_client, self.userdata) fm, user = self._save_content(operation, self.userdata) - # we need to wait to get an updated created_at - time.sleep(1) fm.save_file(operation.id, "content2", user) all_changes = fm.get_all_changes(operation.id, user) response = test_client.get('/get_change_content', data={"token": token, diff --git a/tests/_test_mscolab/test_sockets_manager.py b/tests/_test_mscolab/test_sockets_manager.py index 6ae9b3620..975f3fdbb 100644 --- a/tests/_test_mscolab/test_sockets_manager.py +++ b/tests/_test_mscolab/test_sockets_manager.py @@ -191,11 +191,12 @@ def test_get_messages(self): assert messages[0]["text"] == "message from 1" assert len(messages) == 2 assert messages[0]["u_id"] == self.user.id - timestamp = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S %z") + timestamp = datetime.datetime(1970, 1, 1, + tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z") messages = self.cm.get_messages(1, timestamp) assert len(messages) == 2 assert messages[0]["u_id"] == self.user.id - timestamp = datetime.datetime.now(tz=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S %z") + timestamp = datetime.datetime.now(tz=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z") messages = self.cm.get_messages(1, timestamp) assert len(messages) == 0 @@ -221,7 +222,8 @@ def test_get_messages_api(self): data = { "token": token, "op_id": self.operation.id, - "timestamp": datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S %z") + "timestamp": datetime.datetime(1970, 1, 1, + tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z") } # returns an array of messages url = urljoin(self.url, 'messages') @@ -257,7 +259,8 @@ def test_edit_message(self): data = { "token": token, "op_id": self.operation.id, - "timestamp": datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S %z") + "timestamp": datetime.datetime(1970, 1, 1, + tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z") } # returns an array of messages url = urljoin(self.url, 'messages')