def test_cleanup_old_nonces_cleans_up_old_nonces(self):
        now = time.time()
        # Patch the module's time module so that the nonces appear as if
        # they were created now - timestamp_threshold seconds ago.
        timemod = self.patch(module_time, "time")
        timemod.return_value = now - timestamp_threshold
        old_nonces = [Nonce.objects.create() for i in range(3)]
        self.assertEquals(0, cleanup_old_nonces())
        # Patch the module's time module back.
        timemod.return_value = now
        new_nonces = [Nonce.objects.create() for i in range(3)]

        cleanup_count = cleanup_old_nonces()

        # The old nonces plus the checkpoint nonce are deleted.
        self.assertEquals(len(old_nonces) + 1, cleanup_count)
        self.assertThat(Nonce.objects.all(), ContainsAll(new_nonces))
        self.assertEqual(len(new_nonces) + 1, Nonce.objects.all().count())
    def test_cleanup_old_nonces_cleans_up_old_nonces(self):
        now = time.time()
        # Patch the module's time module so that the nonces appear as if
        # they were created now - timestamp_threshold seconds ago.
        timemod = self.patch(module_time, "time")
        timemod.return_value = now - timestamp_threshold
        old_nonces = [Nonce.objects.create() for i in range(3)]
        self.assertEquals(0, cleanup_old_nonces())
        # Patch the module's time module back.
        timemod.return_value = now
        new_nonces = [Nonce.objects.create() for i in range(3)]

        cleanup_count = cleanup_old_nonces()

        # The old nonces plus the checkpoint nonce are deleted.
        self.assertEquals(len(old_nonces) + 1, cleanup_count)
        self.assertThat(Nonce.objects.all(), ContainsAll(new_nonces))
        self.assertEqual(len(new_nonces) + 1, Nonce.objects.all().count())
Exemple #3
0
 def test_cleanup_old_nonces_returns_0_if_no_checkpoint(self):
     self.assertEqual(0, cleanup_old_nonces())
Exemple #4
0
def cleanup_old_nonces(**kwargs):
    nb_nonces_deleted = nonces_cleanup.cleanup_old_nonces()
    logger.info("%d expired nonce(s) cleaned up." % nb_nonces_deleted)
 def test_cleanup_old_nonces_returns_0_if_no_checkpoint(self):
     self.assertEquals(0, cleanup_old_nonces())