Пример #1
0
    def test_touch_updates_last_accessed(self, datetime):
        datetime.utcnow.return_value = self.now

        e = CacheEntry('foo', created_at=self.minute_before,
            last_accessed_at=self.minute_before)

        e.touch()
        self.assertEqual(e.last_accessed_at, self.now)
Пример #2
0
    def test_to_dict(self):
        e = CacheEntry('foo', created_at=self.hour_before,
            last_accessed_at=self.minute_before)

        data = e.to_dict()

        self.assertEqual(data['value'], 'foo')
        self.assertEqual(data['created_at'],
            '2013-01-01 09:30:00.000000')
        self.assertEqual(data['last_accessed_at'],
            '2013-01-01 10:29:00.000000')
Пример #3
0
    def test_cache_put(self, CacheEntry, CacheStats):
        store = MagicMock()

        c = Cache(store=MagicMock(return_value=store))
        c.put('foo', 'Value Of Foo', new=True)

        CacheEntry.assert_called_once_with('Value Of Foo')

        store.__setitem__.assert_called_once_with('foo',
            CacheEntry.return_value)
        CacheStats.return_value.put.assert_called_once_with(new=True)
Пример #4
0
    def test_is_expired_checks_ttl_tti(self, datetime):
        datetime.utcnow.return_value = self.now

        e = CacheEntry('foo', created_at=self.hour_before,
            last_accessed_at=self.minute_before)

        # check ttl
        self.assertTrue(e.is_expired(3600, 24 * 3600))
        self.assertFalse(e.is_expired(3601, 24 * 3600))
        # check tti
        self.assertTrue(e.is_expired(24 * 3600, 60))
        self.assertFalse(e.is_expired(24 * 3600, 61))
Пример #5
0
    def test_parse_invalid_dates(self, datetime):
        datetime.strptime.side_effect = ValueError

        e = CacheEntry.parse({'value': 'foo'})

        self.assertEqual(e.value, 'foo')
        self.assertEqual(e.created_at, datetime.utcnow.return_value)
        self.assertEqual(e.last_accessed_at, datetime.utcnow.return_value)
Пример #6
0
    def test_parse(self):
        e = CacheEntry.parse({
            'value': 'foo',
            'created_at': '2013-01-01 09:30:00.0',
            'last_accessed_at': '2013-01-01 10:29:00.0'
        })

        self.assertEqual(e.value, 'foo')
        self.assertEqual(e.created_at, self.hour_before)
        self.assertEqual(e.last_accessed_at, self.minute_before)
Пример #7
0
    def test_cache_entry_to_dict_parse(self):
        _, acc = self.create_account(self.app.accounts)
        acc.update({'surname': 'Surname'})

        acc_entry_before = acc._store._get_cache(acc.href).store[acc.href]
        acc_entry_after = CacheEntry.parse(acc_entry_before.to_dict())
        self.assertEqual(acc_entry_before.value, acc_entry_after.value)
        self.assertEqual(
            acc_entry_before.created_at, acc_entry_after.created_at)
        self.assertEqual(
            acc_entry_before.last_accessed_at,
            acc_entry_after.last_accessed_at)