Skip to content

Commit

Permalink
Applications improvements - #97
Browse files Browse the repository at this point in the history
- model: add a method to build administration URL
- routes: rename application.application into application.get
- features: restore authenticated application properties at startup - close #96
  • Loading branch information
Guts committed Aug 27, 2019
2 parents 768fcc8 + c14bd43 commit 6e06d49
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 27 deletions.
2 changes: 1 addition & 1 deletion isogeo_pysdk/api/routes_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, api_client=None):

@lru_cache()
@ApiDecorators._check_bearer_validity
def account(self, include: list = ["_abilities"], caching: bool = 1) -> User:
def get(self, include: list = ["_abilities"], caching: bool = 1) -> User:
"""Get authenticated user account(= profile) informations.
:param list include: additional parts of model to include in response
Expand Down
14 changes: 6 additions & 8 deletions isogeo_pysdk/api/routes_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def listing(
return applications

@ApiDecorators._check_bearer_validity
def application(
def get(
self, application_id: str, include: list = ["_abilities", "groups"]
) -> Application:
"""Get details about a specific application.
Expand Down Expand Up @@ -412,20 +412,18 @@ def associate_group(
For dev memory, there are two main cases:
Case 1 - application with no groups associated yet:
- self.application(application_id=app_uuid, include=[]).groups[0] is None
- len(self.application(application_id=app_uuid, include=[]).groups) == 1
- self.get(application_id=app_uuid, include=[]).groups[0] is None
- len(self.get(application_id=app_uuid, include=[]).groups) == 1
Case 2 - application with some groups already associated but without include:
- self.application(application_id=app_uuid, include=[]).groups[0] is None
- len(self.application(application_id=app_uuid, include=[]).groups) == 1
- self.get(application_id=app_uuid, include=[]).groups[0] is None
- len(self.get(application_id=app_uuid, include=[]).groups) == 1
"""
if len(application.groups) and application.groups[0] is None:
logger.debug(
"Application doesn't contain its included workgroups. Let's make a new request..."
)
application = self.application(
application_id=application._id, include=["groups"]
)
application = self.get(application_id=application._id, include=["groups"])
else:
pass

Expand Down
19 changes: 17 additions & 2 deletions isogeo_pysdk/isogeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from isogeo_pysdk import api
from isogeo_pysdk.api_hooks import IsogeoHooks
from isogeo_pysdk.checker import IsogeoChecker
from isogeo_pysdk.models import User
from isogeo_pysdk.models import Application, User
from isogeo_pysdk.utils import IsogeoUtils

# ##############################################################################
Expand Down Expand Up @@ -298,7 +298,7 @@ def connect(self, username: str = None, password: str = None):
verify=self.ssl,
)
# get authenticated user informations
self.account.account()
self.account.get()
elif self.auth_mode == "group":
# get token
self.token = self.fetch_token(
Expand All @@ -307,6 +307,21 @@ def connect(self, username: str = None, password: str = None):
client_secret=self.client_secret,
verify=self.ssl,
)
# get authenticated application informations
associated_shares = self.share.listing(caching=0)
if not len(associated_shares):
logger.warning("No shares are feeding this application.")
self.app_properties = None
else:
# if application has associated shares, then retrieve informations
logger.info(
"This application is feeded by {} share(s).".format(
len(associated_shares)
)
)
self.app_properties = Application(
**self.share.listing()[0].get("applications")[0]
)

# -- PROPERTIES -----------------------------------------------------------
@property
Expand Down
9 changes: 9 additions & 0 deletions isogeo_pysdk/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,15 @@ def url(self, url: str):
self._url = url

# -- METHODS -----------------------------------------------------------------------
def admin_url(self, url_base: str = "https://manage.isogeo.com") -> str:
"""Returns the administration URL (https://manage.isogeo.com) for this application.
:param str url_base: base URL of admin site. Defaults to: https://app.isogeo.com
:rtype: str
"""
return "{}/applications/{}".format(url_base, self._id)

def to_dict(self) -> dict:
"""Returns the model properties as a dict"""
result = {}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def tearDownClass(cls):
def test_account(self):
"""GET :/account/}"""
# compare account objects
me = self.isogeo.account.account(caching=0) # Account route
me = self.isogeo.account.get(caching=0) # Account route
self.assertIsInstance(me, User)

def test_account_memberships(self):
Expand Down
16 changes: 10 additions & 6 deletions tests/test_applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ def test_applications_workgroup(self):
self.assertEqual(application.name, i.get("name"))
self.assertEqual(application.staff, i.get("staff"))

# check admin url
self.assertIsInstance(application.admin_url(self.isogeo.mng_url), str)
self.assertTrue(
application.admin_url(self.isogeo.mng_url).startswith("https")
)

def test_application_workgroups(self):
"""GET :/applications/{application_uiid}/groups}"""
# retrieve applications
Expand Down Expand Up @@ -305,15 +311,13 @@ def test_application_detailed(self):
self.assertTrue(self.isogeo.application.exists(application_group.get("_id")))

# get and check
application_user_confidential = self.isogeo.application.application(
application_user_confidential = self.isogeo.application.get(
application_user_confidential.get("_id")
)
application_user_public = self.isogeo.application.application(
application_user_public = self.isogeo.application.get(
application_user_public.get("_id")
)
application_group = self.isogeo.application.application(
application_group.get("_id")
)
application_group = self.isogeo.application.get(application_group.get("_id"))
self.assertIsInstance(application_user_confidential, Application)
self.assertIsInstance(application_user_public, Application)
self.assertIsInstance(application_group, Application)
Expand All @@ -335,7 +339,7 @@ def test_applications_update(self):
application_fixture = self.isogeo.application.update(application_fixture)

# check if the change is effective
application_fixture_updated = self.isogeo.application.application(
application_fixture_updated = self.isogeo.application.get(
application_fixture._id
)
self.assertEqual(
Expand Down
16 changes: 7 additions & 9 deletions tests/test_shares.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@


# module target
from isogeo_pysdk import Isogeo, Share, IsogeoUtils
from isogeo_pysdk import Isogeo, Share


# #############################################################################
# ######## Globals #################
# ##################################

utils = IsogeoUtils()

if Path("dev.env").exists():
load_dotenv("dev.env", override=True)

Expand Down Expand Up @@ -102,8 +100,6 @@ def setUpClass(cls):
password=environ.get("ISOGEO_USER_PASSWORD"),
)

utils.set_base_url(environ.get("ISOGEO_PLATFORM", "qa"))

def setUp(self):
"""Executed before each test."""
# tests stuff
Expand Down Expand Up @@ -323,11 +319,13 @@ def test_shares_get_detailed_basic(self):
self.assertTrue(hasattr(share, "type"))
self.assertTrue(hasattr(share, "urlToken"))
# test methods
self.assertIn("app", share_appli.admin_url(utils.app_url))
self.assertIsInstance(share_appli.opencatalog_url(utils.oc_url), (str, None))
self.assertIn("app", share_appli.admin_url(self.isogeo.app_url))
self.assertIsInstance(
share_appli.opencatalog_url(self.isogeo.oc_url), (str, None)
)

self.assertIn("app", share_group.admin_url(utils.app_url))
self.assertFalse(share_group.opencatalog_url(utils.oc_url))
self.assertIn("app", share_group.admin_url(self.isogeo.app_url))
self.assertFalse(share_group.opencatalog_url(self.isogeo.oc_url))

# -- PUT/PATCH --
# def test_shares_update(self):
Expand Down

0 comments on commit 6e06d49

Please sign in to comment.