def test_zip_to_binary_and_back(): package_file = open('tests/resources/zip_binary.txt') zip_contents = package_file.read().replace("\n", "") zip_contents = zip_contents.replace('"', '') utils.binary_to_zip(zip_contents) return_binary = utils.zip_to_binary('retrieve.zip') assert zip_contents == return_binary
def retrieve(filename, dir='src/'): client = MetadataClient() u, p, ip = utils.retrieve_credentials() ip = True if ip == 'True' else False client.login(u, p, is_production=ip) if not os.path.exists(dir): os.mkdir(dir) name, type = (filename.split(".")) utils.build_package(name, type, dir) retrieve_request = client.retrieve(dir + 'package.xml') while client.check_status(retrieve_request.id)[0].done == False: pass retrieve_response = client.check_retrieve_status(retrieve_request.id) binary_to_zip(retrieve_response.zipFile) shutil.move('retrieve.zip', dir + 'retrieve.zip') os.system('unzip -uo ' + dir + '/retrieve.zip -d ' + dir)
def test_binary_to_zip(): test_file = open('test.txt', 'w') test_file.write('testing') test_file.close() zipped = zipfile.ZipFile('test.zip', 'w') zipped.write('test.txt') zipped.close() zipped = open('test.zip', 'r') zip_contents = zipped.read() zip_contents+="===" encoded_file = base64.b64encode(zip_contents) zipped.close() utils.binary_to_zip(zip_contents) assert os.path.isfile('test.zip')
def retrieve_package(dir='src/'): ################################################# ##### Retrieve the contents specified of a ###### ##### package.xml in the src directory ########## ################################################# client = MetadataClient() u, p, ip = utils.retrieve_credentials() ip = True if ip == 'True' else False client.login(u, p, is_production=ip) if not os.path.exists(dir): os.mkdir(dir) retrieve_request = client.retrieve(dir + 'package.xml') while client.check_status(retrieve_request.id)[0].done == False: pass retrieve_response = client.check_retrieve_status(retrieve_request.id) binary_to_zip(retrieve_response.zipFile) shutil.move('retrieve.zip', dir + 'retrieve.zip') os.system('unzip -uo ' + dir + '/retrieve.zip -d ' + dir)