Skip to content

Commit

Permalink
helper should handle milliseconds <= 6 digits #85
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Aug 22, 2019
1 parent e0b2285 commit 9c513fe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions isogeo_pysdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def hlpr_date_as_datetime(cls, in_date: str) -> datetime:
out_date = datetime.strptime(
in_date, _dtm_data
) # events datetimes (=dates)
elif len(in_date) == 32 and "." in in_date:
elif len(in_date) > 25 and len(in_date) <= 32 and "." in in_date:
out_date = datetime.strptime(
in_date, _dtm_metadata
) # metadata timestamps with 6 milliseconds
Expand All @@ -856,7 +856,7 @@ def hlpr_date_as_datetime(cls, in_date: str) -> datetime:
)
else:
raise TypeError(
"This format of timestamps is not recognized: {}.Try by yourself!".format(
"This format of timestamps is not recognized: {}. Try by yourself!".format(
in_date
)
)
Expand Down
14 changes: 13 additions & 1 deletion tests/test_metadatas.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@


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


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

utils = IsogeoUtils()

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

Expand Down Expand Up @@ -146,6 +148,16 @@ def test_metadatas_in_search_results(self):
self.assertEqual(md.get("created"), metadata.created)
self.assertEqual(md.get("modified"), metadata.modified)

# -- HELPERS
# dates
md_date_creation = utils.hlpr_date_as_datetime(metadata._created)
self.assertEqual(int(metadata._created[:4]), md_date_creation.year)
md_date_modification = utils.hlpr_date_as_datetime(metadata._modified)
self.assertEqual(int(metadata._modified[:4]), md_date_modification.year)
if metadata.created:
ds_date_creation = utils.hlpr_date_as_datetime(metadata.created)
self.assertEqual(int(metadata.created[:4]), ds_date_creation.year)

# def test_search_specific_mds_bad(self):
# """Searches filtering on specific metadata."""
# # get random metadata within a small search
Expand Down
9 changes: 7 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,10 @@ def test_set_base_url_bad_parameter(self):
"""Raise error if platform parameter is bad."""
with self.assertRaises(ValueError):
self.utils.set_base_url(platform="skynet")
self.utils.set_base_url(platform=environ.get("ISOGEO_PLATFORM", "qa"))

# -- URLs Builders - edit (app) ------------------------------------------
def test_get_edit_url_ok(self):
"""Test URL builder for edition link on APP"""
self.utils.set_base_url(platform=environ.get("ISOGEO_PLATFORM", "qa"))
url = self.utils.get_edit_url(
md_id="0269803d50c446b09f5060ef7fe3e22b",
md_type="vector-dataset",
Expand Down Expand Up @@ -368,6 +366,13 @@ def test_helper_datetimes(self):
self.assertIsInstance(md_date, datetime)
self.assertEqual(md_date.year, 2019)

# metadata timestamps str - 6 milliseconds
md_date_lesser = self.utils.hlpr_date_as_datetime(
"2017-12-01T16:36:28.74561+00:00"
)
self.assertIsInstance(md_date_lesser, datetime)
self.assertEqual(md_date_lesser.year, 2017)

# metadata timestamps str - more than 6 milliseconds
md_date_larger = self.utils.hlpr_date_as_datetime(
"2019-06-13T16:21:38.1917618+00:00"
Expand Down

0 comments on commit 9c513fe

Please sign in to comment.