def testGetSetImage(self): in_blob = testutils.Resource("icon.png") interface.SetImage(1, in_blob) out_blob = interface.GetImage(1) self.assertEqual(in_blob, out_blob) with self.assertRaises(ValueError): interface.SetImage(1, testutils.Resource("icon_toobig.png")) with self.assertRaises(ValueError): interface.SetImage(1, testutils.Resource("intro.aac"))
def testHistory(self): audio = testutils.Resource("intro.aac") now = datetime.datetime.today() r1 = interface.SendRose(1, 2, 1, now=now + datetime.timedelta(1)) r2 = interface.SendRose(3, 1, 1, now=now + datetime.timedelta(2)) interface.SendMessage(1, 4, audio, now=now + datetime.timedelta(3)) interface.SendMessage(5, 1, audio, now=now + datetime.timedelta(4)) by_last_incoming = interface.History(1) by_last_sent_rose = interface.History(1, sent_rose_only=True) by_last_received_rose = interface.History(1, received_rose_only=True) by_last_sent_message = interface.History(1, sent_message_only=True) by_last_received_message = interface.History( 1, received_message_only=True)
def testSendMessageAndGetMessageFile(self): now = datetime.datetime.today() in_blob = testutils.Resource("intro.aac") interface.SendMessage(1, 2, in_blob, now=now) # Retrieve without marking the message as listened to out_blob = interface.GetMessageFile(1, 2, now, False) self.assertEqual(in_blob, out_blob) sender_rel = interface.Relationship(1, 2) recip_rel = interface.Relationship(2, 1) sent_msg = interface.GetForRelationship(model.SentMessage, 1, 2, now) rcvd_msg = interface.GetForRelationship(model.ReceivedMessage, 2, 1, now) self.assertEqual(now, sender_rel.last_sent_message) self.assertEqual(now, recip_rel.last_received_message) self.assertEqual(1, recip_rel.new_messages) self.assertEqual(True, sent_msg.new) self.assertEqual(True, rcvd_msg.new) self.assertEqual([], sent_msg.retrieved) self.assertEqual([], rcvd_msg.retrieved) # Retrieve again, this time marking it as listened now2 = now + datetime.timedelta(days=1) interface.GetMessageFile(1, 2, now, True, now=now2) recip_rel = interface.Relationship(2, 1) sent_msg = interface.GetForRelationship(model.SentMessage, 1, 2, now) rcvd_msg = interface.GetForRelationship(model.ReceivedMessage, 2, 1, now) self.assertEqual(0, recip_rel.new_messages) self.assertEqual(False, sent_msg.new) self.assertEqual(False, rcvd_msg.new) self.assertEqual([now2], sent_msg.retrieved) self.assertEqual([now2], rcvd_msg.retrieved) # Retrieve and mark as listened once more, ensure retrievals count up and # affect on number of new messages is idempotent now3 = now + datetime.timedelta(days=2) interface.GetMessageFile(1, 2, now, True, now=now3) recip_rel = interface.Relationship(2, 1) sent_msg = interface.GetForRelationship(model.SentMessage, 1, 2, now) rcvd_msg = interface.GetForRelationship(model.ReceivedMessage, 2, 1, now) self.assertEqual(0, recip_rel.new_messages) self.assertEqual(False, sent_msg.new) self.assertEqual(False, rcvd_msg.new) self.assertEqual([now2, now3], sent_msg.retrieved) self.assertEqual([now2, now3], rcvd_msg.retrieved)
def testSetImage(self): img = testutils.Resource("icon.png") self.api.Call("/account/set_image", blob=common.Encode(img)) out_img = interface.GetForUid(model.ImageFile, testutils.DEFAULT_UID).blob self.assertEqual(img, out_img)
def testSetIntro(self): audio = testutils.Resource("intro.aac") self.api.Call("/account/set_intro", blob=common.Encode(audio)) out_audio = interface.GetForUid(model.IntroFile, testutils.DEFAULT_UID).blob self.assertEqual(audio, out_audio)