def test_push(self): target = "dddd" content = "gggg" notice = Notice.push(self.user, self.notice_type, target, content) notice1 = Notice.push(self.user, self.notice_type, target, content) self.assertEqual(notice, notice1) notice.delete()
def test_home(self): notice = Notice.push(user=self.user, notice_type=self.notice_type, target="http://www.baidu.com", content=u"ggg") url = reverse("notification.views.home") resp = self.client.get(url) self.assertEqual(resp.status_code, 200) notice.delete()
def test_unread(self): notice = Notice.push(self.user, self.notice_type, "http://www.baidu.com", "ffgg") notices = Notice.objects.unread(self.user, NoticeSetting.DEVICE_WEB) self.assertEqual(len(notices), 1) notice.delete()
def test_update_notice(self): notice = Notice.push(user=self.user, notice_type=self.notice_type, target="11", content=u"ggg", reminder_value=1) views.update_notice(notice) result = notice.reminder_value self.assertEqual(result, 2, "update_notice_above run fail") notice.delete()
def test_initialize_notice(self): notice = Notice.push(user=self.user, notice_type=self.notice_type, target="11", content=u"ggg") views.initialize_notice(notice) result = int(time.mktime(notice.last_reminder_time.timetuple())) except_result = int(time.mktime(datetime.datetime.now().timetuple())) self.assertEqual(result, except_result, "initialize_notice run fail") notice.delete()
def test_update_notice_below(self): """test update_notice_above, normal operation, the reminder_value is below 365, noting unusual """ notice = Notice.push(user=self.user, notice_type=self.notice_type, target="11", content=u"ggg", reminder_value=1) views.update_notice(notice) result = notice.reminder_value self.assertEqual(result, 2, "update_notice_below run fail") notice.delete()
def test_unread_and_unsend_with_sent(self): notice = Notice.push(self.user, self.notice_type, "http://www.baidu.com", "ffgg", sent_device=2) notices = Notice.objects.unread_and_unsend(self.user, NoticeSetting.DEVICE_WEB) self.assertEqual(len(notices), 1) notices = Notice.objects.unread_and_unsend(self.user, NoticeSetting.DEVICE_EMAIL) self.assertEqual(len(notices), 0) notice.delete()
def test_get_reminder_flag(self): """test get_reminder_flag, normal operation, the last_reminder_time is not None, noting unusual """ notice = Notice.push(user=self.user, notice_type=self.notice_type, target="http://www.baidu.com", content=u"ggg", last_reminder_time=datetime.datetime.now()) result = views.get_reminder_flag(notice, 3600*24) except_result = 1 self.assertEqual(result, except_result, "get_reminder_flag run fail") notice.delete()
def test_go(self): notice = Notice.push(user=self.user, notice_type=self.notice_type, target="http://www.baidu.com", content=u"ggg") url = reverse("notification.views.go", args=[notice.id]) resp = self.client.get(url) self.assertEqual(resp.status_code, 302) notice.delete()
def test_get_reasons(self): notices = [] notice = Notice.push(user=self.user, notice_type=self.notice_type, target="9", content=u"ggg",add_datetime='2013-10-28 15:48:18') notices.append(notice) init_reasons = [] result = views.get_reasons(init_reasons, notices) except_result = [u"<span class='text-muted'>2013-10-28 15:48:18</span> <a href='/notification/go/9/' target='_blank'>ggg</a>"] self.assertEqual(result, except_result,"get_reasons run fail") notice.delete()
def test_clear(self): notice = Notice.push(user=self.user, notice_type=self.notice_type, target="http://www.baidu.com", content=u"ggg") url = reverse("notification.views.clear") resp = self.client.get(url) self.assertEqual(resp.status_code, 200) notices = Notice.objects.unread_of_email(self.user) self.assertEqual(len(notices), 0) notice.delete()
def test_my(self): notice = Notice.push(user=self.user, notice_type=self.notice_type, target="http://www.baidu.com", content=u"ggg") url = reverse("notification.views.my") resp = self.client.get(url) self.assertEqual(resp.status_code, 200) result = simplejson.loads(resp.content) self.assertTrue(result["is_ok"]) notice.delete()
def test_send_to_email(self): target = "dddd" content = "gggg" self.notice_type.flags = 3 self.notice_type.save() notice = Notice.push(self.user, self.notice_type, target, content) Notice.send_to_email(self.user) new_notice = Notice.objects.get(id=notice.id) self.assertEqual(new_notice.sent_device, 2) self.notice_type.flags = 1 self.notice_type.save() notice.delete()
def message_created(sender, instance, created, **kwargs): '''Notify the recipient that a new private message has been received.''' if created: target = reverse('ppmsg.views.view_detail', args=(instance.sender.username,)) notice_type = NoticeType.create(label="private message", display=u"新私信", description=u"新私信") Notice.push(user=instance.recipient, notice_type=notice_type, target=target, content=instance.sender.username + u"给您发来新的私信")
def test_unread_with_read(self): notice = Notice.push(self.user, self.notice_type, "http://www.baidu.com", "ffgg", is_read=True) notices = Notice.objects.unread(self.user, NoticeSetting.DEVICE_WEB) self.assertEqual(len(notices), 0) notice.delete()
def test_notice_is_could_send(self): notice = Notice.push(self.user, self.notice_type, "http://www.baidu.com", "ffgg") self.assertTrue(notice.is_could_send(NoticeSetting.DEVICE_WEB)) notice.delete()