示例#1
0
    def test_time_too_old(self):
        with mock.patch.object(config, 'CACHE_INTERVAL', 30):
            rdb.set("my-item/updated", seconds_old(30))
            self.assertTrue(backend.too_old("my-item"))

            rdb.set("my-item/updated", seconds_old(29))
            self.assertFalse(backend.too_old("my-item"))
示例#2
0
    def test_time_too_old(self):
        with mock.patch.object(config, 'CACHE_INTERVAL', 30):
            rdb.set("my-item/updated", seconds_old(30))
            self.assertTrue(backend.too_old("my-item"))

            rdb.set("my-item/updated", seconds_old(29))
            self.assertFalse(backend.too_old("my-item"))
示例#3
0
    def test_cache_other_page_cached(self):
        rdb.set("test_key", STORIES_JSON)

        with mock.patch.object(items, 'update_page') as update_page:
            update_page.assert_not_called()
            self.assertEqual(STORIES_JSON,
                             items._get_cache('test_key', 'test_item'))
示例#4
0
    def test_cache_other_page_cached(self):
        rdb.set("test_key", STORIES_JSON)

        with mock.patch.object(items, 'update_page') as update_page:
            update_page.assert_not_called()
            self.assertEqual(STORIES_JSON,
                             items._get_cache('test_key', 'test_item'))
示例#5
0
    def test_cache_cached_too_old_gets_update(self):
        rdb.set('test_key', STORIES_JSON)

        rdb.set("/test_key/updated", seconds_old(31))

        with mock.patch.object(config, 'CACHE_INTERVAL', 30):
            with mock.patch.object(items.tasks.update, 'delay') as update:
                self.assertEqual(STORIES_JSON,
                                 items._get_cache('test_key', 'test_item'))
                update.assert_called_with('test_key', 'test_item')
示例#6
0
    def test_cache_cached_too_old_gets_update(self):
        rdb.set('test_key', STORIES_JSON)

        rdb.set("/test_key/updated", seconds_old(31))

        with mock.patch.object(config, 'CACHE_INTERVAL', 30):
            with mock.patch.object(items.tasks.update, 'delay') as update:
                self.assertEqual(STORIES_JSON,
                                 items._get_cache('test_key', 'test_item'))
                update.assert_called_with('test_key', 'test_item')