示例#1
0
    def test_delete_messages(self):
        node = orm.Node("b")
        old_messages = self.messages.get_messages(node)
        self.messages.delete_messages(node)
        new_messages = self.messages.get_messages(node)

        self.assertEqual(len(old_messages), 2)
        self.assertEqual(len(new_messages), 0)
示例#2
0
 def test_get_messages_limit_offset(self):
     node = orm.Node("c")
     messages = self.messages.get_messages(node, limit=3, offset=1)
     self.assertEqual(len(messages), 2)
     self.assertEqual(messages[0].node_id, node.node_id)
     self.assertEqual(messages[0].text, "message2 c from me")
     self.assertFalse(messages[0].to_me)
     self.assertEqual(messages[0].timestamp, 5000)
示例#3
0
    def test_set_node_unread_to_zero(self):
        node = orm.Node("b")
        self.nodes.set_node_unread_to_zero(node)
        self._cursor.execute("SELECT unread_count FROM Nodes WHERE node_id=?",
                             (node.node_id, ))

        unread_count, = self._cursor.fetchone()
        self.assertEqual(node.unread_count, 0)
        self.assertEqual(unread_count, 0)
示例#4
0
    def test_increment_unread_count(self):
        node = orm.Node("a")
        self.nodes.increment_node_unread(node)
        self._cursor.execute("SELECT unread_count FROM Nodes WHERE node_id=?",
                             (node.node_id, ))

        unread_count, = self._cursor.fetchone()
        self.assertEqual(node.unread_count, 1)
        self.assertEqual(unread_count, 1)
示例#5
0
    def test_get_messages_limit_none_offset_none(self):
        node = orm.Node("c")
        messages = self.messages.get_messages(node)

        self.assertEqual(len(messages), 3)
        self.assertEqual(messages[0].node_id, node.node_id)
        self.assertEqual(messages[0].text, "message1 c from me")
        self.assertFalse(messages[0].to_me)
        self.assertEqual(messages[0].timestamp, 1000)
示例#6
0
    def test_update_node_activity(self):
        delta = 2
        node = orm.Node("a")
        self.nodes.update_node_activity(node)
        self._cursor.execute("SELECT last_activity FROM Nodes WHERE node_id=?",
                             (node.node_id, ))

        last_activity_db, = self._cursor.fetchone()
        curr_time = time.time()

        self.assertLessEqual(curr_time - last_activity_db, delta)
        self.assertLessEqual(curr_time - node.last_activity, delta)
示例#7
0
 def test_delete_node(self):
     node = orm.Node("a")
     self.nodes.delete_node(node)
     self.assertFalse(self.nodes.check_node_exists(node))
示例#8
0
 def test_add_node_failed(self):
     node = orm.Node("c")
     with self.assertRaises(orm.NodeAlreadyExistsError):
         self.nodes.add_node(node)
示例#9
0
 def test_add_node(self):
     node = orm.Node("e")
     self.nodes.add_node(node)
     self.assertTrue(self.nodes.check_node_exists(node))
示例#10
0
 def test_check_node_exists_false(self):
     node = orm.Node("d")
     node_exists = self.nodes.check_node_exists(node)
     self.assertFalse(node_exists)
示例#11
0
 def test_check_node_exists_true(self):
     node = orm.Node("b")
     node_exists = self.nodes.check_node_exists(node)
     self.assertTrue(node_exists)
示例#12
0
 def test_update_node_activity_failed(self):
     node = orm.Node("not_found_node")
     with self.assertRaises(orm.NodeNotFoundError):
         self.nodes.update_node_activity(node)
示例#13
0
 def test_get_messages_limit(self):
     node = orm.Node("c")
     messages = self.messages.get_messages(node, limit=2)
     self.assertEqual(len(messages), 2)