mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
Add tests for our event queues data structure.
(imported from commit 5c00251998d25cf2283737173e5af0b26ccbdad4)
This commit is contained in:
@@ -2476,6 +2476,103 @@ class POSTRequestMock(object):
|
|||||||
self.session = DummySession()
|
self.session = DummySession()
|
||||||
self.META = {'PATH_INFO': 'test'}
|
self.META = {'PATH_INFO': 'test'}
|
||||||
|
|
||||||
|
from zerver.lib.event_queue import EventQueue
|
||||||
|
class EventQueueTest(TestCase):
|
||||||
|
def test_one_event(self):
|
||||||
|
queue = EventQueue("1")
|
||||||
|
queue.push({"type": "pointer",
|
||||||
|
"pointer": 1,
|
||||||
|
"timestamp": "1"})
|
||||||
|
self.assertEqual(queue.contents(),
|
||||||
|
[{'id': 0,
|
||||||
|
'type': 'pointer',
|
||||||
|
"pointer": 1,
|
||||||
|
"timestamp": "1"}])
|
||||||
|
|
||||||
|
def test_event_collapsing(self):
|
||||||
|
queue = EventQueue("1")
|
||||||
|
for pointer_val in xrange(1, 10):
|
||||||
|
queue.push({"type": "pointer",
|
||||||
|
"pointer": pointer_val,
|
||||||
|
"timestamp": str(pointer_val)})
|
||||||
|
self.assertEqual(queue.contents(),
|
||||||
|
[{'id': 8,
|
||||||
|
'type': 'pointer',
|
||||||
|
"pointer": 9,
|
||||||
|
"timestamp": "9"}])
|
||||||
|
|
||||||
|
queue = EventQueue("2")
|
||||||
|
for pointer_val in xrange(1, 10):
|
||||||
|
queue.push({"type": "pointer",
|
||||||
|
"pointer": pointer_val,
|
||||||
|
"timestamp": str(pointer_val)})
|
||||||
|
queue.push({"type": "unknown"})
|
||||||
|
for pointer_val in xrange(11, 20):
|
||||||
|
queue.push({"type": "pointer",
|
||||||
|
"pointer": pointer_val,
|
||||||
|
"timestamp": str(pointer_val)})
|
||||||
|
self.assertEqual(queue.contents(),
|
||||||
|
[{"type": "unknown",
|
||||||
|
"id": 9,},
|
||||||
|
{'id': 18,
|
||||||
|
'type': 'pointer',
|
||||||
|
"pointer": 19,
|
||||||
|
"timestamp": "19"}])
|
||||||
|
for pointer_val in xrange(21, 23):
|
||||||
|
queue.push({"type": "pointer",
|
||||||
|
"pointer": pointer_val,
|
||||||
|
"timestamp": str(pointer_val)})
|
||||||
|
self.assertEqual(queue.contents(),
|
||||||
|
[{"type": "unknown",
|
||||||
|
"id": 9,},
|
||||||
|
{'id': 18,
|
||||||
|
'type': 'pointer',
|
||||||
|
"pointer": 19,
|
||||||
|
"timestamp": "19"},
|
||||||
|
{'id': 20,
|
||||||
|
'type': 'pointer',
|
||||||
|
"pointer": 22,
|
||||||
|
"timestamp": "22"},])
|
||||||
|
|
||||||
|
def test_flag_collapsing(self):
|
||||||
|
queue = EventQueue("1")
|
||||||
|
queue.push({"type": "update_message_flags",
|
||||||
|
"flag": "read",
|
||||||
|
"operation": "add",
|
||||||
|
"all": False,
|
||||||
|
"messages": [1, 2, 3, 4],
|
||||||
|
"timestamp": "1"})
|
||||||
|
queue.push({"type": "update_message_flags",
|
||||||
|
"flag": "read",
|
||||||
|
"all": False,
|
||||||
|
"operation": "add",
|
||||||
|
"messages": [5, 6],
|
||||||
|
"timestamp": "1"})
|
||||||
|
self.assertEqual(queue.contents(),
|
||||||
|
[{'id': 1,
|
||||||
|
'type': 'update_message_flags',
|
||||||
|
"all": False,
|
||||||
|
"flag": "read",
|
||||||
|
"operation": "add",
|
||||||
|
"messages": [1,2,3,4,5,6],
|
||||||
|
"timestamp": "1"}])
|
||||||
|
|
||||||
|
def test_collapse_event(self):
|
||||||
|
queue = EventQueue("1")
|
||||||
|
queue.push({"type": "pointer",
|
||||||
|
"pointer": 1,
|
||||||
|
"timestamp": "1"})
|
||||||
|
queue.push({"type": "unknown",
|
||||||
|
"timestamp": "1"})
|
||||||
|
self.assertEqual(queue.contents(),
|
||||||
|
[{'id': 0,
|
||||||
|
'type': 'pointer',
|
||||||
|
"pointer": 1,
|
||||||
|
"timestamp": "1"},
|
||||||
|
{'id': 1,
|
||||||
|
'type': 'unknown',
|
||||||
|
"timestamp": "1"}])
|
||||||
|
|
||||||
class GetProfileTest(AuthedTestCase):
|
class GetProfileTest(AuthedTestCase):
|
||||||
|
|
||||||
def common_update_pointer(self, email, pointer):
|
def common_update_pointer(self, email, pointer):
|
||||||
|
|||||||
Reference in New Issue
Block a user