def test_get_outstanding(self): five_days_ago = sane_now() - datetime.timedelta(days=5) fake_acct('1', five_days_ago) fake_acct('2', five_days_ago) fake_acct('3', sane_now()) # This guy was created long ago and last checked just now, so he # shouldn't show up in results. a = fake_acct('4', sane_now()) a.creation_time = five_days_ago a.save() results = self._sut.get_outstanding_accounts() self.assertEquals(3, len(results))
def mark_as_checked(self): """ Tells this account to remember that it was checked against the TPL site as of this instant. """ self.last_check = utils.sane_now() self.save()
def get_outstanding_accounts(self): """ Fetch all those accounts that we need to check against the TPL website. In this case, that means any account we haven't checked in 24h. """ yesterday = utils.sane_now() - datetime.timedelta(days=1) mgr = LibraryAccount.objects old_accts_to_check = mgr.filter(last_check__lte=yesterday) new_accts_to_check = mgr.filter(creation_time__gte=yesterday) return old_accts_to_check | new_accts_to_check