class DBUniqHandlerTest(unittest.TestCase):
    def setUp(self):
        self.handler = DBUniqHandler()
        self.hash1 = hashlib.sha1("test1").hexdigest()
        self.hash2 = hashlib.sha1("test2").hexdigest()
        self.hash3 = hashlib.sha1("test3").hexdigest()

    def test_check(self):
        self.assertEqual(self.handler.check(self.hash1), True)
        self.assertEqual(self.handler.check(self.hash1), False)
        time.sleep(2)
        self.assertEqual(self.handler.check(self.hash1), True)

    def test_cleanup(self):
        self.assertEqual(self.handler.check(self.hash1), True)
        self.assertEqual(self.handler.check(self.hash2), True)
        self.assertEqual(self.handler.check(self.hash3), True)
        self.assertEqual(DBUniqHandlerHashes.objects.all().count(), 3)
        self.handler.cleanup()
        self.assertEqual(DBUniqHandlerHashes.objects.all().count(), 3)
        time.sleep(2)
        self.assertEqual(self.handler.check(self.hash1), True)
        self.assertEqual(DBUniqHandlerHashes.objects.all().count(), 3)
        self.handler.cleanup()
        self.assertEqual(DBUniqHandlerHashes.objects.all().count(), 1)

    def tearDown(self):
        DBUniqHandlerHashes.objects.all().delete()
 def setUp(self):
     self.handler = DBUniqHandler()
     self.hash1 = hashlib.sha1("test1").hexdigest()
     self.hash2 = hashlib.sha1("test2").hexdigest()
     self.hash3 = hashlib.sha1("test3").hexdigest()