-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from specklesystems/gergo/urlCompare
gergo/urlCompare
- Loading branch information
Showing
4 changed files
with
88 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import sys | ||
from pathlib import Path | ||
from appdirs import user_data_dir | ||
|
||
|
||
def base_path(app_name) -> Path: | ||
# from appdirs https://github.com/ActiveState/appdirs/blob/master/appdirs.py | ||
# default mac path is not the one we use (we use unix path), so using special case for this | ||
system = sys.platform | ||
if system.startswith("java"): | ||
import platform | ||
|
||
os_name = platform.java_ver()[3][0] | ||
if os_name.startswith("Mac"): | ||
system = "darwin" | ||
|
||
if system == "darwin": | ||
return Path(Path.home(), ".config", app_name) | ||
|
||
return Path(user_data_dir(appname=app_name, appauthor=False, roaming=True)) | ||
|
||
|
||
def accounts_path(app_name: str = "Speckle") -> Path: | ||
""" | ||
Gets the path where the Speckle applications are looking for accounts. | ||
""" | ||
return base_path(app_name).joinpath("Accounts") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import pytest | ||
import json | ||
from specklepy.api.wrapper import StreamWrapper | ||
from specklepy.transports.sqlite import SQLiteTransport | ||
from specklepy.paths import accounts_path | ||
from pathlib import Path | ||
import pytest | ||
|
||
|
||
def test_parse_stream(): | ||
|
@@ -79,3 +83,39 @@ def test_get_transport_with_token(): | |
|
||
assert transport is not None | ||
assert client.account.token == "super-secret-token" | ||
|
||
|
||
@pytest.fixture | ||
def user_path() -> Path: | ||
path = accounts_path().joinpath("test_acc.json") | ||
# hey, py37 doesn't support the missing_ok argument | ||
try: | ||
path.unlink() | ||
except: | ||
pass | ||
try: | ||
path.unlink(missing_ok=True) | ||
except: | ||
pass | ||
path.parent.absolute().mkdir(exist_ok=True) | ||
yield path | ||
path.unlink() | ||
|
||
|
||
def test_wrapper_url_match(user_path) -> None: | ||
""" | ||
The stream wrapper should only recognize exact url matches for the account | ||
definitions and not match for subdomains. | ||
""" | ||
account = { | ||
"token": "foobar", | ||
"serverInfo": {"name": "foo", "url": "http://foo.bar.baz", "company": "Foo"}, | ||
"userInfo": {"id": "bla", "name": "A rando tester", "email": "[email protected]"}, | ||
} | ||
|
||
user_path.write_text(json.dumps(account)) | ||
wrap = StreamWrapper("http://bar.baz/streams/bogus") | ||
|
||
account = wrap.get_account() | ||
|
||
assert account.userInfo.email is None |