def testPut(self): # create domain domain = 'valueput.datasettest.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.put(req, headers=headers) self.failUnlessEqual(rsp.status_code, 201) # creates domain #create 1d dataset payload = {'type': 'H5T_STD_I32LE', 'shape': 10} req = self.endpoint + "/datasets/" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset1UUID = rspJson['id'] self.assertTrue(helper.validateId(dset1UUID)) # link new dataset as 'dset1' ok = helper.linkObject(domain, dset1UUID, 'dset1') self.assertTrue(ok) req = self.endpoint + "/datasets/" + dset1UUID + "/value" data = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] payload = {'type': 'H5T_STD_I32LE', 'shape': 10, 'value': data} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 200) # read back the data readData = helper.readDataset(domain, dset1UUID) self.failUnlessEqual(readData, data) # verify we got back what we started with #create 2d dataset payload = {'type': 'H5T_STD_I32LE', 'shape': (10, 10)} req = self.endpoint + "/datasets/" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset2UUID = rspJson['id'] self.assertTrue(helper.validateId(dset2UUID)) # link new dataset as 'dset2' ok = helper.linkObject(domain, dset2UUID, 'dset2') self.assertTrue(ok) req = self.endpoint + "/datasets/" + dset2UUID + "/value" data = [] for i in range(10): row = [] for j in range(10): row.append(i * 10 + j) data.append(row) payload = {'type': 'H5T_STD_I32LE', 'shape': [10, 10], 'value': data} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 200) # read back the data readData = helper.readDataset(domain, dset2UUID) self.failUnlessEqual(readData, data) # verify we got back what we started with
def testDeleteAnonymous(self): # test delete works with anonymous dataset domain = 'tall_dset22_deleted.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) g2_uuid = helper.getUUID(domain, root_uuid, 'g2') self.assertTrue(helper.validateId(g2_uuid)) d22_uuid = helper.getUUID(domain, g2_uuid, 'dset2.2') self.assertTrue(helper.validateId(d22_uuid)) # delete g2, that will make dataset anonymous req = self.endpoint + "/groups/" + g2_uuid headers = {'host': domain} rsp = requests.delete(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) # verify that a GET on the dataset succeeds still req = helper.getEndpoint() + "/datasets/" + d22_uuid headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) # delete dataset... req = self.endpoint + "/datasets/" + d22_uuid headers = {'host': domain} rsp = requests.delete(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) # verify that a GET on the dataset fails req = helper.getEndpoint() + "/datasets/" + d22_uuid headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 410)
def testPut(self): # create domain domain = 'valueput.datasettest.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.put(req, headers=headers) self.failUnlessEqual(rsp.status_code, 201) # creates domain #create 1d dataset payload = {'type': 'H5T_STD_I32LE', 'shape': 10} req = self.endpoint + "/datasets" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset1UUID = rspJson['id'] self.assertTrue(helper.validateId(dset1UUID)) # link new dataset as 'dset1' ok = helper.linkObject(domain, dset1UUID, 'dset1') self.assertTrue(ok) req = self.endpoint + "/datasets/" + dset1UUID + "/value" data = [2,3,5,7,11,13,17,19,23,29] # payload = {'type': 'H5T_STD_I32LE', 'shape': 10, 'value': data } payload = { 'value': data } headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 200) # read back the data readData = helper.readDataset(domain, dset1UUID) self.failUnlessEqual(readData, data) # verify we got back what we started with #create 2d dataset payload = {'type': 'H5T_STD_I32LE', 'shape': (10,10)} req = self.endpoint + "/datasets" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset2UUID = rspJson['id'] self.assertTrue(helper.validateId(dset2UUID)) # link new dataset as 'dset2' ok = helper.linkObject(domain, dset2UUID, 'dset2') self.assertTrue(ok) req = self.endpoint + "/datasets/" + dset2UUID + "/value" data = [] for i in range(10): row = [] for j in range(10): row.append(i*10 + j) data.append(row) payload = { 'value': data } headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 200) # read back the data readData = helper.readDataset(domain, dset2UUID) self.failUnlessEqual(readData, data) # verify we got back what we started with
def testGetDomain(self): domain = helper.getTestDomain("tall.h5") print("testGetDomain", 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 self.assertEqual(rsp.headers['content-type'], 'application/json; charset=utf-8') rspJson = json.loads(rsp.text) for name in ("lastModified", "created", "hrefs", "root", "owner", "class"): self.assertTrue(name in rspJson) now = time.time() self.assertTrue(rspJson["created"] < now - 10) self.assertTrue(rspJson["lastModified"] < now - 10) self.assertEqual(len(rspJson["hrefs"]), 7) self.assertTrue(rspJson["root"].startswith("g-")) self.assertTrue(rspJson["owner"]) self.assertEqual(rspJson["class"], "domain") self.assertFalse( "num_groups" in rspJson) # should only show up with the verbose param root_uuid = rspJson["root"] helper.validateId(root_uuid) # verify that passing domain as query string works as well del headers["X-Hdf-domain"] params = {"host": domain} rsp = requests.get(req, params=params, headers=headers) self.assertEqual(rsp.status_code, 200) self.assertEqual(rsp.headers['content-type'], 'application/json; charset=utf-8') rspJson = json.loads(rsp.text) root_uuid_2 = rspJson["root"] self.assertEqual(root_uuid, root_uuid_2) # same deal using the "domain" param params = {"domain": domain} rsp = requests.get(req, params=params, headers=headers) self.assertEqual(rsp.status_code, 200) self.assertEqual(rsp.headers['content-type'], 'application/json; charset=utf-8') rspJson = json.loads(rsp.text) root_uuid_3 = rspJson["root"] self.assertEqual(root_uuid, root_uuid_3) # verify that invalid domain fails domain = domain[1:] # strip off the '/' params = {"domain": domain} rsp = requests.get(req, params=params, headers=headers) self.assertEqual(rsp.status_code, 400)
def testPutVLenInt(self): # Test PUT value for 1d attribute with variable length int types print("testPutVLenInt", self.base_domain) headers = helper.getRequestHeaders(domain=self.base_domain) req = self.endpoint + '/' # Get root uuid rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) root_uuid = rspJson["root"] helper.validateId(root_uuid) # create dataset vlen_type = {"class": "H5T_VLEN", "base": { "class": "H5T_INTEGER", "base": "H5T_STD_I32LE"}} payload = {'type': vlen_type, 'shape': [4,]} req = self.endpoint + "/datasets" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset_uuid = rspJson['id'] self.assertTrue(helper.validateId(dset_uuid)) # link new dataset as 'dset' name = 'dset' req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {"id": dset_uuid} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 201) # write values to dataset data = [[1,], [1,2], [1,2,3], [1,2,3,4]] req = self.endpoint + "/datasets/" + dset_uuid + "/value" payload = { 'value': data } rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 200) # read values from dataset rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("hrefs" in rspJson) self.assertTrue("value" in rspJson) value = rspJson["value"] self.assertEqual(len(value), 4) for i in range(4): self.assertEqual(value[i], data[i]) # read back a selection params = {"select": "[2:3]"} rsp = requests.get(req, headers=headers, params=params) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("hrefs" in rspJson) self.assertTrue("value" in rspJson) value = rspJson["value"] self.assertEqual(len(value), 1) self.assertEqual(value[0], data[2])
def testGetReadOnly(self): domain = 'tall_ro.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) helper.validateId(rspJson["root"])
def testPutVLenString(self): # Test PUT value for 1d attribute with variable length string types print("testPutVLenString", self.base_domain) headers = helper.getRequestHeaders(domain=self.base_domain) req = self.endpoint + '/' # Get root uuid rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) root_uuid = rspJson["root"] helper.validateId(root_uuid) # create dataset vlen_type = { "class": "H5T_STRING", "charSet": "H5T_CSET_ASCII", "strPad": "H5T_STR_NULLTERM", "length": "H5T_VARIABLE" } payload = { 'type': vlen_type, 'shape': [ 4, ] } req = self.endpoint + "/datasets" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset_uuid = rspJson['id'] self.assertTrue(helper.validateId(dset_uuid)) # link new dataset as 'dset' name = 'dset' req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {"id": dset_uuid} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 201) # write values to dataset data = ["This is", "a variable length", "string", "array"] req = self.endpoint + "/datasets/" + dset_uuid + "/value" payload = {'value': data} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 200) # read values from dataset rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("hrefs" in rspJson) self.assertTrue("value" in rspJson) value = rspJson["value"] self.assertEqual(len(value), 4) for i in range(4): self.assertEqual(value[i], data[i])
def testGetDomain(self): domain = 'tall.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) self.failUnlessEqual(rsp.headers['content-type'], 'application/json') rspJson = json.loads(rsp.text) helper.validateId(rspJson["root"])
def testPutAttributeDatatype(self): # Test creation/deletion of datatype obj print("testPutAttributeDatatype", self.base_domain) headers = helper.getRequestHeaders(domain=self.base_domain) req = self.endpoint + '/' # Get root uuid rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) root_uuid = rspJson["root"] helper.validateId(root_uuid) # create a committed type obj data = {"type": "H5T_IEEE_F32LE"} req = self.endpoint + '/datatypes' rsp = requests.post(req, data=json.dumps(data), headers=headers) self.assertEqual(rsp.status_code, 201) rspJson = json.loads(rsp.text) self.assertEqual(rspJson["attributeCount"], 0) ctype_id = rspJson["id"] self.assertTrue(helper.validateId(ctype_id)) # link the new datatype name = "dtype_with_attribute" req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {"id": ctype_id} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 201) # add an attribute attr_name = "attr" attr_payload = {'type': 'H5T_STD_I32LE', 'value': 42} req = self.endpoint + "/datatypes/" + ctype_id + "/attributes/" + attr_name rsp = requests.put(req, data=json.dumps(attr_payload), headers=headers) self.assertEqual(rsp.status_code, 201) # created # read back the obj req = self.endpoint + '/datatypes/' + ctype_id rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("id" in rspJson) self.assertEqual(rspJson["id"], ctype_id) self.assertFalse("attributes" in rspJson) # read back the obj with attributes params = {"include_attrs": 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) self.assertEqual(rspJson["id"], ctype_id) self.assertTrue("attributes" in rspJson) attrs = rspJson["attributes"] self.assertTrue("attr" in attrs)
def testPutVLenCompound(self): # Test PUT value for 1d attribute with variable length int types print("testPutVLenCompound", self.base_domain) headers = helper.getRequestHeaders(domain=self.base_domain) req = self.endpoint + '/' # Get root uuid rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) root_uuid = rspJson["root"] helper.validateId(root_uuid) # create dataset fields = [ {"type": {"class": "H5T_INTEGER", "base": "H5T_STD_U64BE"}, "name": "VALUE1"}, {"type": {"class": "H5T_FLOAT", "base": "H5T_IEEE_F64BE"}, "name": "VALUE2"}, {"type": {"class": "H5T_ARRAY", "dims": [2], "base": {"class": "H5T_STRING", "charSet": "H5T_CSET_ASCII", "strPad": "H5T_STR_NULLTERM", "length": "H5T_VARIABLE"}}, "name": "VALUE3"}] datatype = {'class': 'H5T_COMPOUND', 'fields': fields } payload = {'type': datatype, 'shape': [4,]} req = self.endpoint + "/datasets" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset_uuid = rspJson['id'] self.assertTrue(helper.validateId(dset_uuid)) # link new dataset as 'dset' name = 'dset' req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {"id": dset_uuid} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 201) # write values to dataset data = [] for i in range(4): e = [i+1, i+1/10.0, ["Hi! "*(i+1), "Bye!" *(i+1)]] data.append(e) req = self.endpoint + "/datasets/" + dset_uuid + "/value" payload = { 'value': data } rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 200) # read values from dataset rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("hrefs" in rspJson) self.assertTrue("value" in rspJson) value = rspJson["value"] self.assertEqual(len(value), 4)
def testGetInfo(self): req = self.endpoint + "/info" print("req", req) rsp = requests.get(req) self.assertEqual(rsp.status_code, 200) self.assertEqual(rsp.headers['content-type'], 'application/json') rsp_json = json.loads(rsp.text) helper.validateId(rsp_json["id"]) self.assertEqual(rsp_json["active_dn_count"], 0) self.assertEqual(rsp_json["active_sn_count"], 0) self.assertEqual(rsp_json["target_dn_count"], 4) self.assertEqual(rsp_json["target_sn_count"], 4) self.assertEqual(rsp_json["cluster_state"], "INITIALIZING")
def testGetDomainVerbose(self): domain = helper.getTestDomain("tall.h5") print("testGetDomainVerbose", domain) headers = helper.getRequestHeaders(domain=domain) req = helper.getEndpoint() + '/' params = {"verbose": 1} rsp = requests.get(req, params=params, headers=headers) if rsp.status_code == 404: print("WARNING: Failed to get domain: {}. Is test data setup?". format(domain)) return # abort rest of test self.assertEqual(rsp.status_code, 200) self.assertEqual(rsp.headers['content-type'], 'application/json; charset=utf-8') rspJson = json.loads(rsp.text) for name in ("lastModified", "created", "hrefs", "root", "owner", "class"): self.assertTrue(name in rspJson) now = time.time() self.assertTrue(rspJson["created"] < now - 10) self.assertTrue(rspJson["lastModified"] < now - 10) self.assertEqual(len(rspJson["hrefs"]), 7) self.assertTrue(rspJson["root"].startswith("g-")) self.assertTrue(rspJson["owner"]) self.assertEqual(rspJson["class"], "domain") root_uuid = rspJson["root"] helper.validateId(root_uuid) # restore when sqlite changes are complete self.assertTrue("num_groups" in rspJson) self.assertEqual(rspJson["num_groups"], 6) self.assertTrue("num_datasets" in rspJson) self.assertEqual(rspJson["num_datasets"], 4) self.assertTrue("num_datatypes" in rspJson) self.assertEqual(rspJson["num_datatypes"], 0) self.assertTrue("allocated_bytes" in rspJson) # test that allocated_bytes falls in a given range self.assertEqual(rspJson["allocated_bytes"], 580) # total_size may change slightly based on specifics of JSON serialization self.assertTrue(rspJson["total_size"] > 5000) self.assertTrue(rspJson["total_size"] < 7000) # TODO - num_chunks should be present self.assertTrue("num_objects" in rspJson) self.assertTrue(rspJson["num_objects"], 14)
def testGetVlen(self): domain = 'vlen_attr.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint() + "/datasets/" + dset_uuid + "/attributes/A1" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 1) self.assertEqual(shape['dims'][0], 2) typeItem = rspJson['type'] self.assertEqual(typeItem['class'], 'H5T_VLEN') baseType = typeItem['base'] self.assertEqual(baseType['class'], 'H5T_INTEGER') self.assertEqual(baseType['base'], 'H5T_STD_I32LE') #verify data returned value = rspJson['value'] self.assertEqual(len(value), 2) self.assertEqual(len(value[1]), 12) self.assertEqual(value[1][11], 144)
def testGetFixedString(self): domain = 'fixed_string_attr.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint() + "/datasets/" + dset_uuid + "/attributes/A1" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 1) self.assertEqual(shape['dims'][0], 4) typeItem = rspJson['type'] self.assertEqual(typeItem['class'], 'H5T_STRING') self.assertEqual(typeItem['cset'], 'H5T_CSET_ASCII') self.assertEqual(typeItem['order'], 'H5T_ORDER_NONE') self.assertEqual(typeItem['strsize'], 7) self.assertEqual(typeItem['strpad'], 'H5T_STR_NULLPAD') self.assertTrue('value' in rspJson) value = rspJson['value'] self.assertEqual(len(value), 4) self.assertEqual(value[0], "Parting") self.assertEqual(value[1], "is such") self.assertEqual(value[2], "sweet") self.assertEqual(value[3], "sorrow.")
def testGetArray(self): domain = 'array_attr.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint() + "/datasets/" + dset_uuid + "/attributes/A1" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 1) self.assertEqual(shape['dims'][0], 4) typeItem = rspJson['type'] self.assertEqual(typeItem['class'], 'H5T_ARRAY') self.assertTrue('dims' in typeItem) typeShape = typeItem['dims'] self.assertEqual(len(typeShape), 2) self.assertEqual(typeShape[0], 3) self.assertEqual(typeShape[1], 5) typeBase = typeItem['base'] self.assertEqual(typeBase['class'], 'H5T_INTEGER') self.assertEqual(typeBase['base'], 'H5T_STD_I64LE') # bug! - unable to read value from attribute with array type # code is not returning 'value' key in this case # h5py issue: https://github.com/h5py/h5py/issues/498 if 'value' in rspJson: print 'remove above if check once h5py 2.4 is released' self.assertTrue('value' in rspJson) value = rspJson['value'] self.assertEqual(len(value), 4) elem = value[0] # elem should be a 3x5 array self.assertEqual(elem[2], [0, -2, -4, -6, -8])
def testGetCommitted(self): domain = 'committed_type.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) req = helper.getEndpoint() + "/groups/" + root_uuid + "/attributes/attr1" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SCALAR') self.assertTrue('dims' not in shape) typeItem = rspJson['type'] # returns '/datatypes/<uuid>' npos = typeItem.rfind('/') type_uuid = typeItem[(npos+1):] self.assertTrue(helper.validateId(type_uuid))
def testPutPointSelection(self): # create domain domain = 'valueputpointsel.datasettest.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.put(req, headers=headers) self.failUnlessEqual(rsp.status_code, 201) # creates domain #create 1d dataset payload = {'type': 'H5T_STD_I32LE', 'shape': 100} req = self.endpoint + "/datasets" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset1UUID = rspJson['id'] self.assertTrue(helper.validateId(dset1UUID)) # link new dataset as 'dset1' ok = helper.linkObject(domain, dset1UUID, 'dset1') self.assertTrue(ok) req = self.endpoint + "/datasets/" + dset1UUID + "/value" primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97] value = [1,] * len(primes) # write 1's at indexes that are prime # write 1's to all the prime indexes payload = { 'points': primes, 'value': value } headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 200) # read back the data readData = helper.readDataset(domain, dset1UUID) self.failUnlessEqual(readData[37], 1) # prime self.failUnlessEqual(readData[38], 0) # not prime
def setupAcls(self): rootUUID = self.getUUIDByPath('/') self.assertTrue(helper.validateId(rootUUID)) headers = self.getHeaders() # set allaccess acl for test_user2 payload = {'perm': allaccess_perm} req = self.endpoint + "/acls/test_user2" rsp = requests.put(req, data=json.dumps(payload), headers=headers) if rsp.status_code == 401: # acl is already setup by another test, return return self.assertEqual(rsp.status_code, 201) # set read-only acl for test_user1 payload = {'perm': readonly_perm} req = self.endpoint + "/acls/test_user1" rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 201) # set default acl for domain payload = {'perm': no_perm} req = self.endpoint + "/acls/default" rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 201) # try - again - should report authorizationis required now rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 401)
def testGetCommitted(self): domain = 'committed_type.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) req = helper.getEndpoint() + "/groups/" + root_uuid + "/attributes/attr1" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SCALAR') self.assertTrue('dims' not in shape) typeItem = rspJson['type'] # returns '/datatypes/<uuid>' npos = typeItem.rfind('/') type_uuid = typeItem[(npos+1):] self.assertTrue(helper.validateId(type_uuid))
def testGetArray(self): domain = 'array_attr.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint() + "/datasets/" + dset_uuid + "/attributes/A1" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 1) self.assertEqual(shape['dims'][0], 4) typeItem = rspJson['type'] self.assertEqual(typeItem['class'], 'H5T_ARRAY') self.assertTrue('dims' in typeItem) typeShape = typeItem['dims'] self.assertEqual(len(typeShape), 2) self.assertEqual(typeShape[0], 3) self.assertEqual(typeShape[1], 5) typeBase = typeItem['base'] self.assertEqual(typeBase['class'], 'H5T_INTEGER') self.assertEqual(typeBase['base'], 'H5T_STD_I64LE') self.assertTrue('value' in rspJson) value = rspJson['value'] self.assertEqual(len(value), 4) elem = value[0] # elem should be a 3x5 array self.assertEqual(len(elem), 3) self.assertEqual(elem[2], [0, -2, -4, -6, -8])
def testGetCompoundCommitted(self): domain = 'compound_committed.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'dset') req = helper.getEndpoint() + "/datasets/" + dset_uuid headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 1) self.assertEqual(shape['dims'][0], 72) typeItem = rspJson['type'] self.assertEqual(typeItem['class'], 'H5T_COMPOUND') self.assertTrue('fields' in typeItem) fields = typeItem['fields'] self.assertEqual(len(fields), 3) timeField = fields[1] self.assertEqual(timeField['name'], 'time') self.assertTrue('type' in timeField) timeFieldType = timeField['type'] self.assertEqual(timeFieldType['class'], 'H5T_STRING') self.assertEqual(timeFieldType['cset'], 'H5T_CSET_ASCII') self.assertEqual(timeFieldType['order'], 'H5T_ORDER_NONE') self.assertEqual(timeFieldType['strsize'], 6) self.assertEqual(timeFieldType['strpad'], 'H5T_STR_NULLPAD') tempField = fields[2] self.assertEqual(tempField['name'], 'temp') tempFieldType = tempField['type'] self.assertEqual(tempFieldType['class'], 'H5T_INTEGER') self.assertEqual(tempFieldType['base'], 'H5T_STD_I32LE')
def testPostTypes(self): domain = 'datatypes.datatypetest.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.put(req, headers=headers) self.failUnlessEqual(rsp.status_code, 201) # creates domain root_uuid = helper.getRootUUID(domain) # list of types supported datatypes = ( 'H5T_STD_I8LE', 'H5T_STD_U8LE', 'H5T_STD_I16LE', 'H5T_STD_U16LE', 'H5T_STD_I32LE', 'H5T_STD_U32LE', 'H5T_STD_I64LE', 'H5T_STD_I64LE', 'H5T_IEEE_F32LE', 'H5T_IEEE_F64LE' ) #todo: check on 'vlen_bytes', 'vlen_unicode' for datatype in datatypes: payload = {'type': datatype} req = self.endpoint + "/datatypes" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create datatypes rspJson = json.loads(rsp.text) dtype_uuid = rspJson['id'] self.assertTrue(helper.validateId(dtype_uuid)) # link new datatype using the type name name = datatype req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {"id": dtype_uuid} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201)
def testGetArray(self): domain = 'array_dset.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint() + "/datasets/" + dset_uuid headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 1) self.assertEqual(shape['dims'][0], 4) typeItem = rspJson['type'] self.assertEqual(typeItem['class'], 'H5T_ARRAY') self.assertTrue('dims' in typeItem) typeShape = typeItem['dims'] self.assertEqual(len(typeShape), 2) self.assertEqual(typeShape[0], 3) self.assertEqual(typeShape[1], 5) typeItemBase = typeItem['base'] self.assertEqual(typeItemBase['class'], 'H5T_INTEGER') self.assertEqual(typeItemBase['base'], 'H5T_STD_I64LE')
def testPutCommittedType(self): domain = 'tall_updated.' + config.get('domain') attr_name = 'attr_committed' root_uuid = helper.getRootUUID(domain) headers = {'host': domain} # create the datatype payload = {'type': 'H5T_IEEE_F32LE'} req = self.endpoint + "/datatypes/" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create datatype rspJson = json.loads(rsp.text) dtype_uuid = rspJson['id'] self.assertTrue(helper.validateId(dtype_uuid)) # link new datatype as 'dtype1' root_uuid = helper.getRootUUID(domain) name = 'dtype1' req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {'id': dtype_uuid} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create the attribute using the type created above value = [] for i in range(10): value.append(i*0.5) payload = {'type': dtype_uuid, 'shape': 10, 'value': value} req = self.endpoint + "/groups/" + root_uuid + "/attributes/" + attr_name rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create attribute rspJson = json.loads(rsp.text) self.assertEqual(len(rspJson['hrefs']), 3)
def setupAcls(self): rootUUID = self.getUUIDByPath('/') self.assertTrue(helper.validateId(rootUUID)) headers = self.getHeaders() # set allaccess acl for test_user2 payload = { 'perm': allaccess_perm } req = self.endpoint + "/acls/test_user2" rsp = requests.put(req, data=json.dumps(payload), headers=headers) if rsp.status_code == 401: # acl is already setup by another test, return return self.failUnlessEqual(rsp.status_code, 201) # set read-only acl for test_user1 payload = { 'perm': readonly_perm } req = self.endpoint + "/acls/test_user1" rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # set default acl for domain payload = { 'perm': no_perm } req = self.endpoint + "/acls/default" rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # try - again - should report authorizationis required now rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 401)
def testDataset(self): self.domain = 'tall_acl.' + config.get('domain') self.setupAcls() rootUUID = self.getUUIDByPath('/') self.assertTrue(helper.validateId(rootUUID)) # create dataset headers = self.getHeaders() payload = {'type': 'H5T_STD_I32LE'} req = self.endpoint + "/datasets" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 401) # auth needed headers = self.getHeaders(user=self.user1) rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 403) # not authorized headers = self.getHeaders(user=self.user2) rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 201) # OK rspJson = json.loads(rsp.text) dataset_uuid = rspJson['id'] # read dataset headers = self.getHeaders() req = self.endpoint + "/datasets/" + dataset_uuid rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 401) # un-authorized headers = self.getHeaders(user=self.user1) rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) # OK # read dataset acls req += "/acls" rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 403) # test_user1 doesn't have readACL permission headers = self.getHeaders(user=self.user2) rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("acls" in rspJson) acls = rspJson["acls"] self.assertEqual(len(acls), 0) # empty list of acls # delete dataset headers = self.getHeaders() req = self.endpoint + "/datasets/" + dataset_uuid rsp = requests.delete(req, headers=headers) self.assertEqual(rsp.status_code, 401) # auth needed headers = self.getHeaders(user=self.user1) rsp = requests.delete(req, headers=headers) self.assertEqual(rsp.status_code, 403) # not authorized headers = self.getHeaders(user=self.user2) rsp = requests.delete(req, headers=headers) self.assertEqual(rsp.status_code, 200) # OK
def testDelete(self): domain = 'tall_g2_deleted.' + config.get('domain') rootUUID = helper.getRootUUID(domain) helper.validateId(rootUUID) g2UUID = helper.getUUID(domain, rootUUID, 'g2') self.assertTrue(helper.validateId(g2UUID)) req = self.endpoint + "/groups/" + g2UUID headers = {'host': domain} rsp = requests.delete(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("hrefs" in rspJson) # do a GET, should return 410 (GONE) req = self.endpoint + "/groups/" + g2UUID rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 410)
def testGetArray(self): domain = 'array_attr.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint( ) + "/datasets/" + dset_uuid + "/attributes/A1" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 1) self.assertEqual(shape['dims'][0], 4) typeItem = rspJson['type'] self.assertEqual(typeItem['class'], 'H5T_ARRAY') self.assertTrue('dims' in typeItem) typeShape = typeItem['dims'] self.assertEqual(len(typeShape), 2) self.assertEqual(typeShape[0], 3) self.assertEqual(typeShape[1], 5) typeBase = typeItem['base'] self.assertEqual(typeBase['class'], 'H5T_INTEGER') self.assertEqual(typeBase['base'], 'H5T_STD_I64LE') self.assertTrue('value' in rspJson) value = rspJson['value'] self.assertEqual(len(value), 4) elem = value[0] # elem should be a 3x5 array self.assertEqual(len(elem), 3) self.assertEqual(elem[2], [0, -2, -4, -6, -8])
def testPostArray(self): domain = 'newarraydset.datasettest.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.put(req, headers=headers) self.failUnlessEqual(rsp.status_code, 201) # creates domain datatype = { 'class': 'H5T_ARRAY', 'base': 'H5T_STD_I64LE', 'shape': (3, 5) } payload = {'type': datatype, 'shape': 10} req = self.endpoint + "/datasets/" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset_uuid = rspJson['id'] self.assertTrue(helper.validateId(dset_uuid)) # link new dataset as 'dset1' root_uuid = helper.getRootUUID(domain) name = 'dset1' req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {"id": dset_uuid} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201)
def testPutCompound(self): domain = 'valueputcompound.datasettest.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.put(req, headers=headers) self.failUnlessEqual(rsp.status_code, 201) # creates domain root_uuid = helper.getRootUUID(domain) headers = {'host': domain} fields = ({'name': 'temp', 'type': 'H5T_STD_I32LE'}, {'name': 'pressure', 'type': 'H5T_IEEE_F32LE'}) datatype = {'class': 'H5T_COMPOUND', 'fields': fields } #create 1d dataset payload = {'type': datatype, 'shape': 2} req = self.endpoint + "/datasets" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset1UUID = rspJson['id'] self.assertTrue(helper.validateId(dset1UUID)) # link new dataset as 'dset1' ok = helper.linkObject(domain, dset1UUID, 'dset_compound') self.assertTrue(ok) value = ((55, 32.34), (59, 29.34)) payload = {'value': value} req = self.endpoint + "/datasets/" + dset1UUID + "/value" rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 200) # write value
def testGetArray(self): domain = 'array_attr.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint( ) + "/datasets/" + dset_uuid + "/attributes/A1" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 1) self.assertEqual(shape['dims'][0], 4) typeItem = rspJson['type'] self.assertEqual(typeItem['class'], 'H5T_ARRAY') self.assertTrue('dims' in typeItem) typeShape = typeItem['dims'] self.assertEqual(len(typeShape), 2) self.assertEqual(typeShape[0], 3) self.assertEqual(typeShape[1], 5) typeBase = typeItem['base'] self.assertEqual(typeBase['class'], 'H5T_INTEGER') self.assertEqual(typeBase['base'], 'H5T_STD_I64LE') # bug! - unable to read value from attribute with array type # code is not returning 'value' key in this case # h5py issue: https://github.com/h5py/h5py/issues/498 if 'value' in rspJson: print 'remove above if check once h5py 2.4 is released' self.assertTrue('value' in rspJson) value = rspJson['value'] self.assertEqual(len(value), 4) elem = value[0] # elem should be a 3x5 array self.assertEqual(elem[2], [0, -2, -4, -6, -8])
def testPostTypes(self): domain = 'datatypes.datatypetest.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.put(req, headers=headers) self.failUnlessEqual(rsp.status_code, 201) # creates domain root_uuid = helper.getRootUUID(domain) # list of types supported datatypes = ('H5T_STD_I8LE', 'H5T_STD_U8LE', 'H5T_STD_I16LE', 'H5T_STD_U16LE', 'H5T_STD_I32LE', 'H5T_STD_U32LE', 'H5T_STD_I64LE', 'H5T_STD_I64LE', 'H5T_IEEE_F32LE', 'H5T_IEEE_F64LE') #todo: check on 'vlen_bytes', 'vlen_unicode' for datatype in datatypes: payload = {'type': datatype} req = self.endpoint + "/datatypes" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create datatypes rspJson = json.loads(rsp.text) dtype_uuid = rspJson['id'] self.assertTrue(helper.validateId(dtype_uuid)) # link new datatype using the type name name = datatype req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {"id": dtype_uuid} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201)
def testGetEnum(self): domain = 'enum_attr.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint( ) + "/datasets/" + dset_uuid + "/attributes/A1" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 2) self.assertEqual(shape['dims'][0], 4) self.assertEqual(shape['dims'][1], 7) typeItem = rspJson['type'] self.assertEqual(typeItem['class'], 'H5T_ENUM') baseType = typeItem['base'] self.assertEqual(baseType['class'], 'H5T_INTEGER') self.assertEqual(baseType['base'], 'H5T_STD_I16BE') self.assertTrue('mapping' in typeItem) mapping = typeItem['mapping'] self.assertEqual(len(mapping), 4) self.assertEqual(mapping['SOLID'], 0) self.assertEqual(mapping['LIQUID'], 1) self.assertEqual(mapping['GAS'], 2) self.assertEqual(mapping['PLASMA'], 3) self.assertTrue('value' in rspJson) value = rspJson['value'] self.assertEqual(len(value), 4) self.assertEqual(value[1][2], mapping['GAS'])
def testGetFixedString(self): domain = 'fixed_string_attr.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint( ) + "/datasets/" + dset_uuid + "/attributes/A1" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 1) self.assertEqual(shape['dims'][0], 4) typeItem = rspJson['type'] self.assertEqual(typeItem['class'], 'H5T_STRING') self.assertEqual(typeItem['cset'], 'H5T_CSET_ASCII') self.assertEqual(typeItem['order'], 'H5T_ORDER_NONE') self.assertEqual(typeItem['strsize'], 7) self.assertEqual(typeItem['strpad'], 'H5T_STR_NULLPAD') self.assertTrue('value' in rspJson) value = rspJson['value'] self.assertEqual(len(value), 4) self.assertEqual(value[0], "Parting") self.assertEqual(value[1], "is such") self.assertEqual(value[2], "sweet") self.assertEqual(value[3], "sorrow.")
def testPutCommittedType(self): domain = 'tall_updated.' + config.get('domain') attr_name = 'attr_committed' root_uuid = helper.getRootUUID(domain) headers = {'host': domain} # create the datatype payload = {'type': 'H5T_IEEE_F32LE'} req = self.endpoint + "/datatypes/" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create datatype rspJson = json.loads(rsp.text) dtype_uuid = rspJson['id'] self.assertTrue(helper.validateId(dtype_uuid)) # link new datatype as 'dtype1' root_uuid = helper.getRootUUID(domain) name = 'dtype1' req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {'id': dtype_uuid} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create the attribute using the type created above value = [] for i in range(10): value.append(i * 0.5) payload = {'type': dtype_uuid, 'shape': 10, 'value': value} req = self.endpoint + "/groups/" + root_uuid + "/attributes/" + attr_name rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create attribute rspJson = json.loads(rsp.text) self.assertEqual(len(rspJson['hrefs']), 3)
def testGetVlen(self): domain = 'vlen_attr.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint( ) + "/datasets/" + dset_uuid + "/attributes/A1" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 1) self.assertEqual(shape['dims'][0], 2) typeItem = rspJson['type'] self.assertEqual(typeItem['class'], 'H5T_VLEN') baseType = typeItem['base'] self.assertEqual(baseType['class'], 'H5T_INTEGER') self.assertEqual(baseType['base'], 'H5T_STD_I32LE') #verify data returned value = rspJson['value'] self.assertEqual(len(value), 2) self.assertEqual(len(value[1]), 12) self.assertEqual(value[1][11], 144)
def testPostCompoundType(self): domain = 'compound.datasettest.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.put(req, headers=headers) self.failUnlessEqual(rsp.status_code, 201) # creates domain root_uuid = helper.getRootUUID(domain) fields = ({'name': 'temp', 'type': 'H5T_STD_I32LE'}, {'name': 'pressure', 'type': 'H5T_IEEE_F32LE'}) datatype = {'class': 'H5T_COMPOUND', 'fields': fields } payload = {'type': datatype, 'shape': 10} req = self.endpoint + "/datasets/" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset_uuid = rspJson['id'] self.assertTrue(helper.validateId(dset_uuid)) # link the new dataset name = "dset" req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {"id": dset_uuid} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201)
def testGetEnum(self): domain = 'enum_dset.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint() + "/datasets/" + dset_uuid headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 2) self.assertEqual(shape['dims'][0], 4) self.assertEqual(shape['dims'][1], 7) typeItem = rspJson['type'] self.assertEqual(typeItem['class'], 'H5T_ENUM') typeBase = typeItem['base'] self.assertEqual(typeBase['class'], 'H5T_INTEGER') self.assertEqual(typeBase['base'], 'H5T_STD_I16BE') self.assertTrue('mapping' in typeItem) mapping = typeItem['mapping'] self.assertEqual(len(mapping), 4) self.assertEqual(mapping['SOLID'], 0) self.assertEqual(mapping['LIQUID'], 1) self.assertEqual(mapping['GAS'], 2) self.assertEqual(mapping['PLASMA'], 3)
def testPostWithLink(self): # test PUT_root domain = 'newlinkedtype.datatypetest.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.put(req, headers=headers) self.failUnlessEqual(rsp.status_code, 201) root_uuid = helper.getRootUUID(domain) payload = { 'type': 'H5T_IEEE_F64LE', 'link': { 'id': root_uuid, 'name': 'linked_dtype' } } req = self.endpoint + "/datatypes" headers = {'host': domain} # create a new group rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) rspJson = json.loads(rsp.text) self.failUnlessEqual(rspJson["attributeCount"], 0) self.assertTrue(helper.validateId(rspJson["id"]))
def testPostCompoundType(self): domain = 'compound.datatypetest.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.put(req, headers=headers) self.failUnlessEqual(rsp.status_code, 201) # creates domain root_uuid = helper.getRootUUID(domain) fields = ({ 'name': 'temp', 'type': 'H5T_STD_I32LE' }, { 'name': 'pressure', 'type': 'H5T_IEEE_F32LE' }) datatype = {'class': 'H5T_COMPOUND', 'fields': fields} payload = {'type': datatype} req = self.endpoint + "/datatypes" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create datatype rspJson = json.loads(rsp.text) dtype_uuid = rspJson['id'] self.assertTrue(helper.validateId(dtype_uuid)) # link the new datatype name = "dtype_compound" req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {"id": dtype_uuid} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201)
def testDataset(self): self.domain = 'tall_acl.' + config.get('domain') self.setupAcls() rootUUID = self.getUUIDByPath('/') self.assertTrue(helper.validateId(rootUUID)) # create dataset headers = self.getHeaders() payload = {'type': 'H5T_STD_I32LE' } req = self.endpoint + "/datasets" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 401) # auth needed headers = self.getHeaders(user=self.user1) rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 403) # not authorized headers = self.getHeaders(user=self.user2) rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 201) # OK rspJson = json.loads(rsp.text) dataset_uuid = rspJson['id'] # read dataset headers = self.getHeaders() req = self.endpoint + "/datasets/" + dataset_uuid rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 401) # un-authorized headers = self.getHeaders(user=self.user1) rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) # OK # read dataset acls req += "/acls" rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 403) # test_user1 doesn't have readACL permission headers = self.getHeaders(user=self.user2) rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("acls" in rspJson) acls = rspJson["acls"] self.assertEqual(len(acls), 0) # empty list of acls # delete dataset headers = self.getHeaders() req = self.endpoint + "/datasets/" + dataset_uuid rsp = requests.delete(req, headers=headers) self.assertEqual(rsp.status_code, 401) # auth needed headers = self.getHeaders(user=self.user1) rsp = requests.delete(req, headers=headers) self.assertEqual(rsp.status_code, 403) # not authorized headers = self.getHeaders(user=self.user2) rsp = requests.delete(req, headers=headers) self.assertEqual(rsp.status_code, 200) # OK
def testGetDomainWithDot(self): domain = helper.nameEncode('tall.dots.need.to.be.encoded') + '.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) self.assertEqual(rsp.headers['content-type'], 'application/json') rspJson = json.loads(rsp.text) helper.validateId(rspJson["root"]) # try using host as query argument req = self.endpoint + "/?host=" + domain rsp = requests.get(req) self.assertEqual(rsp.status_code, 200) self.assertEqual(rsp.headers['content-type'], 'application/json') rspJson = json.loads(rsp.text) helper.validateId(rspJson["root"])
def testGetCommitted(self): domain = 'committed_type.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint() + "/datasets/" + dset_uuid headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 1) self.assertEqual(shape['dims'][0], 4) typeItem = rspJson['type'] # returns '/datatypes/<uuid>' npos = typeItem.rfind('/') type_uuid = typeItem[(npos+1):] self.assertTrue(helper.validateId(type_uuid))
def testGetCommitted(self): domain = 'committed_type.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint() + "/datasets/" + dset_uuid headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) shape = rspJson['shape'] self.assertEqual(shape['class'], 'H5S_SIMPLE') self.assertEqual(len(shape['dims']), 1) self.assertEqual(shape['dims'][0], 4) typeItem = rspJson['type'] # returns '/datatypes/<uuid>' npos = typeItem.rfind('/') type_uuid = typeItem[(npos + 1):] self.assertTrue(helper.validateId(type_uuid))
def testGetRootGroup(self): print("testGetRootGroup", self.base_domain) headers = helper.getRequestHeaders(domain=self.base_domain) req = helper.getEndpoint() + '/' rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) root_uuid = rspJson["root"] helper.validateId(root_uuid) req = helper.getEndpoint() + '/groups/' + root_uuid rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertTrue("id" in rspJson) group_id = rspJson["id"] helper.validateId(group_id) self.assertTrue("root" in rspJson) root_id = rspJson["root"] self.assertEqual(group_id, root_id) self.assertTrue("domain" in rspJson) #self.assertEqual(rspJson["domain"], self.base_domain) #TBD self.assertTrue("created" in rspJson) self.assertTrue("lastModified" in rspJson) self.assertTrue("linkCount" in rspJson) self.assertTrue("attributeCount" in rspJson) # try get with a different user (who has read permission) headers = helper.getRequestHeaders(domain=self.base_domain, username="******") rsp = requests.get(req, headers=headers) if config.get("default_public"): self.assertEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) self.assertEqual(rspJson["root"], root_uuid) else: self.assertEqual(rsp.status_code, 403) # try to do a GET with a different domain (should fail) another_domain = helper.getParentDomain(self.base_domain) headers = helper.getRequestHeaders(domain=another_domain) req = helper.getEndpoint() + '/groups/' + root_uuid rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 400)
def make_group(parent_id, name): # create new group payload = {'link': {'id': parent_id, 'name': name}} req = helper.getEndpoint() + "/groups" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.assertEqual(rsp.status_code, 201) rspJson = json.loads(rsp.text) new_group_id = rspJson["id"] self.assertTrue(helper.validateId(rspJson["id"])) return new_group_id
def testDelete(self): domain = 'tall_dset112_deleted.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) g1_uuid = helper.getUUID(domain, root_uuid, 'g1') self.assertTrue(helper.validateId(g1_uuid)) g11_uuid = helper.getUUID(domain, g1_uuid, 'g1.1') self.assertTrue(helper.validateId(g11_uuid)) d112_uuid = helper.getUUID(domain, g11_uuid, 'dset1.1.2') self.assertTrue(helper.validateId(d112_uuid)) req = self.endpoint + "/datasets/" + d112_uuid headers = {'host': domain} rsp = requests.delete(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) # verify that a GET on the dataset fails req = helper.getEndpoint() + "/datasets/" + d112_uuid headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 410)
def testGetOpaque(self): domain = 'opaque_dset.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint() + "/datasets/" + dset_uuid + "/value" headers = {'host': domain} rsp = requests.get(req, headers=headers) # get for Opaque data is not supported yet. Check that the call returns 501 self.failUnlessEqual(rsp.status_code, 501)
def testGetDomain(self): domain = 'tall.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.assertEqual(rsp.status_code, 200) self.assertEqual(rsp.headers['content-type'], 'application/json') rspJson = json.loads(rsp.text) root_uuid = rspJson["root"] helper.validateId(root_uuid) # try again with query arg req = self.endpoint + "/?host=" + domain rsp = requests.get(req) self.assertEqual(rsp.status_code, 200) self.assertEqual(rsp.headers['content-type'], 'application/json') rspJson = json.loads(rsp.text) helper.validateId(rspJson["root"]) self.assertEqual(root_uuid, rspJson["root"])
def testPostCommittedType(self): domain = 'committedtype.datasettest.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.put(req, headers=headers) self.failUnlessEqual(rsp.status_code, 201) # creates domain # create the datatype payload = {'type': 'H5T_IEEE_F32LE'} req = self.endpoint + "/datatypes/" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create datatype rspJson = json.loads(rsp.text) dtype_uuid = rspJson['id'] self.assertTrue(helper.validateId(dtype_uuid)) # link new datatype as 'dtype1' root_uuid = helper.getRootUUID(domain) name = 'dtype1' req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {'id': dtype_uuid} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create the dataset payload = {'type': dtype_uuid, 'shape': 10} req = self.endpoint + "/datasets/" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset_uuid = rspJson['id'] self.assertTrue(helper.validateId(dset_uuid)) # link new dataset as 'dset1' name = 'dset1' req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {"id": dset_uuid} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201)
def testPostResizable(self): domain = 'resizabledset.datasettest.' + config.get('domain') req = self.endpoint + "/" headers = {'host': domain} rsp = requests.put(req, headers=headers) self.failUnlessEqual(rsp.status_code, 201) # creates domain payload = {'type': 'H5T_IEEE_F32LE', 'shape': 10, 'maxshape': 20} req = self.endpoint + "/datasets/" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset_uuid = rspJson['id'] self.assertTrue(helper.validateId(dset_uuid)) # link new dataset as 'resizable' root_uuid = helper.getRootUUID(domain) name = 'resizable' req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {"id": dset_uuid} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create a datataset with unlimited dimension payload = {'type': 'H5T_IEEE_F32LE', 'shape': 10, 'maxshape': 0} req = self.endpoint + "/datasets/" rsp = requests.post(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201) # create dataset rspJson = json.loads(rsp.text) dset_uuid = rspJson['id'] self.assertTrue(helper.validateId(dset_uuid)) # link new dataset as 'resizable' root_uuid = helper.getRootUUID(domain) name = 'unlimited' req = self.endpoint + "/groups/" + root_uuid + "/links/" + name payload = {"id": dset_uuid} headers = {'host': domain} rsp = requests.put(req, data=json.dumps(payload), headers=headers) self.failUnlessEqual(rsp.status_code, 201)
def testGetCollection(self): domain = 'namedtype.' + config.get('domain') req = self.endpoint + "/datatypes" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) datatypeIds = rspJson["datatypes"] self.failUnlessEqual(len(datatypeIds), 2) for uuid in datatypeIds: self.assertTrue(helper.validateId(uuid))
def testGetCommitted(self): domain = 'committed_type.' + config.get('domain') root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, 'DS1') req = helper.getEndpoint() + "/datasets/" + dset_uuid + "/value" headers = {'host': domain} rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) data = rspJson['value'] self.failUnlessEqual(len(data), 4)
def testGetSimpleOneElementString(self): domain = 'scalar.' + config.get('domain') headers = {'host': domain} root_uuid = helper.getRootUUID(domain) self.assertTrue(helper.validateId(root_uuid)) dset_uuid = helper.getUUID(domain, root_uuid, '1ds') req = helper.getEndpoint() + "/datasets/" + dset_uuid + "/value" rsp = requests.get(req, headers=headers) self.failUnlessEqual(rsp.status_code, 200) rspJson = json.loads(rsp.text) data = rspJson['value'] self.assertEqual(data, ["hello",])