Skip to content

Commit

Permalink
Merge pull request #15 from usnistgov/fix/keyword
Browse files Browse the repository at this point in the history
 keyword lowercase and plural + test for multiple keywords research
  • Loading branch information
RayPlante authored Aug 21, 2024
2 parents ad36a6c + e249823 commit 4487717
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/nistoar/midas/dap/service/mds3.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def _summarize(self, nerd: NERDResource):
out["contactPoint"] = resmd["contactPoint"]
if 'landingPage' in resmd:
out["landingPage"] = resmd["landingPage"]
out["keyword"] = resmd.get("keyword", [])
out["keywords"] = resmd.get("keyword", [])
out["theme"] = list(set(resmd.get("theme", []) + [t.get('tag') for t in resmd.get('topic', [])]))
if resmd.get('responsibleOrganization'):
out['responsibleOrganization'] = list(set(
Expand Down
2 changes: 2 additions & 0 deletions python/tests/nistoar/midas/dap/service/test_mds3_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def test_put_patch(self):
self.assertIs(resp['meta']["creatorisContact"], False)
self.assertEqual(resp['data']['@id'], 'ark:/88434/mds3-0001')
self.assertEqual(resp['data']['doi'], 'doi:10.88888/mds3-0001')
self.assertEqual(resp['data']['keywords'], ['testing'])
self.assertNotIn('authors', resp['data']) # because ['data'] is just a summary
self.assertIn('contactPoint', resp['data']) # this is included in ['data'] summary

Expand All @@ -273,6 +274,7 @@ def test_put_patch(self):
[ "nrdp:PublicDataResource", "dcat:Resource" ])
self.assertIn('_schema', resp)
self.assertIn('_extensionSchemas', resp)
self.assertEqual(resp['keyword'], ['testing'])
self.assertNotIn('components', resp)
self.assertNotIn('authors', resp)
self.assertNotIn('description', resp)
Expand Down
2 changes: 1 addition & 1 deletion python/tests/nistoar/midas/dbio/data/asc_keyandtheme.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$and": [
{
"data.keyword": { "$in": ["Ray"] }
"data.keywords": { "$in": ["Ray"] }
},
{
"data.theme": { "$in": ["Gretchen"] }
Expand Down
15 changes: 15 additions & 0 deletions python/tests/nistoar/midas/dbio/data/asc_orkeywords.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$and": [
{
"$or": [
{
"data.keywords": { "$in": ["Ray"] }
},
{
"data.keywords": { "$in": ["Bob"] }
}

]
}
]
}
13 changes: 11 additions & 2 deletions python/tests/nistoar/midas/dbio/test_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
asc_dates = datadir / 'asc_dates.json'
asc_text = datadir / 'asc_text.json'
asc_keyandtheme = datadir / 'asc_keyandtheme.json'
asc_orkeywords = datadir / 'asc_orkeywords.json'

with open(asc_or, 'r') as file:
constraint_or = json.load(file)
Expand All @@ -44,6 +45,9 @@
with open(asc_keyandtheme, 'r') as file:
constraint_keyandtheme = json.load(file)

with open(asc_orkeywords, 'r') as file:
constraint_orkeywords = json.load(file)

@test.skipIf(not os.environ.get('MONGO_TESTDB_URL'), "test mongodb not available")
class TestInMemoryDBClientFactory(test.TestCase):

Expand Down Expand Up @@ -340,7 +344,7 @@ def test_adv_select_records(self):
"message": "draft created"
},
"data": {
"keyword": ["Chemistry", "Bob"],
"keywords": ["Chemistry", "Bob"],
"theme": ["Physics", "Deo"]

}
Expand All @@ -358,7 +362,7 @@ def test_adv_select_records(self):
"message": "draft created"
},
"data": {
"keyword": ["Ray", "Bob"],
"keywords": ["Ray", "Bob"],
"theme": ["Gretchen", "Deo"]

}
Expand Down Expand Up @@ -435,6 +439,11 @@ def test_adv_select_records(self):
self.assertEqual(len(recs), 1)
self.assertEqual(recs[0].id, "pdr0:0006")

recs = list(self.cli.adv_select_records(constraint_orkeywords, base.ACLs.READ))
self.assertEqual(len(recs), 2)
self.assertEqual(recs[0].id, "pdr0:0002")
self.assertEqual(recs[1].id, "pdr0:0006")



def test_action_log_io(self):
Expand Down

0 comments on commit 4487717

Please sign in to comment.