-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PT-5198] Workspace singleton (#595)
* Adding workspace singleton * Removing from auth the workspace. * Removing unnecessary fixture from test_main * updating changelog and version * Simplify test_auth setup * Simplify auth fixtures and workspace properties * Test improvements * Authenticate module export * Improve workspace ID injection * Apply hooks * Version Bump --------- Co-authored-by: Javid Gafar-zada <[email protected]>
- Loading branch information
1 parent
03909f1
commit c3cdf51
Showing
23 changed files
with
231 additions
and
233 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "up42-py" | ||
version = "1.0.4a1" | ||
version = "1.0.4a2" | ||
description = "Python SDK for UP42, the geospatial marketplace and developer platform." | ||
authors = ["UP42 GmbH <[email protected]>"] | ||
license = "https://github.com/up42/up42-py/blob/master/LICENSE" | ||
|
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
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 |
---|---|---|
|
@@ -269,5 +269,3 @@ | |
"updatedAt": "2022-06-20T04:05:31.755744Z", | ||
} | ||
} | ||
|
||
JSON_BALANCE = {"data": {"balance": 10693}} |
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
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
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,50 +1,43 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
import up42 | ||
from up42 import catalog, main, tasking | ||
from up42 import catalog, main, storage, tasking | ||
|
||
from .fixtures import fixtures_globals as constants | ||
|
||
|
||
def test_initialize_object_without_auth_raises(): | ||
main._auth = None # pylint: disable=protected-access | ||
|
||
with pytest.raises(RuntimeError): | ||
def test_fails_to_initialize_if_not_authenticated(): | ||
with pytest.raises(main.UserNotAuthenticated): | ||
up42.initialize_catalog() | ||
with pytest.raises(RuntimeError): | ||
with pytest.raises(main.UserNotAuthenticated): | ||
up42.initialize_storage() | ||
with pytest.raises(RuntimeError): | ||
with pytest.raises(main.UserNotAuthenticated): | ||
up42.initialize_order(order_id=constants.ORDER_ID) | ||
with pytest.raises(RuntimeError): | ||
with pytest.raises(main.UserNotAuthenticated): | ||
up42.initialize_asset(asset_id=constants.ASSET_ID) | ||
|
||
|
||
def test_global_auth_initialize_objects( | ||
storage_mock, | ||
def test_should_initialize_objects( | ||
auth_mock, | ||
order_mock, | ||
asset_mock, | ||
): | ||
up42.authenticate(username=constants.USER_EMAIL, password=constants.PASSWORD) | ||
catalog_obj = up42.initialize_catalog() | ||
assert isinstance(catalog_obj, catalog.Catalog) | ||
storage_obj = up42.initialize_storage() | ||
assert storage_obj.workspace_id == storage_mock.workspace_id | ||
order_obj = up42.initialize_order(order_id=constants.ORDER_ID) | ||
assert order_obj.info == order_mock.info | ||
asset_obj = up42.initialize_asset(asset_id=constants.ASSET_ID) | ||
assert asset_obj.info == asset_mock.info | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def setup_workspace(requests_mock): | ||
requests_mock.post("https://api.up42.com/oauth/token", json={"access_token": constants.TOKEN}) | ||
requests_mock.get( | ||
url="https://api.up42.com/users/me", | ||
json={"data": {"id": constants.WORKSPACE_ID}}, | ||
) | ||
|
||
|
||
def test_should_initialize_tasking(): | ||
up42.authenticate(username=constants.USER_EMAIL, password=constants.PASSWORD) | ||
result = up42.initialize_tasking() | ||
assert isinstance(result, tasking.Tasking) | ||
with mock.patch("up42.main.workspace") as workspace_mock: | ||
workspace_mock.id = constants.WORKSPACE_ID | ||
workspace_mock.auth = auth_mock | ||
|
||
catalog_obj = up42.initialize_catalog() | ||
assert isinstance(catalog_obj, catalog.Catalog) | ||
|
||
storage_obj = up42.initialize_storage() | ||
assert isinstance(storage_obj, storage.Storage) | ||
assert storage_obj.workspace_id == constants.WORKSPACE_ID | ||
|
||
order_obj = up42.initialize_order(order_id=constants.ORDER_ID) | ||
assert order_obj.info == order_mock.info | ||
asset_obj = up42.initialize_asset(asset_id=constants.ASSET_ID) | ||
assert asset_obj.info == asset_mock.info | ||
result = up42.initialize_tasking() | ||
assert isinstance(result, tasking.Tasking) |
Oops, something went wrong.