Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions magma/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ def set_restricted_access(self):
accconst.text = "Restricted Access Online: Access granted to Licensee only. Available only to MIT affiliates."
return self

def add_keywords(self):
keywords = self._get_path('idinfo/keywords')
theme = etree.SubElement(keywords, 'theme')
etree.SubElement(theme, 'themekt')
etree.SubElement(theme, 'themekey')
place = etree.SubElement(keywords, 'place')
etree.SubElement(place, 'placekt')
etree.SubElement(place, 'placekey')
return self

def _get_path(self, path):
return get_path(path, self.root)

Expand All @@ -167,6 +177,7 @@ def process(fgdc, ds=None):
set_name(ds.name)
metadata.set_distribution().\
set_metadata_contact().\
add_keywords().\
ensure_elements()
return metadata

Expand Down
21 changes: 20 additions & 1 deletion tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,25 @@ def test_sets_restricted_access():
assert r.doc.find('idinfo/accconst').text == "Restricted Access Online: Access granted to Licensee only. Available only to MIT affiliates."


def test_adds_empty_keyword():
r = FGDC(StringIO("""
<metadata>
<idinfo>
<keywords>
<theme>
<themekey>Foo</themekey>
</theme>
<place>
<placekey>Bar</placekey>
</place>
</keywords>
</idinfo>
</metadata>"""))
r.add_keywords()
assert len(r.doc.findall('idinfo/keywords/theme')) == 2
assert len(r.doc.findall('idinfo/keywords/place')) == 2


def test_process_ensures_elements_exist(shp):
r = process(StringIO("<metadata/>"), shp)
assert r.doc.find('idinfo/keywords/theme/themekey') is not None
assert r.doc.find('idinfo/descript/purpose') is not None