Skip to content

Commit

Permalink
Extend Metadata model adding properties to easily get workgroup name …
Browse files Browse the repository at this point in the history
…and ID (#99)

* add properties to easily get the workgroup name and UUID of a metadata
* extend group model adding a property to get the group name (#100)
  • Loading branch information
Guts committed Aug 29, 2019
1 parent 79f103b commit f5466d1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
4 changes: 2 additions & 2 deletions isogeo_pysdk/api/routes_workgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ def listing(
@lru_cache()
@ApiDecorators._check_bearer_validity
def get(
self, workgroup_id: str, include: list = ["_abilities", "limits"]
self, workgroup_id: str, include: tuple = ("_abilities", "limits")
) -> Workgroup:
"""Get details about a specific workgroup.
:param str workgroup_id: workgroup UUID
:param list include: additionnal subresource to include in the response
:param tuple include: additionnal subresource to include in the response
"""
# check workgroup UUID
if not checker.check_is_uuid(workgroup_id):
Expand Down
6 changes: 5 additions & 1 deletion isogeo_pysdk/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# coding: utf-8
#! python3 # noqa: E265

# models which are a dependency for others
from .workgroup import Workgroup # noqa: F401

from .application import Application # noqa: F401
from .catalog import Catalog # noqa: F401

Expand All @@ -25,12 +28,13 @@
from .specification import Specification # noqa: F401
from .thesaurus import Thesaurus # noqa: F401
from .user import User # noqa: F401
from .workgroup import Workgroup # noqa: F401


# depending on previous models
from .condition import Condition # noqa: F401

# shortcuts or confusion reducers
Account = User
Group = Workgroup
Resource = Metadata
ResourceSearch = MetadataSearch
24 changes: 24 additions & 0 deletions isogeo_pysdk/models/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
# package
from isogeo_pysdk.enums import MetadataSubresources, MetadataTypes

# others models
from isogeo_pysdk.models import Workgroup


# #############################################################################
# ########## Globals ###############
Expand Down Expand Up @@ -1251,6 +1254,27 @@ def validityComment(self, validityComment: str):

self._validityComment = validityComment

# -- SPECIFIC TO IMPLEMENTATION ----------------------------------------------------
@property
def groupName(self) -> str:
"""Shortcut to get the name of the workgroup which owns the Metadata."""
if isinstance(self._creator, dict):
return self._creator.get("contact").get("name")
elif isinstance(self._creator, Workgroup):
return self._creator.contact.get("name")
else:
return None

@property
def groupId(self) -> str:
"""Shortcut to get the UUID of the workgroup which owns the Metadata."""
if isinstance(self._creator, dict):
return self._creator.get("_id")
elif isinstance(self._creator, Workgroup):
return self._creator._id
else:
return None

# -- METHODS -----------------------------------------------------------------------
def admin_url(self, url_base: str = "https://app.isogeo.com") -> str:
"""Returns the administration URL (https://app.isogeo.com) for this metadata.
Expand Down
11 changes: 11 additions & 0 deletions isogeo_pysdk/models/workgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ def themeColor(self, themeColor: str):

self._themeColor = themeColor

# -- SPECIFIC TO IMPLEMENTATION ----------------------------------------------------
@property
def name(self) -> str:
"""Shortcut to get the name of the workgroup."""
if isinstance(self.contact, dict):
return self.contact.get("name")
elif isinstance(self.contact, Contact):
return self.contact.name
else:
return None

# -- METHODS -----------------------------------------------------------------------
def to_dict(self) -> dict:
"""Returns the model properties as a dict"""
Expand Down
17 changes: 13 additions & 4 deletions tests/test_metadatas.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Standard library
import logging
import unittest
import urllib3
from os import environ
from pathlib import Path
from random import sample
Expand All @@ -29,11 +28,10 @@

# 3rd party
from dotenv import load_dotenv

import urllib3

# module target
from isogeo_pysdk import Isogeo, IsogeoUtils, Metadata, MetadataSearch

from isogeo_pysdk import Isogeo, IsogeoUtils, Metadata, MetadataSearch, Workgroup

# #############################################################################
# ######## Globals #################
Expand Down Expand Up @@ -161,6 +159,14 @@ def test_metadatas_in_search_results(self):
# admin url
self.assertIsInstance(metadata.admin_url(self.isogeo.app_url), str)

# group name and _id
self.assertIsInstance(metadata.groupName, str)
self.assertIsInstance(metadata.groupId, str)
group = self.isogeo.workgroup.get(metadata.groupId, include=None)
self.assertIsInstance(group, Workgroup)
self.assertEqual(metadata.groupId, group._id)
self.assertEqual(metadata.groupName, group.name)

# def test_search_specific_mds_bad(self):
# """Searches filtering on specific metadata."""
# # get random metadata within a small search
Expand Down Expand Up @@ -191,6 +197,9 @@ def test_metadatas_get_detailed(self):
self.assertTrue(hasattr(metadata, "abstract"))
self.assertTrue(hasattr(metadata, "created"))
self.assertTrue(hasattr(metadata, "modified"))
# specific to implementation
self.assertTrue(hasattr(metadata, "groupId"))
self.assertTrue(hasattr(metadata, "groupName"))

# check method to dict
md_as_dict = metadata.to_dict()
Expand Down
3 changes: 3 additions & 0 deletions tests/test_workgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def test_workgroups_listing_global(self):
self.assertTrue(hasattr(workgroup, "keywordsCasing"))
self.assertTrue(hasattr(workgroup, "metadataLanguage"))
self.assertTrue(hasattr(workgroup, "themeColor"))

# specific
self.assertTrue(hasattr(workgroup, "name"))
# tests attributes value

def test_workgroup_detailed(self):
Expand Down

0 comments on commit f5466d1

Please sign in to comment.