def test_delete_file_by_id(): api.login("system", os.getenv("SYSTEM_PWD")) headers = api.headers() params = {'key': api.API_KEY} file_url = api.url('/api/file/schema3.txt') files = {'file': open(api.schema_path(), 'rb')} resp = requests.post(file_url, params=params, headers=headers, files=files) resp.raise_for_status() node = resp.json() file_id = node['uid'] # download by path resp = requests.get(file_url, params=params, headers=headers) resp.raise_for_status() print(resp.text) # download by id url1 = api.url('/api/file/{0}'.format(file_id)) resp = requests.get(url1, params=params, headers=headers) resp.raise_for_status() print(resp.text) url2 = api.url('/api/file/{0}'.format(file_id)) resp = requests.delete(url2, params=params, headers=headers) resp.raise_for_status()
def test_upload(): api.login("system", os.getenv("SYSTEM_PWD")) headers = api.headers() params = {'key': api.API_KEY} file_url = api.url('/api/file/schema.txt') files = {'file': open(api.schema_path(), 'rb')} resp = requests.post(file_url, params=params, headers=headers, files=files) resp.raise_for_status() node = resp.json() file_id = node['uid'] files = {'file': open(api.schema_path(), 'rb')} resp = requests.post(file_url, params=params, headers=headers, files=files) resp.raise_for_status() files = {'file': open(api.schema_path(), 'rb')} resp = requests.put(file_url, params=params, headers=headers, files=files) resp.raise_for_status() # download by path resp = requests.get(file_url, params=params, headers=headers) resp.raise_for_status() print(resp.text) # download by id file_url2 = api.url(f'/api/file/{file_id}') resp = requests.get(file_url2, params=params, headers=headers) resp.raise_for_status() print(resp.text) resp = requests.delete(file_url, params=params, headers=headers) resp.raise_for_status() resp = requests.get(file_url, params=params, headers=headers) assert (resp.status_code == 404) file_url2 = api.url(f'/api/file/{file_id}') resp = requests.get(file_url2, params=params, headers=headers) assert (resp.status_code == 404)
def main(): api.login("system", os.getenv("SYSTEM_PWD")) headers = api.headers() params = {'key': api.API_KEY} files = [f for f in os.listdir(BOOK_DIR) if isfile(join(BOOK_DIR, f))] for f in files: url = api.url(f'/api/file/{f}') fullpath = join(BOOK_DIR, f) files = {'file': open(fullpath, 'rb')} resp = requests.post(url, params=params, headers=headers, files=files) resp.raise_for_status()
def test_delete_file_node(): api.login("system", os.getenv("SYSTEM_PWD")) headers = api.headers() params = {'key': api.API_KEY} file_url = api.url('/api/file/schema2.txt') files = {'file': open(api.schema_path(), 'rb')} resp = requests.post(file_url, params=params, headers=headers, files=files) resp.raise_for_status() node = resp.json() file_id = node['uid']