Skip to content

Commit

Permalink
Metadata - Improve title_or_name method fix - Merge #109
Browse files Browse the repository at this point in the history
Metadata - Improve title_or_name method fix #108
  • Loading branch information
Guts committed Sep 25, 2019
2 parents 029d3b8 + 56994a6 commit 180866d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion isogeo_pysdk/models/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,8 +1301,13 @@ def title_or_name(self, slugged: bool = False) -> str:
"""
if self._title:
title_or_name = self._title
else:
elif self._name:
title_or_name = self._name
else:
logger.warning(
"Metadata has no title nor name. So this method is useless..."
)
return None

# slugify
if slugged:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_metadatas.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,35 @@ def tearDownClass(cls):

# -- TESTS ---------------------------------------------------------
# -- MODEL --
def test_metadatas_title_or_name(self):
"""Model integrated method to retrive title or name"""
# title but no name
md_title_no_name = Metadata(
title="BD Topo® - My title really inspires the masses - Villenave d'Ornon"
)
self.assertEqual(
md_title_no_name.title_or_name(),
"BD Topo® - My title really inspires the masses - Villenave d'Ornon",
)
self.assertEqual(
md_title_no_name.title_or_name(1),
"bd-topo-my-title-really-inspires-the-masses-villenave-dornon",
)

# no title but name - 1
md_no_title_name = Metadata(name="reference.roads_primary")
self.assertEqual(md_no_title_name.title_or_name(), "reference.roads_primary")

# no title but name - 2
md_no_title_name = Metadata(name="reference chemins de forêt.shp")
self.assertEqual(
md_no_title_name.title_or_name(1), "reference-chemins-de-foretshp"
)

# no title nor name
md_no_title_no_name = Metadata()
self.assertIsNone(md_no_title_no_name.title_or_name(0))
self.assertIsNone(md_no_title_no_name.title_or_name(1))

# -- GET --
def test_metadatas_exists(self):
Expand Down

0 comments on commit 180866d

Please sign in to comment.