def test_WeedMaster(): master = WeedMaster() assert master.__repr__() # assign assign_key_dict = master.acquire_assign_info() assert isinstance(assign_key_dict, dict) assert assign_key_dict.has_key('fid') assert assign_key_dict['fid'].replace(',', '') > 0x001 fid = assign_key_dict['fid'] volume_id = fid.split(',')[0] # lookup lookup_dict = master.lookup(fid) assert isinstance(lookup_dict, dict) assert lookup_dict.has_key('locations') locations_list = lookup_dict['locations'] assert locations_list[0].has_key('url') assert locations_list[0].has_key('publicUrl') # vacuum vacuum_dict = master.vacuum() assert isinstance(vacuum_dict, dict) assert vacuum_dict.has_key('Topology') # status status_dict = master.get_status() assert isinstance(status_dict, dict) assert status_dict.has_key('Topology')
def test_volume_put_get_delete_file(): master = WeedMaster() assert master.__repr__() # assign assign_key_dict = master.get_assign_key() assert isinstance(assign_key_dict, dict) assert assign_key_dict.has_key('fid') assert assign_key_dict['fid'].replace(',', '') > 0x001 fid = assign_key_dict['fid'] volume_id = fid.split(',')[0] # lookup lookup_dict = master.lookup(fid) assert isinstance(lookup_dict, dict) assert lookup_dict.has_key('locations') locations_list = lookup_dict['locations'] assert locations_list[0].has_key('url') assert locations_list[0].has_key('publicUrl') volume_url = 'http://' + locations_list[0]['publicUrl'] url = urlparse.urlparse(volume_url) #volume = WeedVolume(host=url.hostname, port=url.port) volume = master.get_volume(fid) status_dict = volume.get_status() assert isinstance(status_dict, dict) assert status_dict.has_key('Version') assert status_dict.has_key('Volumes') assert isinstance(status_dict['Volumes'], list) # file_to_post = './test_file_to_post_to_weed.xml' file_to_update = 'test_file_to_post_to_weed.xml' file_to_post = os.path.join(TEST_PATH, file_to_update) with open(file_to_post, 'wb') as tmp_file: tmp_file.write("nonsense " * 1024 * 256) put_result = volume.put_file(os.path.abspath(file_to_post), fid) assert not 'error' in put_result assert 'size' in put_result data = volume.get_file(fid) assert data # print data with open(file_to_post, 'r') as fd: file_data = fd.read() assert data == file_data delete_result = volume.delete_file(fid) assert delete_result assert not 'error' in delete_result assert 'size' in delete_result
def test_volume_put_get_delete_file(): master = WeedMaster() assert master.__repr__() # assign assign_key_dict = master.get_assign_key() assert isinstance(assign_key_dict, dict) assert assign_key_dict.has_key('fid') assert assign_key_dict['fid'].replace(',', '') > 0x001 fid = assign_key_dict['fid'] volume_id = fid.split(',')[0] # lookup lookup_dict = master.lookup(fid) assert isinstance(lookup_dict, dict) assert lookup_dict.has_key('locations') locations_list = lookup_dict['locations'] assert locations_list[0].has_key('url') assert locations_list[0].has_key('publicUrl') volume_url = 'http://' + locations_list[0]['publicUrl'] url = urlparse.urlparse(volume_url) #volume = WeedVolume(host=url.hostname, port=url.port) volume = master.get_volume(fid) status_dict = volume.get_status() assert isinstance(status_dict, dict) assert status_dict.has_key('Version') assert status_dict.has_key('Volumes') assert isinstance(status_dict['Volumes'], list) # file_to_post = './test_file_to_post_to_weed.xml' file_to_update = 'test_file_to_post_to_weed.xml' file_to_post = os.path.join(TEST_PATH, file_to_update) with open(file_to_post, 'wb') as tmp_file: tmp_file.write("nonsense " * 1024 * 256) put_result = volume.put_file(os.path.abspath(file_to_post),fid) assert not 'error' in put_result assert 'size' in put_result data = volume.get_file(fid) assert data # print data with open(file_to_post, 'r') as fd: file_data = fd.read() assert data == file_data delete_result = volume.delete_file(fid) assert delete_result assert not 'error' in delete_result assert 'size' in delete_result
def test_WeedMaster2(): master = WeedMaster() assert master.__repr__() # assign wak = master.acquire_new_assign_key(10) assert isinstance(wak, dict) assert wak.has_key('fid') fid = wak.fid fids = [fid] + [fid + '_' + str(i + 1) for i in range(10)] locations = [] for i in fids: l = master.lookup(i) assert l.has_key('locations') locations.append(l) for i, l in enumerate(locations): if i < (len(locations) - 1): assert locations[i] == locations[i + 1]