示例#1
0
 def test_convert(self, client_env):
     client = Client()
     result_path, cache_key, metadata = client.convert(client_env.src_doc)
     assert result_path.endswith('/sample.html.zip')
     assert os.path.isfile(result_path)
     assert cache_key is None  # no cache, no cache_key
     assert metadata == {'error': False, 'oocp_status': 0}
示例#2
0
 def test_argument_error(self, client_env):
     # wrong args lead to ArgumentErrors
     client = Client()
     # illegal output format and not existing processors
     options = {'oocp-out-fmt': 'foo', 'meta-procord': 'foo,bar'}
     with pytest.raises(ArgumentParserError):
         client.convert(client_env.src_doc, options=options)
示例#3
0
 def test_options(self, client_env):
     # we can pass in options
     client = Client()
     options = {'oocp-out-fmt': 'pdf', 'meta-procord': 'oocp'}
     result_path, cache_key, metadata = client.convert(client_env.src_doc,
                                                       options=options)
     assert result_path.endswith('/sample.pdf')
     assert metadata == {'error': False, 'oocp_status': 0}
示例#4
0
 def test_get_cached(self, client_env):
     # we can get an already cached doc
     client = Client(cache_dir=client_env.cache_dir)
     result_path, cache_key, metadata = client.convert(client_env.src_doc)
     assert cache_key == '396199333edbf40ad43e62a1c1397793_1_1'
     cached_path = client.get_cached(cache_key)
     assert filecmp.cmp(result_path, cached_path, shallow=False)
     assert client_env.cache_dir in cached_path
示例#5
0
    def get_cached(self, cache_key):
        """Get a cached document.

        Retrieve the document representation stored under `cache_key`
        in cache if it exists. Returns `None` otherwise.
        """
        client = Client(cache_dir=self.cache_dir)
        return client.get_cached(cache_key)
示例#6
0
 def test_get_cached_by_source(self, client_env):
     # we can get a file when cached and by source/options
     client = Client(cache_dir=client_env.cache_dir)
     result_path, cache_key, metadata = client.convert(client_env.src_doc)
     assert cache_key == '396199333edbf40ad43e62a1c1397793_1_1'
     c_path, c_key = client.get_cached_by_source(client_env.src_doc)
     assert filecmp.cmp(result_path, c_path, shallow=False)
     assert client_env.cache_dir in c_path
     assert c_key == '396199333edbf40ad43e62a1c1397793_1_1'
示例#7
0
 def test_get_cached_by_source_no_cache_dir(self, client_env):
     # we cannot get a cached file if w/o cache_dir set
     client = Client(cache_dir=None)
     c_path, c_key = client.get_cached_by_source(client_env.src_doc)
     assert c_path is None
     assert c_key is None
示例#8
0
 def test_get_cached_by_source_no_file(self, client_env):
     # we cannot get a cached file if it has not been cached before
     client = Client(cache_dir=client_env.cache_dir)
     c_path, c_key = client.get_cached_by_source(client_env.src_doc)
     assert c_path is None
     assert c_key is None
示例#9
0
 def test_get_cached_no_manager(self, client_env):
     # no cache_dir -> no cache_manager, but we cope with it
     client = Client(cache_dir=None)
     assert client.get_cached(
         '396199333edbf40ad43e62a1c1397793_1_1') is None
示例#10
0
 def test_get_cached_no_file(self, client_env):
     # when asking for cached files we cope with nonexistent docs
     client = Client(cache_dir=client_env.cache_dir)
     assert client.get_cached(
         '396199333edbf40ad43e62a1c1397793_1_1') is None