def testGetByPath(self): domain = helper.getTestDomain("tall.h5") print("testGetByPath", domain) headers = helper.getRequestHeaders(domain=domain) req = helper.getEndpoint() + '/' rsp = requests.get(req, headers=headers) if rsp.status_code != 200: print("WARNING: Failed to get domain: {}. Is test data setup?".format(domain)) return # abort rest of test domainJson = json.loads(rsp.text) self.assertTrue("root" in domainJson) root_id = domainJson["root"] # Get group at /g1/g1.1 by using h5path params = {"h5path": "/g1/g1.1"} rsp = requests.get(req, headers=headers, params=params) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("id" in rspJson) g11id = helper.getUUIDByPath(domain, "/g1/g1.1") self.assertEqual(g11id, rspJson["id"]) self.assertTrue("root" in rspJson) self.assertEqual(root_id, rspJson["root"]) # Get dataset at /g1/g1.1/dset1.1.1 by using relative h5path params = {"h5path": "./g1/g1.1/dset1.1.1"} rsp = requests.get(req, headers=headers, params=params) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("id" in rspJson) d111id = helper.getUUIDByPath(domain, "/g1/g1.1/dset1.1.1") self.assertEqual(d111id, rspJson["id"]) self.assertTrue("root" in rspJson) self.assertEqual(root_id, rspJson["root"])
def getUUIDByPath(self, path): username = self.user1['username'] password = self.user1['password'] obj_uuid = helper.getUUIDByPath(self.domain, path, user=username, password=password) return obj_uuid
def testGetByPath(self): domain = helper.getTestDomain("tall.h5") print("testGetByPath", domain) headers = helper.getRequestHeaders(domain=domain) # verify domain exists req = helper.getEndpoint() + '/' rsp = requests.get(req, headers=headers) if rsp.status_code != 200: print("WARNING: Failed to get domain: {}. Is test data setup?". format(domain)) return # abort rest of test rspJson = json.loads(rsp.text) root_uuid = rspJson["root"] # get the group at "/g1/g1.1" h5path = "/g1/g1.1" req = helper.getEndpoint() + "/groups/" params = {"h5path": h5path} rsp = requests.get(req, headers=headers, params=params) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) for name in ("id", "hrefs", "attributeCount", "linkCount", "domain", "root", "created", "lastModified"): self.assertTrue(name in rspJson) # verify we get the same id when following the path via service calls g11id = helper.getUUIDByPath(domain, "/g1/g1.1") self.assertEqual(g11id, rspJson["id"]) # Try with a trailing slash h5path = "/g1/g1.1/" req = helper.getEndpoint() + "/groups/" params = {"h5path": h5path} rsp = requests.get(req, headers=headers, params=params) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertEqual(g11id, rspJson["id"]) # try relative h5path g1id = helper.getUUIDByPath(domain, "/g1/") h5path = "./g1.1" req = helper.getEndpoint() + "/groups/" + g1id params = {"h5path": h5path} rsp = requests.get(req, headers=headers, params=params) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertEqual(g11id, rspJson["id"]) # try a invalid link and verify a 404 is returened h5path = "/g1/foobar" req = helper.getEndpoint() + "/groups/" params = {"h5path": h5path} rsp = requests.get(req, headers=headers, params=params) self.assertEqual(rsp.status_code, 404) # try passing a path to a dataset and verify we get 404 h5path = "/g1/g1.1/dset1.1.1" req = helper.getEndpoint() + "/groups/" params = {"h5path": h5path} rsp = requests.get(req, headers=headers, params=params) self.assertEqual(rsp.status_code, 404) # try getting the path of the group req = helper.getEndpoint() + "/groups/" + g11id params = {"getalias": 1} rsp = requests.get(req, params=params, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("alias" in rspJson) self.assertEqual(rspJson["alias"], [ '/g1/g1.1', ])
def testGet(self): # test getting links from an existing domain domain = helper.getTestDomain("tall.h5") print("testGetDomain", domain) headers = helper.getRequestHeaders(domain=domain) # verify domain exists req = helper.getEndpoint() + '/' rsp = requests.get(req, headers=headers) if rsp.status_code != 200: print("WARNING: Failed to get domain: {}. Is test data setup?". format(domain)) return # abort rest of test rspJson = json.loads(rsp.text) root_uuid = rspJson["root"] self.assertTrue(root_uuid.startswith("g-")) # get the "/g1" group g1_2_uuid = helper.getUUIDByPath(domain, "/g1/g1.2") now = time.time() # get links for /g1/g1.2: req = helper.getEndpoint() + '/groups/' + g1_2_uuid + '/links' rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("hrefs" in rspJson) hrefs = rspJson["hrefs"] self.assertEqual(len(hrefs), 3) self.assertTrue("links" in rspJson) links = rspJson["links"] self.assertEqual(len(links), 2) g1_2_1_uuid = None extlink_file = None for link in links: self.assertTrue("class" in link) link_class = link["class"] if link_class == 'H5L_TYPE_HARD': for name in ("target", "created", "collection", "class", "id", "title", "href"): self.assertTrue(name in link) g1_2_1_uuid = link["id"] self.assertTrue(g1_2_1_uuid.startswith("g-")) self.assertEqual(link["title"], "g1.2.1") self.assertTrue(link["created"] < now - 10) else: self.assertEqual(link_class, 'H5L_TYPE_EXTERNAL') for name in ("created", "class", "h5domain", "h5path", "title", "href"): self.assertTrue(name in link) self.assertEqual(link["title"], "extlink") extlink_file = link["h5domain"] self.assertEqual(extlink_file, "somefile") self.assertEqual(link["h5path"], "somepath") self.assertTrue(link["created"] < now - 10) self.assertTrue(g1_2_1_uuid is not None) self.assertTrue(extlink_file is not None) self.assertEqual(helper.getUUIDByPath(domain, "/g1/g1.2/g1.2.1"), g1_2_1_uuid) # get link by title req = helper.getEndpoint() + '/groups/' + g1_2_1_uuid + '/links/slink' rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) for name in ("created", "lastModified", "link", "hrefs"): self.assertTrue(name in rspJson) # created should be same as lastModified for links self.assertEqual(rspJson["created"], rspJson["lastModified"]) self.assertTrue(rspJson["created"] < now - 10) hrefs = rspJson["hrefs"] self.assertEqual(len(hrefs), 3) link = rspJson["link"] for name in ("title", "h5path", "class"): self.assertTrue(name in link) self.assertEqual(link["class"], 'H5L_TYPE_SOFT') self.assertFalse("h5domain" in link) # only for external links self.assertEqual(link["title"], "slink") self.assertEqual(link["h5path"], "somevalue")