Exemplo n.º 1
0
class BulkJsonHistoryTest(TestCase):
    def setUp(self) -> None:
        self.history = BulkJsonHistory("test", settings.BULK_DATA_DIR)

    def tearDown(self) -> None:
        self.history.delete_from_disk()

    def test_load_the_file(self) -> None:
        data = self.history.load_json_file()
        self.assertEqual({}, data)

    def test_load_date_when_none(self) -> None:
        d = self.history.get_last_good_date()
        self.assertIsNone(d)

    def test_set_date_then_load_it(self) -> None:
        self.history.add_current_attempt_and_save()
        self.history.mark_success_and_save()
        d = self.history.get_last_good_date()
        self.assertAlmostEqual(
            # The date serialized is within ten seconds of now.
            d,
            now(),
            delta=timedelta(seconds=10),
        )

    def test_add_current_attempt(self) -> None:
        self.history.add_current_attempt_and_save()
        d = self.history.get_last_attempt()
        self.assertAlmostEqual(d, now(), delta=timedelta(seconds=10))
Exemplo n.º 2
0
class BulkJsonHistoryTest(TestCase):

    def setUp(self):
        self.history = BulkJsonHistory('test')

    def tearDown(self):
        self.history.delete_from_disk()

    def test_load_the_file(self):
        data = self.history.load_json_file()
        self.assertEqual(
            {},
            data,
        )

    def test_load_date_when_none(self):
        d = self.history.get_last_good_date()
        self.assertIsNone(d)

    def test_set_date_then_load_it(self):
        self.history.add_current_attempt_and_save()
        self.history.mark_success_and_save()
        d = self.history.get_last_good_date()
        self.assertAlmostEqual(
            # The date serialized is within ten seconds of now.
            d,
            now(),
            delta=timedelta(seconds=10)
        )

    def test_add_current_attempt(self):
        self.history.add_current_attempt_and_save()
        d = self.history.get_last_attempt()
        self.assertAlmostEqual(
            d,
            now(),
            delta=timedelta(seconds=10)
        )