Exemplo n.º 1
0
 def test_add_remove(self):
     state = self.state
     msg_id = uums.add_message_to_state('india', 'source_test_user', state, self.test_message)
     prenum = len(uums.get_messages_from_state(state))
     uums.remove_messages_from_state(state, [ msg_id ])
     msgs = uums.get_messages_from_state(state)
     assert len(msgs) == prenum - 1
Exemplo n.º 2
0
 def test_add_get(self):
     state = self.state
     prenum = len(uums.get_messages_from_state(state))
     msg_id = uums.add_message_to_state('india', 'source_test_user', state, self.test_message)
     msgs = uums.get_messages_from_state(state)
     assert len(msgs) == prenum + 1
     assert msgs[-1]['id'] == msg_id
Exemplo n.º 3
0
 def test_multi_add_remove(self):
     num = 50
     state = self.state
     msg_ids = []
     prenum = len(uums.get_messages_from_state(state))
     for i in range(num):
         msg_ids.append(uums.add_message_to_state('india', 'source_test_user_%i' % i, state, "%s_%i" % (self.test_message, i)))
     msgs = uums.get_messages_from_state(state)
     assert len(msgs) == prenum + num
     prenum = len(msgs)
     uums.remove_messages_from_state(state, msg_ids)
     msgs = uums.get_messages_from_state(state)
     assert len(msgs) == prenum - num
     for msg in msgs:
         assert msg['id'] not in msg_ids
Exemplo n.º 4
0
 def test_get_messages_from_empty_state(self):
     state = self.state
     assert 'uums' not in state
     assert uums.get_messages_from_state(state) == []
     assert 'uums' in state
     assert 'messages' in state['uums']
     assert state['uums']['messages'] == []
Exemplo n.º 5
0
 def test_random_multi_add_remove(self):
     for i in range(10):
         num = random.randint(50, 100)
         state = self.state
         msg_ids = []
         prenum = len(uums.get_messages_from_state(state))
         for i in range(num):
             msg_ids.append(uums.add_message_to_state('india', 'source_test_user_%i' % i, state, "%s_%i" % (self.test_message, i)))
         msgs = uums.get_messages_from_state(state)
         assert len(msgs) == prenum + num
         prenum = len(msgs)
         sample_num = random.randint(10, num - 10)
         to_remove = random.sample(msg_ids, sample_num)
         uums.remove_messages_from_state(state, to_remove)
         msgs = uums.get_messages_from_state(state)
         assert len(msgs) == prenum - len(to_remove), "%i != %i - %i" % (len(msgs), prenum, len(to_remove))
         for msg in msgs:
             assert msg['id'] not in to_remove
Exemplo n.º 6
0
 def test_multi_add_shuffled_one_by_one_remove(self):
     for i in range(10):
         num = 50
         state = self.state
         msg_ids = []
         prenum = len(uums.get_messages_from_state(state))
         for i in range(num):
             msg_ids.append(uums.add_message_to_state('india', 'source_test_user_%i' % i, state, "%s_%i" % (self.test_message, i)))
         msgs = uums.get_messages_from_state(state)
         assert len(msgs) == prenum + num
         prenum = len(msgs)
         random.shuffle(msg_ids)
         for msg_id in msg_ids:
             uums.remove_messages_from_state(state, [msg_id])
             msgs = uums.get_messages_from_state(state)
             for msg in msgs:
                 assert msg['id'] != msg_id
         msgs = uums.get_messages_from_state(state)
         assert len(msgs) == prenum - num
         for msg in msgs:
             assert msg['id'] not in msg_ids
Exemplo n.º 7
0
 def setup(self):
     self._state = {'user_id': 'test_user'}
     uums.get_messages_from_state(self.state)