Skip to content

Commit

Permalink
Verify filters on clientside
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennart Regebro committed Jul 23, 2024
1 parent f75e5a6 commit b3cd59f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
21 changes: 20 additions & 1 deletion src/unoserver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def _connect(self, proxy, retries=5, sleep=10):
while retries > 0:
try:
info = proxy.info()
if not info["unoserver"] == __version__:
raise RuntimeError(
f"Version mismatch. Client runs {__version__} while "
f"Server runs {info['unoserver']}"
)
return info
except ConnectionError:
retries -= 1
Expand Down Expand Up @@ -112,7 +117,21 @@ def convert(
raise ValueError("The outpath can not be a directory")

with ServerProxy(f"http://{self.server}:{self.port}", allow_none=True) as proxy:
self._connect(proxy)
info = self._connect(proxy)

if infiltername and infiltername not in info["import_filters"]:
existing = "\n".join(sorted(info["import_filters"]))
logger.critical(
f"Unknown import filter: {infiltername}. Available filters:\n{existing}"
)
raise RuntimeError("Invalid parameter")

if filtername and filtername not in info["export_filters"]:
existing = "\n".join(sorted(info["export_filters"]))
logger.critical(
f"Unknown export filter: {filtername}. Available filters:\n{existing}"
)
raise RuntimeError("Invalid parameter")

result = proxy.convert(
inpath,
Expand Down
21 changes: 12 additions & 9 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_explicit_export_filter(server_fixture, filename):

@pytest.mark.parametrize("filename", ["simple.odt", "simple.xlsx"])
def test_invalid_explicit_export_filter_prints_available_filters(
server_fixture, filename
caplog, server_fixture, filename
):
infile = os.path.join(TEST_DOCS, filename)

Expand All @@ -156,10 +156,13 @@ def test_invalid_explicit_export_filter_prints_available_filters(
sys.argv = ["unoconverter", "--filter", "asdasdasd", infile, outfile.name]
try:
client.converter_main()
except Fault as err:
assert "Office Open XML Text" in err.faultString
assert "writer8" in err.faultString
assert "writer_pdf_Export" in err.faultString
except RuntimeError:
errstr = caplog.text
print(errstr)
print("=" * 30)
assert "Office Open XML Text" in errstr
assert "writer8" in errstr
assert "writer_pdf_Export" in errstr


def test_update_index(server_fixture):
Expand Down Expand Up @@ -190,7 +193,7 @@ def test_update_index(server_fixture):

def test_convert_not_local():
hostname = socket.gethostname()
cmd = ["unoserver", "--uno-port=2102", "--port=2103", f"--interface={hostname}"]
cmd = ["unoserver", "--uno-port=2104", "--port=2105", f"--interface={hostname}"]
process = subprocess.Popen(cmd)
try:
# Wait for it to start
Expand All @@ -205,7 +208,7 @@ def test_convert_not_local():
"unoconverter",
"--host",
hostname,
"--port=2103",
"--port=2105",
infile,
outfile.name,
]
Expand All @@ -226,7 +229,7 @@ def test_convert_not_local():

def test_compare_not_local():
hostname = socket.gethostname()
cmd = ["unoserver", "--uno-port=2102", "--port=2103", f"--interface={hostname}"]
cmd = ["unoserver", "--uno-port=2104", "--port=2105", f"--interface={hostname}"]
process = subprocess.Popen(cmd)
try:
# Wait for it to start
Expand All @@ -242,7 +245,7 @@ def test_compare_not_local():
"unoconverter",
"--host",
hostname,
"--port=2103",
"--port=2105",
infile1,
infile2,
outfile.name,
Expand Down
1 change: 1 addition & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_server_params(popen_mock, thread_mock):
]
)


@mock.patch("threading.Thread")
@mock.patch("subprocess.Popen")
def test_server_ipv6_params(popen_mock, thread_mock):
Expand Down

0 comments on commit b3cd59f

Please sign in to comment.