Esempio n. 1
0
class TestFileCache(BaseTest):
    """ Class for testing the filecache """
    def setUp(self):
        shutil.rmtree('tmp', ignore_errors=True)
        self.c = FileCache('tmp')

    def tearDown(self):
        del self.c
        shutil.rmtree('tmp', ignore_errors=True)

    def test_file_cache_get_set(self):
        self.c.set(*self.ex_str)
        self.c.set(*self.ex_int)
        self.c.set(*self.ex_cpx)
        self.assertEqual(self.c.get(self.ex_str[0]), self.ex_str[1])
        self.assertEqual(self.c.get(self.ex_int[0]), self.ex_int[1])
        self.check_complex(self.c.get(self.ex_cpx[0]))

    def test_file_cache_update(self):
        self.c.set(
            self.ex_cpx[0],
            CachedResponse(status_code=200,
                           headers={'foo', 'test'},
                           content='Nothing'.encode('latin-1'),
                           url='http://foobarbaz.com'))
        self.c.set(*self.ex_cpx)
        self.check_complex(self.c.get(self.ex_cpx[0]))

    def test_file_cache_invalidate(self):
        self.c.set('key', 'bar')
        self.assertEqual(self.c.get('key'), 'bar')
        self.c.invalidate('key')
        self.assertEqual(self.c.get('key'), None)
Esempio n. 2
0
class TestFileCache(BaseTest):
    """ Class for testing the filecache """
    def setUp(self):
        shutil.rmtree('tmp', ignore_errors=True)
        self.c = FileCache('tmp')

    def tearDown(self):
        del self.c
        shutil.rmtree('tmp', ignore_errors=True)

    def test_file_cache_get_set(self):
        self.c.set(*self.ex_str)
        self.c.set(*self.ex_int)
        self.c.set(*self.ex_cpx)
        self.assertEqual(self.c.get(self.ex_str[0]), self.ex_str[1])
        self.assertEqual(self.c.get(self.ex_int[0]), self.ex_int[1])
        self.check_complex(self.c.get(self.ex_cpx[0]))

        self.c.set('expired', 'baz', -1)
        self.c.set('never', 'foo', 0)
        self.c.set('nevertoo', 'bar', None)
        self.assertEqual(self.c.get('expired', 'default_because_expired'),
                         'default_because_expired')
        self.assertEqual(self.c.get('expired'), None)
        self.assertEqual(self.c.get('never'), 'foo')
        self.assertEqual(self.c.get('nevertoo'), 'bar')

    def test_file_cache_invalidate(self):
        self.c.set('key', 'bar')
        self.assertEqual(self.c.get('key'), 'bar')
        self.c.invalidate('key')
        self.assertEqual(self.c.get('key'), None)