def test_check_callback_and_save(self):
# we ensure a user may by default not send more than 50 messages a day
Message.objects.filter(sender=self.participant1).count()
r = 100
for i in range(r):
try:
m = Message(sender=self.participant1, thread=self.thread1, body="hi")
m.save()
except Exception:
pass
# we have more than 50 messages (more in setUp)
self.assertEqual(50, Message.objects.filter(sender=self.participant1).count())
# the limit is only in the last 24 hours
Message.objects.filter(sender=self.participant1).update(sent_at=now() - timedelta(days=1, seconds=1))
last = Message.objects.filter(sender=self.participant1).latest('id')
new = Message.objects.create(sender=self.participant1, thread=self.thread1, body="hi")
self.assertEqual(new.id, last.id + 1)
评论列表
文章目录