def testReporterReminders(self): # backend for our connection backend = PersistantBackend.objects.create(slug='reindeer', title='santas sleigh') # create a reporter reporter = Reporter.objects.create(alias='santa') connection = reporter.connections.create(identity='northpole', backend=backend) now = datetime.datetime.now() # set our last seen to now connection.last_seen = now connection.save() # test that we have no expired reporters expired = Reminder.get_expired_reporters(now) # should be no expired just yet self.assertEquals(0, len(expired)) # now change our last seen to 31 days ago connection.last_seen = now - datetime.timedelta(31) connection.save() # we should have one expired reporter expired = Reminder.get_expired_reporters(now) self.assertEquals(1, len(expired)) # now mark that we've reminded this reporter expired_type = ReminderType.objects.get(pk=6) reminder = Reminder.objects.create(reporter=reporter, date=datetime.datetime.now(), type=expired_type) # make sure we no longer trigger a reminder expired = Reminder.get_expired_reporters(now) self.assertEquals(0, len(expired)) # finally, move the reminder so that it happened before the last time we # were seen, meaning it doesn't apply to this expiration reminder.date = connection.last_seen - datetime.timedelta(10) reminder.save() # we should need a reminder again expired = Reminder.get_expired_reporters(now) self.assertEquals(1, len(expired))
def check_expired_reporters(self): # get our reminder reminder_type = ReminderType.objects.get(pk=6) today = datetime.date.today() # get all our pending expired reporters for reporter in Reminder.get_expired_reporters(today): # look up the supervisors for this reporter sups = Reporter.objects.filter(location=reporter.location, groups__pk=2) for sup in sups: # determine the right messages to send for this reporter message = reminder_type.message_kw if sup.language == 'en': message = reminder_type.message_en elif sup.language == 'fr': message = reminder_type.message_fr message = message % (reporter.alias, reporter.connection().identity) print "notifying %s of expired reporter with '%s'" % (sup.connection().identity, message) print reporter.last_seen() # and send it off if not self.dry: self.send_message(sup.connection(), message) if not self.dry: Reminder.objects.create(type=reminder_type, date=datetime.datetime.now(), reporter=reporter)
def check_expired_reporters(self): # get our reminder reminder_type = ReminderType.objects.get(pk=6) today = datetime.date.today() # get all our pending expired reporters for reporter in Reminder.get_expired_reporters(today): # look up the supervisors for this reporter sups = Reporter.objects.filter(location=reporter.location, groups__pk=2) for sup in sups: # determine the right messages to send for this reporter message = reminder_type.message_kw if sup.language == 'en': message = reminder_type.message_en elif sup.language == 'fr': message = reminder_type.message_fr message = message % (reporter.alias, reporter.connection().identity) print "notifying %s of expired reporter with '%s'" % ( sup.connection().identity, message) print reporter.last_seen() # and send it off if not self.dry: self.send_message(sup.connection(), message) if not self.dry: Reminder.objects.create(type=reminder_type, date=datetime.datetime.now(), reporter=reporter)