Skip to content

Commit

Permalink
Handle schema for locally mapped GUI files with unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Sep 28, 2023
1 parent 2ee74f3 commit 7a96e82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ovos_gui/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ def get_uri(self, framework: str = "qt5", server_url: str = None) -> str:
self.namespace
if server_url:
if "://" not in server_url:
LOG.debug(f"No schema in server_url, assuming 'http'")
server_url = f"http://{server_url}"
if server_url.startswith("/"):
LOG.debug(f"No schema in server_url, assuming 'file'")
server_url = f"file://{server_url}"
else:
LOG.debug(f"No schema in server_url, assuming 'http'")
server_url = f"http://{server_url}"
path = f"{server_url}/{res_namespace}/{framework}/{res_filename}"
LOG.info(f"Resolved server URI: {path}")
return path
Expand Down
16 changes: 16 additions & 0 deletions test/unittests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ def test_gui_page_from_server(self):
self.assertEqual(qt6,
f"https://files.local/{namespace}/qt5/{page_id}.qml")

def test_gui_page_from_mapped_path(self):
name = "test_page"
persistent = False
duration = 60
page_id = "test_page"
namespace = "skill.test"

page = GuiPage(None, name, persistent, duration, page_id, namespace)
qt5 = page.get_uri(server_url="/path/for/gui/client")
self.assertEqual(qt5,
f"file:///path/for/gui/client/{namespace}/qt5/{page_id}.qml")

qt6 = page.get_uri(server_url="/path/for/gui/client")
self.assertEqual(qt6,
f"file:///path/for/gui/client/{namespace}/qt5/{page_id}.qml")

def test_gui_page_from_local_path(self):
name = "test"
persistent = True
Expand Down

0 comments on commit 7a96e82

Please sign in to comment.