Skip to content

Commit

Permalink
portal_utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Dec 18, 2023
1 parent f10e4ac commit 16bbd38
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dcicutils/portal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def init(unspecified: Optional[list] = []) -> None:
self._key = None
self._key_pair = None
self._key_id = None
self._secret = None
self._keys_file = None
self._env = None
self._server = None
Expand All @@ -61,6 +62,7 @@ def init_from_portal(portal: Portal, unspecified: Optional[list] = None) -> None
self._key = portal._key
self._key_pair = portal._key_pair
self._key_id = portal._key_id
self._secret = portal._secret
self._keys_file = portal._keys_file
self._env = portal._env
self._server = portal._server
Expand All @@ -82,6 +84,7 @@ def init_from_key(key: dict, server: Optional[str], unspecified: Optional[list]
isinstance(secret := key.get("secret"), str) and secret): # noqa
self._key = {"key": key_id, "secret": secret}
self._key_id = key_id
self._secret = secret
self._key_pair = (key_id, secret)
if ((isinstance(server, str) and server) or (isinstance(server := key.get("server"), str) and server)):
if server := normalize_server(server):
Expand Down Expand Up @@ -168,6 +171,10 @@ def key_pair(self) -> Optional[tuple]:
def key_id(self) -> Optional[str]:
return self._key_id

@property
def secret(self) -> Optional[str]:
return self._secret

@property
def keys_file(self) -> Optional[str]:
return self._keys_file
Expand Down
13 changes: 13 additions & 0 deletions test/test_portal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def test_portal_constructor_c():

portal = Portal(keys_file)
assert portal.key_id == "ABCDEFGHI"
assert portal.secret == "adfxdloiebvhzp"
assert portal.key_pair == ("ABCDEFGHI", "adfxdloiebvhzp")
assert portal.server == "http://localhost:8080"
assert portal.key == {"key": "ABCDEFGHI", "secret": "adfxdloiebvhzp", "server": "http://localhost:8080"}
Expand All @@ -114,3 +115,15 @@ def test_portal_constructor_c():
assert portal.app is None
assert portal.vapp is None
assert portal.ini_file is None

portal_copy = Portal(portal)
assert portal.ini_file == portal_copy.ini_file
assert portal.key == portal_copy.key
assert portal.key_pair == portal_copy.key_pair
assert portal.key_id == portal_copy.key_id
assert portal.keys_file == portal_copy.keys_file
assert portal.env == portal_copy.env
assert portal.server == portal_copy.server
assert portal.app == portal_copy.app
assert portal.vapp == portal_copy.vapp
assert portal.secret == portal_copy.secret

0 comments on commit 16bbd38

Please sign in to comment.