def test_saving(self): history = PickleHistory(self._history_file) url = 'foo' entry1 = PickleHistoryTest.EntryMock(1, datetime.now()) entry2 = PickleHistoryTest.EntryMock(2, datetime.now()) history.add_entry(url, entry1) self.assertTrue(history.contains(url, entry1)) self.assertFalse(history.contains(url, entry2)) history.save() del history history = PickleHistory(self._history_file) self.assertTrue(history.contains(url, entry1)) self.assertFalse(history.contains(url, entry2))
def test_cleanup(self): history_args = {'file_path': self._history_file, 'entry_count': 2, 'days_to_keep': 30} history = PickleHistory(**history_args) url = 'foo' today = datetime.now() last_month = today - timedelta(weeks=4) two_months_ago = today - timedelta(weeks=8) entry1 = PickleHistoryTest.EntryMock(1, two_months_ago) entry2 = PickleHistoryTest.EntryMock(2, last_month) entry3 = PickleHistoryTest.EntryMock(3, today) history.add_entry(url, entry1) history.add_entry(url, entry2) self.assertTrue(history.contains(url, entry1)) self.assertTrue(history.contains(url, entry2)) self.assertFalse(history.contains(url, entry3)) history.save() del history history = PickleHistory(**history_args) self.assertTrue(history.contains(url, entry1)) self.assertTrue(history.contains(url, entry2)) self.assertFalse(history.contains(url, entry3)) history.add_entry(url, entry3) self.assertTrue(history.contains(url, entry1)) self.assertTrue(history.contains(url, entry2)) self.assertTrue(history.contains(url, entry3)) history.save() del history history = PickleHistory(**history_args) self.assertFalse(history.contains(url, entry1)) self.assertTrue(history.contains(url, entry2)) self.assertTrue(history.contains(url, entry3))