Skip to content

Commit

Permalink
update created_at for Changes and Messages
Browse files Browse the repository at this point in the history
improved tests
  • Loading branch information
ReimarBauer committed Feb 25, 2024
1 parent dd40e3d commit 20e47a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mslib/mscolab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 text: {self.text}, u_id: {self.u_id}, op_id: {self.op_id}>, message_type: {self.message_type}'
Expand All @@ -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()
7 changes: 7 additions & 0 deletions tests/_test_mscolab/test_files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
limitations under the License.
"""
from flask_testing import TestCase
import time
import os
import fs
import pytest
Expand Down Expand Up @@ -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():
Expand Down
8 changes: 7 additions & 1 deletion tests/_test_mscolab/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 20e47a8

Please sign in to comment.