예제 #1
0
 def setUp(self):
     self.dirname = tempfile.mkdtemp()
     self.store = CachedTempFilestore(
         FileSystemHeaderedFilestore(self.dirname))
예제 #2
0
 def setUp(self):
     self.dirname = tempfile.mkdtemp()
     self.store = FileSystemHeaderedFilestore(self.dirname)
예제 #3
0
class TestFileSystemHeaderedFileStore(unittest.TestCase):
    def setUp(self):
        self.dirname = tempfile.mkdtemp()
        self.store = FileSystemHeaderedFilestore(self.dirname)

    def tearDown(self):
        shutil.rmtree(self.dirname)

    def test_put(self):
        self.store.put('foo', [('Cache-Tag', '1'),
                               ('Content-Type', 'text/plain')],
                       StringIO("Yay!"))
        assert file(
            os.path.join(self.dirname, 'foo'),
            'rb').read() == 'Cache-Tag: 1\nContent-Type: text/plain\n\nYay!'
        (headers, f) = self.store.get('foo')
        try:
            assert headers == [('Cache-Tag', '1'),
                               ('Content-Type', 'text/plain')]
            assert f.read() == 'Yay!'
        finally:
            f.close()

    def test_put_headersdict(self):
        self.store.put('foo', {
            'Cache-Tag': '1',
            'Content-Type': 'text/plain'
        }, StringIO("Yay!"))
        assert file(
            os.path.join(self.dirname, 'foo'),
            'rb').read() == 'Cache-Tag: 1\nContent-Type: text/plain\n\nYay!'

    def test_get(self):
        self.store.put('foo', [('Cache-Tag', '1'),
                               ('Content-Type', 'text/plain')],
                       StringIO("Yay!"))
        headers, f = self.store.get('foo')
        try:
            assert headers == [('Cache-Tag', '1'),
                               ('Content-Type', 'text/plain')]
            assert f.read() == 'Yay!'
        finally:
            f.close()

    def test_headers(self):
        self.store.put('foo', [('foo', 'foo'), ('bar', 'bar')],
                       StringIO('Yay!'))
        (headers, f) = self.store.get('foo')
        try:
            assert headers == [('foo', 'foo'), ('bar', 'bar')]
            assert f.read() == 'Yay!'
        finally:
            f.close()

    def test_not_found(self):
        self.assertRaises(KeyError, self.store.get, 'not_found')

    def test_delete(self):
        self.store.put('foo', [], StringIO('foo'))
        self.store.delete('foo')
        self.assertRaises(KeyError, self.store.get, 'foo')

    def test_delete_glob(self):
        self.store.put('foo', [], StringIO('foo'))
        self.store.delete('fo', glob=True)
        self.assertRaises(KeyError, self.store.get, 'foo')

    def test_unicode(self):
        gbp = '£'.decode('utf-8')
        self.store.put('foo', [('a', gbp)], StringIO('foo'))
        (headers, f) = self.store.get('foo')
        headers = dict(headers)
        assert isinstance(headers['a'], unicode)
        assert headers['a'] == gbp
예제 #4
0
class TestFileSystemHeaderedFileStore(unittest.TestCase):

    def setUp(self):
        self.dirname = tempfile.mkdtemp()
        self.store = FileSystemHeaderedFilestore(self.dirname)

    def tearDown(self):
        shutil.rmtree(self.dirname)

    def test_put(self):
        self.store.put('foo', [('Cache-Tag', '1'), ('Content-Type', 'text/plain')], StringIO("Yay!"))
        assert file(os.path.join(self.dirname, 'foo'), 'rb').read() == 'Cache-Tag: 1\nContent-Type: text/plain\n\nYay!'
        (headers, f) = self.store.get('foo')
        try:
            assert headers == [('Cache-Tag', '1'), ('Content-Type', 'text/plain')]
            assert f.read() == 'Yay!'
        finally:
            f.close()

    def test_put_headersdict(self):
        self.store.put('foo', {'Cache-Tag':'1', 'Content-Type':'text/plain'}, StringIO("Yay!"))
        assert file(os.path.join(self.dirname, 'foo'), 'rb').read() == 'Cache-Tag: 1\nContent-Type: text/plain\n\nYay!'

    def test_get(self):
        self.store.put('foo', [('Cache-Tag', '1'), ('Content-Type', 'text/plain')], StringIO("Yay!"))
        headers, f = self.store.get('foo')
        try:
            assert headers == [('Cache-Tag', '1'), ('Content-Type', 'text/plain')]
            assert f.read() == 'Yay!'
        finally:
            f.close()

    def test_headers(self):
        self.store.put('foo', [('foo', 'foo'), ('bar', 'bar')], StringIO('Yay!'))
        (headers, f) = self.store.get('foo')
        try:
            assert headers == [('foo', 'foo'), ('bar', 'bar')]
            assert f.read() == 'Yay!'
        finally:
            f.close()

    def test_not_found(self):
        self.assertRaises(KeyError, self.store.get, 'not_found')

    def test_delete(self):
        self.store.put('foo', [], StringIO('foo'))
        self.store.delete('foo')
        self.assertRaises(KeyError, self.store.get, 'foo')

    def test_delete_glob(self):
        self.store.put('foo', [], StringIO('foo'))
        self.store.delete('fo', glob=True)
        self.assertRaises(KeyError, self.store.get, 'foo')

    def test_unicode(self):
        gbp = '£'.decode('utf-8')
        self.store.put('foo', [('a', gbp)], StringIO('foo'))
        (headers, f) = self.store.get('foo')
        headers = dict(headers)
        assert isinstance(headers['a'], unicode)
        assert headers['a'] == gbp