diff --git a/mslib/mscolab/models.py b/mslib/mscolab/models.py index 3442fb681..a5286eb38 100644 --- a/mslib/mscolab/models.py +++ b/mslib/mscolab/models.py @@ -183,6 +183,7 @@ def __init__(self, op_id, u_id, text, message_type=MessageType.TEXT, reply_id=No self.text = text self.message_type = message_type self.reply_id = reply_id + self.created_at = datetime.datetime.utcnow() def __repr__(self): return f', message_type: {self.message_type}' @@ -206,3 +207,4 @@ def __init__(self, op_id, u_id, commit_hash, version_name=None, comment=None): self.commit_hash = commit_hash self.version_name = version_name self.comment = comment + self.created_at = datetime.datetime.utcnow() diff --git a/tests/_test_mscolab/test_files_api.py b/tests/_test_mscolab/test_files_api.py index 0aeb89473..d85deeff1 100644 --- a/tests/_test_mscolab/test_files_api.py +++ b/tests/_test_mscolab/test_files_api.py @@ -25,6 +25,7 @@ limitations under the License. """ from flask_testing import TestCase +import time import os import fs import pytest @@ -195,9 +196,15 @@ 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 assert len(all_changes) == 2 + assert all_changes[0]["id"] == 2 + assert all_changes[0]["id"] > all_changes[1]["id"] + assert all_changes[0]["created_at"] > all_changes[1]["created_at"] def test_get_change_content(self): with self.app.test_client(): diff --git a/tests/_test_mscolab/test_server.py b/tests/_test_mscolab/test_server.py index 63ddf4846..411536d90 100644 --- a/tests/_test_mscolab/test_server.py +++ b/tests/_test_mscolab/test_server.py @@ -24,7 +24,7 @@ See the License for the specific language governing permissions and limitations under the License. """ - +import time from flask_testing import TestCase import os import pytest @@ -244,13 +244,19 @@ 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) + # the newest change is on index 0, because it has a recent created_at time response = test_client.get('/get_change_content', data={"token": token, "ch_id": all_changes[1]["id"]}) assert response.status_code == 200 data = json.loads(response.data.decode('utf-8')) assert data == {'content': 'content1'} + assert all_changes[0]["id"] == 2 + assert all_changes[0]["id"] > all_changes[1]["id"] + assert all_changes[0]["created_at"] > all_changes[1]["created_at"] def test_set_version_name(self): assert add_user(self.userdata[0], self.userdata[1], self.userdata[2])