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.
- Loading branch information
Showing
3 changed files
with
167 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -813,6 +813,45 @@ def test_get_sw_desc_for(self): | |
"accessURL": "https://bitbucket.com/foo/bar" | ||
}) | ||
|
||
def test_clear_data(self): | ||
self.create_service() | ||
prec = self.svc.create_record("goob") | ||
pdrid = "ark:/88434/%s-%s" % tuple(prec.id.split(":")) | ||
nerd = self.svc.get_nerdm_data(prec.id) | ||
self.assertEqual(set(nerd.keys()), | ||
{"_schema", "@id", "doi", "_extensionSchemas", "@context", "@type"}) | ||
|
||
nerd = self.svc.update_data(prec.id, | ||
{"landingPage": "https://example.com", | ||
"contactPoint": { "fn": "Gurn Cranston", "hasEmail": "mailto:[email protected]"}}) | ||
self.assertEqual(set(nerd.keys()), | ||
{"_schema", "@id", "doi", "_extensionSchemas", "@context", "@type", | ||
"contactPoint", "landingPage"}) | ||
self.assertEqual(set(nerd["contactPoint"].keys()), {"@type", "fn", "hasEmail"}) | ||
|
||
with self.assertRaises(PartNotAccessible): | ||
self.assertIs(self.svc.clear_data(prec.id, "goober"), False) | ||
with self.assertRaises(PartNotAccessible): | ||
self.assertIs(self.svc.clear_data(prec.id, "contactPoint/hasEmail"), True) | ||
nerd = self.svc.get_nerdm_data(prec.id) | ||
self.assertEqual(set(nerd.keys()), | ||
{"_schema", "@id", "doi", "_extensionSchemas", "@context", "@type", | ||
"contactPoint", "landingPage"}) | ||
self.assertEqual(set(nerd["contactPoint"].keys()), {"@type", "fn", "hasEmail"}) | ||
|
||
self.assertIs(self.svc.clear_data(prec.id, "landingPage"), True) | ||
nerd = self.svc.get_nerdm_data(prec.id) | ||
self.assertEqual(set(nerd.keys()), | ||
{"_schema", "@id", "doi", "_extensionSchemas", "@context", "@type", | ||
"contactPoint"}) | ||
self.assertIs(self.svc.clear_data(prec.id, "references"), False) | ||
|
||
self.assertIs(self.svc.clear_data(prec.id), True) | ||
nerd = self.svc.get_nerdm_data(prec.id) | ||
self.assertEqual(set(nerd.keys()), | ||
{"_schema", "@id", "doi", "_extensionSchemas", "@context", "@type"}) | ||
|
||
|
||
def test_update(self): | ||
rec = read_nerd(pdr2210) | ||
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 |
---|---|---|
|
@@ -383,7 +383,7 @@ def test_put_patch(self): | |
self.assertNotIn("downloadURL", resp) | ||
|
||
self.resp = [] | ||
path = id + '/data/components[file_1]' | ||
path = id + '/data/components/file_1' | ||
req = { | ||
'REQUEST_METHOD': 'GET', | ||
'PATH_INFO': self.rootpath + path | ||
|
@@ -443,6 +443,93 @@ def test_put_patch(self): | |
self.assertIn('description', resp) | ||
self.assertEqual(resp['rights'], "What ever.") | ||
|
||
def test_delete(self): | ||
testnerd = read_nerd(pdr2210) | ||
res = deepcopy(testnerd) | ||
del res['references'] | ||
del res['components'] | ||
del res['@id'] | ||
del res['_schema'] | ||
del res['_extensionSchemas'] | ||
|
||
path = "" | ||
req = { | ||
'REQUEST_METHOD': 'POST', | ||
'PATH_INFO': self.rootpath + path | ||
} | ||
req['wsgi.input'] = StringIO(json.dumps({"data": { "contactPoint": res['contactPoint'], | ||
"keyword": [ "testing" ], | ||
"landingPage": "https://example.com/" }, | ||
"meta": { "creatorisContact": "false" }, | ||
"name": "OptSortSph" })) | ||
hdlr = self.app.create_handler(req, self.start, path, nistr) | ||
self.assertTrue(isinstance(hdlr, prj.ProjectSelectionHandler)) | ||
self.assertNotEqual(hdlr.cfg, {}) | ||
self.assertEqual(hdlr._path, "") | ||
body = hdlr.handle() | ||
|
||
self.assertIn("201 ", self.resp[0]) | ||
resp = self.body2dict(body) | ||
self.assertEqual(resp['name'], "OptSortSph") | ||
self.assertEqual(resp['id'], "mds3:0001") | ||
self.assertEqual(resp['data']['@id'], 'ark:/88434/mds3-0001') | ||
self.assertEqual(resp['data']['doi'], 'doi:10.88888/mds3-0001') | ||
recid = resp['id'] | ||
|
||
self.resp = [] | ||
path = recid + '/data' | ||
req = { | ||
'REQUEST_METHOD': 'GET', | ||
'PATH_INFO': self.rootpath + path | ||
} | ||
hdlr = self.app.create_handler(req, self.start, path, nistr) | ||
self.assertTrue(isinstance(hdlr, prj.ProjectDataHandler)) | ||
self.assertEqual(hdlr._path, "") | ||
body = hdlr.handle() | ||
self.assertIn("200 ", self.resp[0]) | ||
resp = self.body2dict(body) | ||
self.assertEqual(resp['@id'], 'ark:/88434/mds3-0001') | ||
self.assertEqual(resp['doi'], 'doi:10.88888/mds3-0001') | ||
self.assertEqual(resp['contactPoint'], | ||
{"fn": "Zachary Levine", "@type": "vcard:Contact", | ||
"hasEmail": "mailto:[email protected]" }) | ||
self.assertEqual(resp['@type'], | ||
[ "nrdp:PublicDataResource", "dcat:Resource" ]) | ||
self.assertEqual(resp['landingPage'], "https://example.com/") | ||
self.assertEqual(resp['keyword'], ["testing"]) | ||
|
||
self.resp = [] | ||
path = recid + '/data/landingPage' | ||
req = { | ||
'REQUEST_METHOD': 'DELETE', | ||
'PATH_INFO': self.rootpath + path | ||
} | ||
hdlr = self.app.create_handler(req, self.start, path, nistr) | ||
self.assertTrue(isinstance(hdlr, prj.ProjectDataHandler)) | ||
self.assertEqual(hdlr._path, "landingPage") | ||
body = hdlr.handle() | ||
self.assertIn("201 ", self.resp[0]) | ||
resp = self.body2dict(body) | ||
self.assertIs(resp, True) | ||
|
||
|
||
self.resp = [] | ||
path = recid + '/data' | ||
req = { | ||
'REQUEST_METHOD': 'GET', | ||
'PATH_INFO': self.rootpath + path | ||
} | ||
hdlr = self.app.create_handler(req, self.start, path, nistr) | ||
self.assertTrue(isinstance(hdlr, prj.ProjectDataHandler)) | ||
self.assertEqual(hdlr._path, "") | ||
body = hdlr.handle() | ||
self.assertIn("200 ", self.resp[0]) | ||
resp = self.body2dict(body) | ||
self.assertNotIn("landingPage", resp) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|