Skip to content

Commit

Permalink
Merge pull request #164 from isogeo/processor-related
Browse files Browse the repository at this point in the history
Metadata Processor related
  • Loading branch information
Guts committed Apr 30, 2020
2 parents ef53b2d + 6871ffe commit 0e9f733
Show file tree
Hide file tree
Showing 19 changed files with 301 additions and 96 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ ISOGEO_USER_PASSWORD=

# SHORTCUTS
ISOGEO_FIXTURES_METADATA_COMPLETE=
ISOGEO_FIXTURES_METADATA_SERVICE
ISOGEO_WORKGROUP_TEST_UUID=
30 changes: 30 additions & 0 deletions .vscode/docstring-config.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{! Sphinx Docstring Template }}
{{summaryPlaceholder}}

{{#parametersExist}}
{{#args}}
:param {{typePlaceholder}} {{var}}: {{descriptionPlaceholder}}
{{/args}}
{{#kwargs}}
:param {{typePlaceholder}} {{var}}: {{descriptionPlaceholder}}. Defaults to: {{&default}} - optional
{{/kwargs}}
{{/parametersExist}}

{{#exceptionsExist}}
{{#exceptions}}
:raises {{type}}: {{descriptionPlaceholder}}
{{/exceptions}}
{{/exceptionsExist}}

{{#returnsExist}}
{{#returns}}
:return: {{descriptionPlaceholder}}
:rtype: {{typePlaceholder}}
{{/returns}}
{{/returnsExist}}

:example:

.. code-block:: python

# here comes an example in Python
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"mikestead.dotenv",
"ms-azure-devops.azure-pipelines",
"ms-python.python",
"ms-vscode.powershell"
"ms-vscode.powershell",
"njpwerner.autodocstring"
]
}

3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"-p",
"test_*.py"
],
"restructuredtext.confPath": "${workspaceFolder}\\docs"
"restructuredtext.confPath": "${workspaceFolder}\\docs",
"autoDocstring.customTemplatePath": ".vscode\\docstring-config.mustache",
}
4 changes: 2 additions & 2 deletions isogeo_pysdk/api/routes_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def listing(self, metadata: Metadata) -> list:
"""
# URL
url_events = utils.get_request_base_url(
route="resources/{}/events/".format(metadata._id)
route="resources/{}/events".format(metadata._id)
)

# request
Expand Down Expand Up @@ -182,7 +182,7 @@ def create(self, metadata: Metadata, event: Event) -> Event:

# URL
url_event_create = utils.get_request_base_url(
route="resources/{}/events/".format(metadata._id)
route="resources/{}/events".format(metadata._id)
)

# request
Expand Down
3 changes: 2 additions & 1 deletion isogeo_pysdk/api/routes_metadata_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def prepare(

# ensure lowercase
prepared_request.action = action.lower()
prepared_request.target = target.lower()
# prepared_request.target = target.lower()
prepared_request.target = target

# check metadatas uuid
metadatas = list(metadatas)
Expand Down
2 changes: 2 additions & 0 deletions isogeo_pysdk/isogeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def connect(self, username: str = None, password: str = None):
password=password,
client_id=self.client_id,
client_secret=self.client_secret,
proxies=self.proxies,
verify=self.ssl,
)
# get authenticated user informations
Expand All @@ -349,6 +350,7 @@ def connect(self, username: str = None, password: str = None):
token_url=self.auto_refresh_url,
client_id=self.client_id,
client_secret=self.client_secret,
proxies=self.proxies,
verify=self.ssl,
)
# get authenticated application informations
Expand Down
44 changes: 33 additions & 11 deletions isogeo_pysdk/models/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
# ##################################

# standard library
from hashlib import sha256
import logging
import pprint
import re
import unicodedata
from hashlib import sha256
from typing import Union

# package
from isogeo_pysdk.enums import MetadataTypes

# others models
from isogeo_pysdk.models import Workgroup
from isogeo_pysdk.models import CoordinateSystem, Workgroup


# #############################################################################
Expand Down Expand Up @@ -205,6 +206,7 @@ class Metadata(object):
"abstract": str,
"collectionContext": str,
"collectionMethod": str,
"coordinateSystem": dict,
"distance": float,
"editionProfile": str,
"encoding": str,
Expand Down Expand Up @@ -612,22 +614,26 @@ def contacts(self, contacts: list):

# coordinateSystem
@property
def coordinateSystem(self) -> dict:
def coordinateSystem(self) -> CoordinateSystem:
"""Gets the coordinateSystem of this Metadata.
:return: The coordinateSystem of this Metadata.
:rtype: dict
:rtype: CoordinateSystem
"""
return self._coordinateSystem

@coordinateSystem.setter
def coordinateSystem(self, coordinateSystem: dict):
def coordinateSystem(self, coordinateSystem: Union[dict, CoordinateSystem]):
"""Sets the coordinate systems of this Metadata.
:param dict coordinateSystem: to be set
:param Union[dict, CoordinateSystem] coordinateSystem: coordinate-system to be set
"""

self._coordinateSystem = coordinateSystem
if isinstance(coordinateSystem, dict):
self._coordinateSystem = CoordinateSystem(**coordinateSystem)
elif isinstance(coordinateSystem, CoordinateSystem):
self._coordinateSystem = coordinateSystem
else:
self._coordinateSystem = None

# created
@property
Expand Down Expand Up @@ -1279,7 +1285,7 @@ def validityComment(self) -> str:

@validityComment.setter
def validityComment(self, validityComment: str):
"""Sets the of this Metadata.
"""Sets the validityComment of this Metadata.
:param str validityComment: to be set
"""
Expand Down Expand Up @@ -1307,6 +1313,12 @@ def groupId(self) -> str:
else:
return None

@property
def typeFilter(self) -> str:
"""Shortcut to get the type as expected in search filter."""
if self.type in MetadataTypes.__members__:
return MetadataTypes[self.type].value

# -- 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 Expand Up @@ -1463,7 +1475,17 @@ def signature(
for i in included_attributes:
# because hash.update requires a
if getattr(self, i):
hasher.update(getattr(self, i).encode())
try:
attr_value = getattr(self, i)
if isinstance(attr_value, str):
hasher.update(attr_value.encode())
elif isinstance(attr_value, dict):
hasher.update(hash(frozenset(attr_value.items())))
else:
hasher.update(hash(attr_value))
pass
except TypeError:
pass

return hasher.hexdigest()

Expand Down
23 changes: 10 additions & 13 deletions isogeo_pysdk/models/metadata_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ def __init__(
tags: dict = None,
total: int = None,
):
"""resource/search?
model
"""
"""Model for object returned by resource/search?."""

# default values for the object attributes/properties
self._envelope = None
Expand Down Expand Up @@ -89,11 +86,11 @@ def envelope(self) -> dict:

@envelope.setter
def envelope(self, envelope: dict):
"""Sets the envelope of this InlineResponse2001.
"""Sets the envelope of this metadata search.
The aggregated convex hull for the entire serach results. Might be null (if the results span the entire globe, for instance). # noqa: E501
:param envelope: The envelope of this InlineResponse2001. # noqa: E501
:param envelope: The envelope of this metadata search. # noqa: E501
:type: object
"""

Expand All @@ -111,7 +108,7 @@ def limit(self) -> int:

@limit.setter
def limit(self, limit: int):
"""Sets the limit of this InlineResponse2001.
"""Sets the limit of this metadata search.
:param int limit: The limit of this Metadata Search
"""
Expand Down Expand Up @@ -149,9 +146,9 @@ def query(self) -> dict:

@query.setter
def query(self, query: dict):
"""Sets the query of this InlineResponse2001.
"""Sets the query of this metadata search.
:param query: The query of this InlineResponse2001. # noqa: E501
:param query: The query of this metadata search. # noqa: E501
:type: object
"""

Expand All @@ -169,9 +166,9 @@ def results(self) -> list:

@results.setter
def results(self, results: list):
"""Sets the results of this InlineResponse2001.
"""Sets the results of this metadata search.
:param results: The results of this InlineResponse2001. # noqa: E501
:param results: The results of this metadata search. # noqa: E501
:type: list[Metadata]
"""

Expand All @@ -189,11 +186,11 @@ def tags(self) -> dict:

@tags.setter
def tags(self, tags: dict):
"""Sets the tags of this InlineResponse2001.
"""Sets the tags of this metadata search.
The aggregated set of tags for the entire search results # noqa: E501
:param tags: The tags of this InlineResponse2001. # noqa: E501
:param tags: The tags of this metadata search. # noqa: E501
:type: Tags
"""

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Common requirements
# -----------------------
setuptools
wheel

# Project requirements
# -----------------------
Expand Down
1 change: 0 additions & 1 deletion tests/dev/dev_perfs_search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: UTF-8 -*-
#! python3 # noqa E265

# #############################################################################
Expand Down
15 changes: 9 additions & 6 deletions tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

"""Usage from the repo root folder:
```python
# for whole test
python -m unittest tests.test_authentication
# for specific
python -m unittest tests.test_authentication.TestAuthentication.test_other_language
```
:Example:
.. code-block:: python
# for whole test
python -m unittest tests.test_authentication
# for specific
python -m unittest tests.test_authentication.TestAuthentication.test_other_language
"""

# #############################################################################
Expand Down
15 changes: 9 additions & 6 deletions tests/test_limitations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

"""Usage from the repo root folder:
```python
# for whole test
python -m unittest tests.test_limitations
# for specific
python -m unittest tests.test_limitations.TestLimitations.test_limitations_create_basic
```
:Example:
.. code-block:: python
# for whole test
python -m unittest tests.test_limitations
# for specific
python -m unittest tests.test_limitations.TestLimitations.test_limitations_create_basic
"""

# #############################################################################
Expand Down
17 changes: 9 additions & 8 deletions tests/test_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,15 @@ def test_link_detailed(self):
# retrieve link
md_links = self.isogeo.metadata.links.listing(self.metadata_fixture_existing)
# pick one randomly
random_link = sample(md_links, 1)[0]
# get
online_link = self.isogeo.metadata.links.get(
metadata_id=self.metadata_fixture_existing._id,
link_id=random_link.get("_id"),
)
# check
self.assertIsInstance(online_link, Link)
if len(md_links):
random_link = sample(md_links, 1)[0]
# get
online_link = self.isogeo.metadata.links.get(
metadata_id=self.metadata_fixture_existing._id,
link_id=random_link.get("_id"),
)
# check
self.assertIsInstance(online_link, Link)

# -- PUT/PATCH --
def test_links_update(self):
Expand Down
15 changes: 9 additions & 6 deletions tests/test_metadatas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

"""Usage from the repo root folder:
```python
# for whole test
python -m unittest tests.test_metadatas
# for specific
python -m unittest tests.test_metadatas.TestMetadatas.test_metadatas_create
```
:Example:
.. code-block:: python
# for whole test
python -m unittest tests.test_metadatas
# for specific
python -m unittest tests.test_metadatas.TestMetadatas.test_metadatas_create
"""

# #############################################################################
Expand Down

0 comments on commit 0e9f733

Please sign in to comment.