Exemplo n.º 1
0
    def test_restore_from_disk_failure(self):
        execution = self.mk_exec_locals()

        execution.locals['__path__'].parent.mkdir()
        execution.locals['__path__'].write_bytes(b'hi')
        with self.assertRaises(FileNotFoundError):
            Response.restore_from_disk(execution)
        execution.locals['__path__'].unlink()

        execution.locals['__metadata_path__'].parent.mkdir()
        execution.locals['__metadata_path__'].write_bytes(b'hi')
        with self.assertRaises(FileNotFoundError):
            Response.restore_from_disk(execution)
        execution.locals['__metadata_path__'].unlink()
Exemplo n.º 2
0
    def test_store_to_disk_success_roundtrip(self):
        execution = self.mk_exec_locals()
        self.assertFalse(exists(execution.locals['__path__']))
        self.assertFalse(exists(execution.locals['__metadata_path__']))
        response = Response('hello world',
                            headers={
                                'content-type': 'text/plain',
                            })
        response.store_to_disk(execution)
        self.assertTrue(exists(execution.locals['__path__']))
        self.assertTrue(exists(execution.locals['__metadata_path__']))

        new_response = Response.restore_from_disk(execution)
        self.assertEqual(new_response.content, response.content)
        self.assertEqual(new_response.headers, response.headers)