generated from usnistgov/opensource-repo
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge feature/dap-add-contact into integration
- Loading branch information
Showing
7 changed files
with
130 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,21 +110,59 @@ def test_create_record(self): | |
with self.assertRaises(AlreadyExists): | ||
self.svc.create_record("goob") | ||
|
||
def hold_test_create_record_withdata(self): | ||
def test_create_record_withdata(self): | ||
self.create_service() | ||
self.assertTrue(not self.svc.dbcli.name_exists("gurn")) | ||
|
||
|
||
# goofy data | ||
prec = self.svc.create_record("gurn", {"color": "red"}, | ||
{"temper": "dark", "creatorisContact": "goob", | ||
"softwarelink": "http://..." }) # misspelled key | ||
self.assertEqual(prec.name, "gurn") | ||
self.assertEqual(prec.id, "mdsx:0003") | ||
self.assertEqual(prec.id, "mdsy:0003") | ||
self.assertEqual(prec.meta, {"creatorisContact": False, "resourceType": "data"}) | ||
for key in "_schema @context _extensionSchemas".split(): | ||
for key in "_schema @type author_count file_count reference_count".split(): | ||
self.assertIn(key, prec.data) | ||
self.assertEqual(prec.data['color'], "red") | ||
self.assertEqual(prec.data['doi'], "doi:88888/mdsx-0003") | ||
self.assertEqual(prec.data['@id'], "ark:/88434/mdsx-0003") | ||
self.assertNotIn('color', prec.data) | ||
self.assertNotIn('contactPoint', prec.data) | ||
self.assertEqual(prec.data['doi'], "doi:10.88888/mdsy-0003") | ||
self.assertEqual(prec.data['@id'], "ark:/88434/mdsy-0003") | ||
self.assertEqual(prec.data['nonfile_count'], 0) | ||
|
||
# some legit metadata but no legit identity info | ||
prec = self.svc.create_record("goob", {"title": "test"}, | ||
{"creatorIsContact": "TRUE", | ||
"softwareLink": "https://github.com/usnistgov/goob" }) | ||
self.assertEqual(prec.name, "goob") | ||
self.assertEqual(prec.id, "mdsy:0004") | ||
self.assertEqual(prec.meta, {"creatorisContact": True, "resourceType": "data", | ||
"softwareLink": "https://github.com/usnistgov/goob"}) | ||
self.assertEqual(prec.data['doi'], "doi:10.88888/mdsy-0004") | ||
self.assertEqual(prec.data['@id'], "ark:/88434/mdsy-0004") | ||
self.assertEqual(prec.data['nonfile_count'], 1) | ||
self.assertNotIn('contactPoint', prec.data) | ||
nerd = self.svc._store.open(prec.id) | ||
links = nerd.nonfiles | ||
self.assertEqual(len(links), 1) | ||
self.assertEqual(links.get(0)['accessURL'], prec.meta['softwareLink']) | ||
|
||
|
||
# inject some identity info into service and try again | ||
self.svc.who._md.update({"userName": "Gurn", "userLastName": "Cranston", "email": "[email protected]"}) | ||
prec = self.svc.create_record("cranston", {"title": "test"}, | ||
{"creatorIsContact": True, | ||
"softwareLink": "https://github.com/usnistgov/goob" }) | ||
self.assertEqual(prec.name, "cranston") | ||
self.assertEqual(prec.id, "mdsy:0005") | ||
self.assertEqual(prec.meta, {"creatorisContact": True, "resourceType": "data", | ||
"softwareLink": "https://github.com/usnistgov/goob"}) | ||
self.assertEqual(prec.data['doi'], "doi:10.88888/mdsy-0005") | ||
self.assertEqual(prec.data['@id'], "ark:/88434/mdsy-0005") | ||
self.assertEqual(prec.data['nonfile_count'], 1) | ||
self.assertIn('contactPoint', prec.data) | ||
self.assertEqual(prec.data['contactPoint'], {"@type": "vcard:Contact", "fn": "Gurn Cranston", | ||
"hasEmail": "mailto:[email protected]"}) | ||
|
||
|
||
def test_moderate_restype(self): | ||
self.create_service() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -688,6 +688,17 @@ def test_authenticate(self): | |
self.assertEqual(who.group, "nist") | ||
self.assertEqual(who.actor, "fed") | ||
self.assertEqual(who.agents, ["Unit testing agent"]) | ||
self.assertIsNone(who.get_prop("email")) | ||
|
||
token = jwt.encode({"sub": "fed", "userEmail": "[email protected]", "OU": "61"}, | ||
self.config['jwt_auth']['key'], algorithm="HS256") | ||
req['HTTP_AUTHORIZATION'] = "Bearer "+token | ||
who = self.app.authenticate(req) | ||
self.assertEqual(who.group, "nist") | ||
self.assertEqual(who.actor, "fed") | ||
self.assertEqual(who.agents, ["Unit testing agent"]) | ||
self.assertEqual(who.get_prop("email"), "[email protected]") | ||
self.assertEqual(who.get_prop("OU"), "61") | ||
|
||
|
||
def test_create_dmp(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,24 @@ def test_ctor(self): | |
self.assertEqual(agent.actor_type, "auto") | ||
self.assertEqual(agent.actor, "pdp") | ||
self.assertEqual(agent.agents, ["thing1", "thing2"]) | ||
self.assertEqual(dict(agent.iter_props()), {}) | ||
|
||
def test_props(self): | ||
agent = prov.PubAgent("ncnr", prov.PubAgent.AUTO, "pdp", ("thing1", "thing2"), | ||
email="[email protected]", lunch="tacos", likes=["mom"]) | ||
self.assertEqual(agent.agents, ["thing1", "thing2"]) | ||
self.assertEqual(dict(agent.iter_props()), | ||
{"email": "[email protected]", "lunch": "tacos", "likes": ["mom"]}) | ||
self.assertEqual(agent.get_prop("email"), "[email protected]") | ||
self.assertEqual(agent.get_prop("lunch"), "tacos") | ||
self.assertEqual(agent.get_prop("likes", "beer"), ["mom"]) | ||
self.assertIsNone(agent.get_prop("hairdo")) | ||
self.assertEqual(agent.get_prop("hairdo", "cueball"), "cueball") | ||
agent.set_prop("hairdo", "piece") | ||
self.assertEqual(agent.get_prop("hairdo", "cueball"), "piece") | ||
agent.set_prop("likes", "beer") | ||
self.assertEqual(agent.get_prop("likes"), "beer") | ||
|
||
|
||
def test_add_agent(self): | ||
agent = prov.PubAgent("ncnr", prov.PubAgent.AUTO, "pdp") | ||
|