Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
drafts: Change "timestamp" from float to integer.
Hemanth V. Allurie60925b3e84c
diff --git a/zerver/models.py b/zerver/models.pyindex a955f9dba88..075c6c7321f 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -1936,7 +1936,7 @@ class Draft(models.Model):def __str__(self) -> str:return f"<{self.__class__.__name__}: {self.user_profile.email} / {self.id} / {self.last_edit_time}>"- def to_dict(self) -> Dict[str, Any]: # nocoverage # Will be added in a later commit.+ def to_dict(self) -> Dict[str, Any]:if self.recipient is None:_type = ""to = []@@ -1958,7 +1958,7 @@ class Draft(models.Model):"to": to,"topic": self.topic,"content": self.content,- "timestamp": self.last_edit_time.timestamp(),+ "timestamp": int(self.last_edit_time.timestamp()),}class AbstractReaction(models.Model):diff --git a/zerver/tests/test_drafts.py b/zerver/tests/test_drafts.pyindex 19e65ea1d3d..0e99a2c2c18 100644--- a/zerver/tests/test_drafts.py+++ b/zerver/tests/test_drafts.py@@ -53,14 +53,14 @@ class DraftCreationTests(ZulipTestCase):"to": [visible_stream_id],"topic": "sync drafts","content": "Let's add backend support for syncing drafts.",- "timestamp": 1595479019.4391587,+ "timestamp": 1595479019,}]expected_draft_dicts = [{"type": "stream","to": [visible_stream_id],"topic": "sync drafts","content": "Let's add backend support for syncing drafts.",- "timestamp": 1595479019.439159, # We only go as far microseconds.+ "timestamp": 1595479019, # We only go as far seconds and drop any extra precision.}]self.create_and_check_drafts_for_success(draft_dicts, expected_draft_dicts)@@ -71,14 +71,14 @@ class DraftCreationTests(ZulipTestCase):"to": [zoe.id],"topic": "This topic should be ignored.","content": "What if we made it possible to sync drafts in Zulip?",- "timestamp": 1595479019.43915,+ "timestamp": 1595479019,}]expected_draft_dicts = [{"type": "private","to": [zoe.id],"topic": "", # For private messages the topic should be ignored."content": "What if we made it possible to sync drafts in Zulip?",- "timestamp": 1595479019.43915,+ "timestamp": 1595479019,}]self.create_and_check_drafts_for_success(draft_dicts, expected_draft_dicts)@@ -97,7 +97,7 @@ class DraftCreationTests(ZulipTestCase):"to": [zoe.id, othello.id],"topic": "", # For private messages the topic should be ignored."content": "What if we made it possible to sync drafts in Zulip?",- "timestamp": 1595479019.0,+ "timestamp": 1595479019,}]self.create_and_check_drafts_for_success(draft_dicts, expected_draft_dicts)@@ -113,21 +113,21 @@ class DraftCreationTests(ZulipTestCase):"to": [visible_stream_id],"topic": "sync drafts","content": "Let's add backend support for syncing drafts.",- "timestamp": 1595479019.43915,+ "timestamp": 1595479019,}, # Stream message draft{"type": "private","to": [zoe.id],"topic": "This topic should be ignored.","content": "What if we made it possible to sync drafts in Zulip?",- "timestamp": 1595479020.43916,+ "timestamp": 1595479020,}, # Private message draft{"type": "private","to": [zoe.id, othello.id],"topic": "","content": "What if we made it possible to sync drafts in Zulip?",- "timestamp": 1595479021.43916,+ "timestamp": 1595479021,}, # Private group message draft]expected_draft_dicts = [@@ -136,21 +136,21 @@ class DraftCreationTests(ZulipTestCase):"to": [visible_stream_id],"topic": "sync drafts","content": "Let's add backend support for syncing drafts.",- "timestamp": 1595479019.43915,+ "timestamp": 1595479019,},{"type": "private","to": [zoe.id],"topic": "","content": "What if we made it possible to sync drafts in Zulip?",- "timestamp": 1595479020.43916,+ "timestamp": 1595479020,},{"type": "private","to": [zoe.id, othello.id],"topic": "","content": "What if we made it possible to sync drafts in Zulip?",- "timestamp": 1595479021.43916,+ "timestamp": 1595479021,}]self.create_and_check_drafts_for_success(draft_dicts, expected_draft_dicts)@@ -171,7 +171,7 @@ class DraftCreationTests(ZulipTestCase):self.assertEqual(Draft.objects.count(), 0)- current_time = round(time.time(), 6)+ current_time = int(time.time())payload = {"drafts": orjson.dumps(draft_dicts).decode()}resp = self.api_post(hamlet, "/api/v1/drafts", payload)self.assert_json_success(resp)@@ -179,10 +179,10 @@ class DraftCreationTests(ZulipTestCase):new_drafts = Draft.objects.all()self.assertEqual(Draft.objects.count(), 1)new_draft = new_drafts[0].to_dict()- self.assertTrue(isinstance(new_draft["timestamp"], float))+ self.assertTrue(isinstance(new_draft["timestamp"], int))# Since it would be too tricky to get the same times, perform# a relative check.- self.assertTrue(new_draft["timestamp"] > current_time)+ self.assertTrue(new_draft["timestamp"] >= current_time)def test_invalid_timestamp(self) -> None:draft_dicts = [{@@ -205,14 +205,14 @@ class DraftCreationTests(ZulipTestCase):"to": [],"topic": "sync drafts","content": "Let's add backend support for syncing drafts.",- "timestamp": 1595479019.43915,+ "timestamp": 1595479019,},{"type": "","to": [],"topic": "sync drafts","content": "Let's add backend support for syncing drafts.",- "timestamp": 1595479019.43915,+ "timestamp": 1595479019,},]expected_draft_dicts = [@@ -221,14 +221,14 @@ class DraftCreationTests(ZulipTestCase):"to": [],"topic": "","content": "Let's add backend support for syncing drafts.",- "timestamp": 1595479019.43915,+ "timestamp": 1595479019,},{"type": "","to": [],"topic": "","content": "Let's add backend support for syncing drafts.",- "timestamp": 1595479019.43915,+ "timestamp": 1595479019,},]self.create_and_check_drafts_for_success(draft_dicts, expected_draft_dicts)@@ -239,7 +239,7 @@ class DraftCreationTests(ZulipTestCase):"to": [],"topic": "sync drafts","content": "Let's add backend support for syncing drafts.",- "timestamp": 1595479019.439159,+ "timestamp": 15954790199,}]self.create_and_check_drafts_for_error(draft_dicts,@@ -254,7 +254,7 @@ class DraftCreationTests(ZulipTestCase):"to": [stream.id], # This can't be accessed by hamlet."topic": "sync drafts","content": "Let's add backend support for syncing drafts.",- "timestamp": 1595479019.43915,+ "timestamp": 1595479019,}]self.create_and_check_drafts_for_error(draft_dicts, "Invalid stream id")@@ -264,7 +264,7 @@ class DraftCreationTests(ZulipTestCase):"to": [99999999999999], # Hopefully, this doesn't exist."topic": "sync drafts","content": "Let's add backend support for syncing drafts.",- "timestamp": 1595479019.43915,+ "timestamp": 1595479019,}]self.create_and_check_drafts_for_error(draft_dicts, "Invalid stream id")@@ -274,7 +274,7 @@ class DraftCreationTests(ZulipTestCase):"to": [99999999999999], # Hopefully, this doesn't exist either."topic": "This topic should be ignored.","content": "What if we made it possible to sync drafts in Zulip?",- "timestamp": 1595479019.43915,+ "timestamp": 1595479019,}]self.create_and_check_drafts_for_error(draft_dicts, "Invalid user ID 99999999999999")@@ -284,7 +284,7 @@ class DraftCreationTests(ZulipTestCase):"to": [],"topic": "sync drafts.","content": "Some regular \x00 content here",- "timestamp": 1595479019.439159,+ "timestamp": 15954790199,}]self.create_and_check_drafts_for_error(draft_dicts,@@ -296,7 +296,7 @@ class DraftCreationTests(ZulipTestCase):"to": [10],"topic": "thinking about \x00","content": "Let's add backend support for syncing drafts.",- "timestamp": 1595479019.439159,+ "timestamp": 15954790199,}]self.create_and_check_drafts_for_error(draft_dicts,@@ -319,7 +319,7 @@ class DraftEditTests(ZulipTestCase):"to": [stream_a],"topic": "drafts","content": "The API should be good",- "timestamp": 1595505700.85247+ "timestamp": 1595505700}resp = self.api_post(hamlet, "/api/v1/drafts", {"drafts": orjson.dumps([draft_dict]).decode()})self.assert_json_success(resp)@@ -329,7 +329,7 @@ class DraftEditTests(ZulipTestCase):draft_dict["content"] = "The API needs to be structured yet simple to use."draft_dict["to"] = [stream_b]draft_dict["topic"] = "designing drafts"- draft_dict["timestamp"] = 1595505800.84923+ draft_dict["timestamp"] = 1595505800# Update this change in the backend.resp = self.api_patch(hamlet, f"/api/v1/drafts/{new_draft_id}",@@ -353,7 +353,7 @@ class DraftEditTests(ZulipTestCase):"to": [10],"topic": "drafts","content": "The API should be good",- "timestamp": 1595505700.85247+ "timestamp": 1595505700}resp = self.api_patch(hamlet, "/api/v1/drafts/999999999",{"draft": orjson.dumps(draft_dict).decode()})@@ -376,7 +376,7 @@ class DraftEditTests(ZulipTestCase):"to": [stream_id],"topic": "drafts","content": "The API should be good",- "timestamp": 1595505700.85247+ "timestamp": 1595505700}resp = self.api_post(hamlet, "/api/v1/drafts", {"drafts": orjson.dumps([draft_dict]).decode()})self.assert_json_success(resp)@@ -412,7 +412,7 @@ class DraftDeleteTests(ZulipTestCase):"to": [stream_id],"topic": "drafts","content": "The API should be good",- "timestamp": 1595505700.85247+ "timestamp": 1595505700}resp = self.api_post(hamlet, "/api/v1/drafts", {"drafts": orjson.dumps([draft_dict]).decode()})self.assert_json_success(resp)@@ -455,7 +455,7 @@ class DraftDeleteTests(ZulipTestCase):"to": [stream_id],"topic": "drafts","content": "The API should be good",- "timestamp": 1595505700.85247+ "timestamp": 1595505700}resp = self.api_post(hamlet, "/api/v1/drafts", {"drafts": orjson.dumps([draft_dict]).decode()})self.assert_json_success(resp)@@ -488,21 +488,21 @@ class DraftFetchTest(ZulipTestCase):"to": [visible_stream_id],"topic": "thinking out loud","content": "What if pigs really could fly?",- "timestamp": 1595479019.439159,+ "timestamp": 15954790199,},{"type": "private","to": [zoe.id],"topic": "","content": "What if made it possible to sync drafts in Zulip?",- "timestamp": 1595479020.439160,+ "timestamp": 1595479020,},{"type": "private","to": [zoe.id, othello.id],"topic": "","content": "What if made it possible to sync drafts in Zulip?",- "timestamp": 1595479021.439161,+ "timestamp": 1595479021,},]payload = {"drafts": orjson.dumps(draft_dicts).decode()}@@ -517,7 +517,7 @@ class DraftFetchTest(ZulipTestCase):"to": [hamlet.id],"topic": "","content": "Hello there!",- "timestamp": 1595479019.439159,+ "timestamp": 15954790199,},]payload = {"drafts": orjson.dumps(zoe_draft_dicts).decode()}