def test_with_repeated_reminder(self, db, reactor): records = [{ 'hash': 'foo', '_id': 1234567890, 'when': datetime.datetime(day=13, month=12, year=2013), 'repeat': range(7), }] db.reminders.find.return_value = records with freeze_time(records[0]['when'] + datetime.timedelta(seconds=300)): client = Mock() reminders._scheduled = set() reminders.init_reminders(client) assert 1234567890 in reminders._scheduled # It's 300 seconds, late. Should be 1 day from that point reactor.callLater.assert_called_with(86400 - 300, reminders._do_reminder, 1234567890, client) db.reminders.save.assert_called_with({ 'hash': 'foo', '_id': 1234567890, 'when': datetime.datetime(day=14, month=12, year=2013), 'repeat': range(7), })
def test_ignores_scheduled_reminder(self, db, reactor): records = [{ 'hash': 'foo', '_id': 1234567890, 'when': datetime.datetime(day=13, month=12, year=2013) }] db.reminders.find.return_value = records reminders._scheduled = set([123456789]) reminders.init_reminders(Mock()) assert not reactor.callLater.called
def test_ignores_scheduled_reminder(self, db, reactor): records = [ { 'hash': 'foo', '_id': 1234567890, 'when': datetime.datetime(day=13, month=12, year=2013) } ] db.reminders.find.return_value = records reminders._scheduled = set([123456789]) reminders.init_reminders(Mock()) assert not reactor.callLater.called
def test_updates_hash(self, db): records = [ { 'hash': 'foo', '_id': 1234567890, 'when': datetime.datetime(day=13, month=12, year=2013) } ] db.reminders.find.return_value = records reminders.init_reminders(Mock()) db.reminders.update.assert_called_with({'_id': 1234567890}, {'$set': {'hash': '123456'}})
def test_updates_hash(self, db): records = [{ 'hash': 'foo', '_id': 1234567890, 'when': datetime.datetime(day=13, month=12, year=2013) }] db.reminders.find.return_value = records reminders.init_reminders(Mock()) db.reminders.update.assert_called_with({'_id': 1234567890}, {'$set': { 'hash': '123456' }})
def test_with_stale_reminder(self, db): records = [{ 'hash': 'foo', '_id': 1234567890, 'when': datetime.datetime(day=13, month=12, year=2013) }] db.reminders.find.return_value = records with freeze_time(records[0]['when'] + datetime.timedelta(days=1)): client = Mock() reminders._scheduled = set() reminders.init_reminders(client) assert 1234567890 not in reminders._scheduled db.reminders.remove.assert_called_with(1234567890)
def test_with_late_reminder(self, db, reactor): records = [{ 'hash': 'foo', '_id': 1234567890, 'when': datetime.datetime(day=13, month=12, year=2013) }] db.reminders.find.return_value = records with freeze_time(records[0]['when'] + datetime.timedelta(seconds=60)): client = Mock() reminders._scheduled = set() reminders.init_reminders(client) assert 1234567890 in reminders._scheduled reactor.callLater.assert_called_with(0, reminders._do_reminder, 1234567890, client)
def test_with_late_reminder(self, db, reactor): records = [ { 'hash': 'foo', '_id': 1234567890, 'when': datetime.datetime(day=13, month=12, year=2013) } ] db.reminders.find.return_value = records with freeze_time(records[0]['when'] + datetime.timedelta(seconds=60)): client = Mock() reminders._scheduled = set() reminders.init_reminders(client) assert 1234567890 in reminders._scheduled reactor.callLater.assert_called_with(0, reminders._do_reminder, 1234567890, client)
def test_with_stale_reminder(self, db): records = [ { 'hash': 'foo', '_id': 1234567890, 'when': datetime.datetime(day=13, month=12, year=2013) } ] db.reminders.find.return_value = records with freeze_time(records[0]['when'] + datetime.timedelta(days=1)): client = Mock() reminders._scheduled = set() reminders.init_reminders(client) assert 1234567890 not in reminders._scheduled db.reminders.remove.assert_called_with(1234567890)
def test_with_repeated_reminder(self, db, reactor): records = [ { 'hash': 'foo', '_id': 1234567890, 'when': datetime.datetime(day=13, month=12, year=2013), 'repeat': range(7), } ] db.reminders.find.return_value = records with freeze_time(records[0]['when'] + datetime.timedelta(seconds=300)): client = Mock() reminders._scheduled = set() reminders.init_reminders(client) assert 1234567890 in reminders._scheduled # It's 300 seconds, late. Should be 1 day from that point reactor.callLater.assert_called_with(86400 - 300, reminders._do_reminder, 1234567890, client) db.reminders.save.assert_called_with({ 'hash': 'foo', '_id': 1234567890, 'when': datetime.datetime(day=14, month=12, year=2013), 'repeat': range(7), })