Example #1
0
 def setUp(self):
     super(BannedAdressCacheTestCase, self).setUp()
     self.cache = BannedAddressesCache()
     self.address = '127.0.0.1'
     self.ban_timestamp = datetime.datetime(2016, 12, 10, 21, 0, 0)
     self.expected_ban_expiry = self.ban_timestamp + datetime.timedelta(
         seconds=60)
Example #2
0
class BannedAdressCacheTestCase(TestCase):
    def setUp(self):
        super(BannedAdressCacheTestCase, self).setUp()
        self.cache = BannedAddressesCache()
        self.address = '127.0.0.1'
        self.ban_timestamp = datetime.datetime(2016, 12, 10, 21, 0, 0)
        self.expected_ban_expiry = self.ban_timestamp + datetime.timedelta(
            seconds=60)

    def test_correct_withdrawal_is_set(self):
        self.cache.add(self.address)
        self.assertTrue(self.cache.contains(self.address))
        expected_expiry = datetime.datetime.now() + datetime.timedelta(
            seconds=60)
        self.assertEqual(self.cache._cache[self.address].year,
                         expected_expiry.year)
        self.assertEqual(self.cache._cache[self.address].month,
                         expected_expiry.month)
        self.assertEqual(self.cache._cache[self.address].day,
                         expected_expiry.day)
        self.assertEqual(self.cache._cache[self.address].hour,
                         expected_expiry.hour)
        self.assertEqual(self.cache._cache[self.address].minute,
                         expected_expiry.minute)
        self.assertEqual(self.cache._cache[self.address].second,
                         expected_expiry.second)

    def test_flush_after_withdrawal(self):
        with mock_now(self.ban_timestamp):
            self.cache.add(self.address)

        with mock_now(self.expected_ban_expiry):
            self.assertFalse(self.cache.contains(self.address))
class BannedAdressCacheTestCase(TestCase):
    def setUp(self):
        super(BannedAdressCacheTestCase, self).setUp()
        self.cache = BannedAddressesCache()
        self.address = '127.0.0.1'
        self.ban_timestamp = datetime.datetime(2016, 12, 10, 21, 0, 0)
        self.expected_ban_expiry = self.ban_timestamp + datetime.timedelta(seconds=60)

    def test_correct_withdrawal_is_set(self):
        self.cache.add(self.address)
        self.assertTrue(self.cache.contains(self.address))
        expected_expiry = datetime.datetime.now() + datetime.timedelta(seconds=60)
        self.assertEqual(self.cache._cache[self.address].year, expected_expiry.year)
        self.assertEqual(self.cache._cache[self.address].month, expected_expiry.month)
        self.assertEqual(self.cache._cache[self.address].day, expected_expiry.day)
        self.assertEqual(self.cache._cache[self.address].hour, expected_expiry.hour)
        self.assertEqual(self.cache._cache[self.address].minute, expected_expiry.minute)
        self.assertEqual(self.cache._cache[self.address].second, expected_expiry.second)

    def test_flush_after_withdrawal(self):
        with mock_now(self.ban_timestamp):
            self.cache.add(self.address)

        with mock_now(self.expected_ban_expiry):
            self.assertFalse(self.cache.contains(self.address))
 def setUp(self):
     super(BannedAdressCacheTestCase, self).setUp()
     self.cache = BannedAddressesCache()
     self.address = '127.0.0.1'
     self.ban_timestamp = datetime.datetime(2016, 12, 10, 21, 0, 0)
     self.expected_ban_expiry = self.ban_timestamp + datetime.timedelta(seconds=60)