本文整理汇总了Python中autopush.db.Message类的典型用法代码示例。如果您正苦于以下问题:Python Message类的具体用法?Python Message怎么用?Python Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_register
def test_register(self):
chid = str(uuid.uuid4())
m = get_rotating_message_table()
message = Message(m, SinkMetrics())
message.register_channel(self.uaid, chid)
# Verify its in the db
rows = m.query_2(uaid__eq=self.uaid, chidmessageid__eq=" ")
results = list(rows)
assert len(results) == 1
示例2: test_message_delete_pagination
def test_message_delete_pagination(self):
def make_messages(channel_id, count):
m = []
t = self._nstime()
ttl = int(time.time()) + 200
for i in range(count):
m.append((self.uaid, channel_id, str(uuid.uuid4()), ttl, {}, t + i))
return m
chid = str(uuid.uuid4())
m = get_rotating_message_table()
message = Message(m, SinkMetrics())
message.register_channel(self.uaid, chid)
# Shove 80 messages in
for message_args in make_messages(chid, 80):
message.store_message(*message_args)
# Verify we can see them all
all_messages = list(message.fetch_messages(self.uaid, limit=100))
eq_(len(all_messages), 80)
# Delete them all
message.delete_messages_for_channel(self.uaid, chid)
# Verify they're gone
all_messages = list(message.fetch_messages(self.uaid, limit=100))
eq_(len(all_messages), 0)
示例3: test_update_message_fail
def test_update_message_fail(self):
message = Message(get_rotating_message_table(), SinkMetrics)
message.store_message(self.uaid, uuid.uuid4().hex, self._nstime(), str(uuid.uuid4()), {})
u = message.table.connection.update_item = Mock()
def raise_condition(*args, **kwargs):
raise ConditionalCheckFailedException(None, None)
u.side_effect = raise_condition
b = message.update_message(self.uaid, uuid.uuid4().hex, self._nstime(), str(uuid.uuid4()), {})
eq_(b, False)
示例4: test_message_delete_fail_condition
def test_message_delete_fail_condition(self):
m = get_rotating_message_table()
message = Message(m, SinkMetrics())
def raise_condition(*args, **kwargs):
raise ConditionalCheckFailedException(None, None)
message.table = Mock()
message.table.delete_item.side_effect = raise_condition
result = message.delete_message(uaid="asdf", channel_id="asdf", message_id="asdf", updateid="asdf")
eq_(result, False)
示例5: test_save_channels
def test_save_channels(self):
chid = str(uuid.uuid4())
chid2 = str(uuid.uuid4())
m = get_rotating_message_table()
message = Message(m, SinkMetrics())
message.register_channel(self.uaid, chid)
message.register_channel(self.uaid, chid2)
exists, chans = message.all_channels(self.uaid)
new_uaid = uuid.uuid4().hex
message.save_channels(new_uaid, chans)
_, new_chans = message.all_channels(new_uaid)
eq_(chans, new_chans)
示例6: test_unregister
def test_unregister(self):
chid = str(uuid.uuid4())
m = get_message_table()
message = Message(m, SinkMetrics())
message.register_channel(self.uaid, chid)
# Verify its in the db
rows = m.query_2(uaid__eq=self.uaid, chidmessageid__eq=" ")
results = list(rows)
assert(len(results) == 1)
eq_(results[0]["chids"], set([chid]))
message.unregister_channel(self.uaid, chid)
# Verify its not in the db
rows = m.query_2(uaid__eq=self.uaid, chidmessageid__eq=" ")
results = list(rows)
assert(len(results) == 1)
eq_(results[0]["chids"], set([]))
示例7: test_all_channels
def test_all_channels(self):
chid = str(uuid.uuid4())
chid2 = str(uuid.uuid4())
m = get_rotating_message_table()
message = Message(m, SinkMetrics())
message.register_channel(self.uaid, chid)
message.register_channel(self.uaid, chid2)
_, chans = message.all_channels(self.uaid)
assert chid in chans
assert chid2 in chans
message.unregister_channel(self.uaid, chid2)
_, chans = message.all_channels(self.uaid)
assert chid2 not in chans
assert chid in chans
示例8: test_unregister
def test_unregister(self):
chid = str(uuid.uuid4())
m = get_rotating_message_table()
message = Message(m, SinkMetrics())
message.register_channel(self.uaid, chid)
# Verify its in the db
rows = m.query_2(uaid__eq=self.uaid, chidmessageid__eq=" ")
results = list(rows)
assert len(results) == 1
eq_(results[0]["chids"], set([chid]))
message.unregister_channel(self.uaid, chid)
# Verify its not in the db
rows = m.query_2(uaid__eq=self.uaid, chidmessageid__eq=" ")
results = list(rows)
assert len(results) == 1
eq_(results[0]["chids"], set([]))
# Test for the very unlikely case that there's no 'chid'
m.connection.update_item = Mock()
m.connection.update_item.return_value = {"Attributes": {"uaid": {"S": self.uaid}}, "ConsumedCapacityUnits": 0.5}
r = message.unregister_channel(self.uaid, "test")
eq_(r, False)
示例9: test_update_message
def test_update_message(self):
chid = uuid.uuid4().hex
m = get_rotating_message_table()
message = Message(m, SinkMetrics())
data1 = str(uuid.uuid4())
data2 = str(uuid.uuid4())
time1 = self._nstime()
time2 = self._nstime() + 100
ttl = self._nstime() + 1000
message.store_message(self.uaid, chid, time1, ttl, data1, {})
message.update_message(self.uaid, chid, time2, ttl, data2, {})
messages = list(message.fetch_messages(self.uaid))
eq_(data2, messages[0]["#dd"])
示例10: test_delete_user
def test_delete_user(self):
chid = str(uuid.uuid4())
chid2 = str(uuid.uuid4())
m = get_rotating_message_table()
message = Message(m, SinkMetrics())
message.register_channel(self.uaid, chid)
message.register_channel(self.uaid, chid2)
data1 = str(uuid.uuid4())
data2 = str(uuid.uuid4())
ttl = int(time.time()) + 100
time1, time2, time3 = self._nstime(), self._nstime(), self._nstime() + 1
message.store_message(self.uaid, chid, time1, ttl, data1, {})
message.store_message(self.uaid, chid2, time2, ttl, data2, {})
message.store_message(self.uaid, chid2, time3, ttl, data1, {})
message.delete_user(self.uaid)
all_messages = list(message.fetch_messages(self.uaid))
eq_(len(all_messages), 0)
示例11: test_all_channels_no_uaid
def test_all_channels_no_uaid(self):
m = get_rotating_message_table()
message = Message(m, SinkMetrics())
exists, chans = message.all_channels("asdf")
assert chans == set([])
示例12: test_all_channels_no_uaid
def test_all_channels_no_uaid(self):
m = get_message_table()
message = Message(m, SinkMetrics())
assert(message.all_channels("asdf") == set([]))