def test_upload_file_with_empty_params(): response = helper.post_upload_resource_response() check.response_has_status_code(response, 400) check.response_has_only_fields(response, 'message', 'description', 'error') check.response_has_field_with_value(response, field='error', value='FieldValidationError')
def test_expired_user(module_folder): folder, *_ = module_folder response = helper.get_resources_response(params=dict(path=folder), by_user='******') check.response_has_status_code(response, 401) check.response_has_only_fields(response, 'message', 'description', 'error') check.response_has_field_with_value(response, field='error', value='UnauthorizedError')
def test_bad_request(module_folder, limit, offset): folder, *_ = module_folder response = helper.get_resources_response(params=dict(path=folder, limit=limit, offset=offset)) check.response_has_status_code(response, 400) check.response_has_only_fields(response, 'message', 'description', 'error') check.response_has_field_with_value(response, field='error', value='FieldValidationError')
def test_publish_file_by_unauthorized_user(module_file): file_path, file_name, *_ = module_file response = helper.put_publish_resource_response(params=dict(path=file_path), by_user='******') check.response_has_status_code(response, 401) check.response_has_only_fields(response, 'message', 'description', 'error') check.response_has_field_with_value(response, field='error', value='UnauthorizedError')
def test_delete_nonexistent_resource(): response = helper.delete_resources_response(params=dict( path='nonexistent.txt')) check.response_has_status_code(response, 404) check.response_has_only_fields(response, 'message', 'description', 'error') check.response_has_field_with_value(response, field='error', value='DiskNotFoundError')
def test_expired_user_do_not_have_access_to_disk_info(): response = helper.get_disk_info_response(by_user='******') check.response_has_status_code(response, 401) check.response_has_field_with_value(response, field='error', value='UnauthorizedError') check.response_does_not_have_fields(response, 'system_folders', 'user', 'max_file_size', 'is_paid', 'used_space')
def test_upload_file_to_nonexistent_folder(): link = config.data.TEST_DATA_URL['test_txt.txt'] file_path = f'nonexistent_folder/existed_file.txt' response = helper.post_upload_resource_response( params=dict(path=file_path, url=link)) check.response_has_status_code(response, 409) check.response_has_only_fields(response, 'message', 'description', 'error') check.response_has_field_with_value(response, field='error', value='DiskPathDoesntExistsError')
def test_upload_file_with_invalid_params(path, url, base_folder): link = None if url is None else config.data.TEST_DATA_URL['test_txt.txt'] file_path = None if path is None else f'{base_folder}/{url}{path}.txt' response = helper.post_upload_resource_response( params=dict(path=file_path, url=link)) check.response_has_status_code(response, 400) check.response_has_only_fields(response, 'message', 'description', 'error') check.response_has_field_with_value(response, field='error', value='FieldValidationError')
def test_delete_file_by_expired_user(temp_file): path, *_ = temp_file() response = helper.delete_resources_response(params=dict(path=path), by_user='******') check.response_has_status_code(response, 401) check.response_has_only_fields(response, 'message', 'description', 'error') check.response_has_field_with_value(response, field='error', value='UnauthorizedError')
def test_upload_file_by_unauthorized_user(base_folder): link = config.data.TEST_DATA_URL['test_txt.txt'] file_path = f'{base_folder}/unauthorized.txt' response = helper.post_upload_resource_response(params=dict(path=file_path, url=link), by_user='******') check.response_has_status_code(response, 401) check.response_has_only_fields(response, 'message', 'description', 'error') check.response_has_field_with_value(response, field='error', value='UnauthorizedError')
def test_meta_for_folder(module_folder): path, folder_name = module_folder response = helper.get_resources_response(params=dict(path=path)) check.response_has_status_code(response, 200) check.response_has_only_fields( response, '_embedded', 'name', 'exif', 'created', 'resource_id', 'modified', 'path', 'comment_ids', 'type', 'revision' ) check.response_has_field_with_value(response, "type", 'dir') check.response_has_field_with_value(response, "name", folder_name)
def test_uploaded_file_with_same_name_should_have_postfix(base_folder): file_path = f'{base_folder}/same_name.txt' link = config.data.TEST_DATA_URL['test_txt.txt'] helper.upload_and_wait_status(params=dict(path=file_path, url=link), status='success') helper.upload_and_wait_status(params=dict(path=file_path, url=link), status='success') with allure.step("First file was uploaded with original name"): response = helper.get_resources_response(params=dict(path=file_path)) check.response_has_status_code(response, 200) check.response_has_field_with_value(response, "name", 'same_name.txt') with allure.step("Second file was uploaded with postfix"): response = helper.get_resources_response(params=dict( path=f'{base_folder}/same_name (1).txt')) check.response_has_status_code(response, 200) check.response_has_field_with_value(response, "name", 'same_name (1).txt')
def test_upload_file_with_type(base_folder, file_name, link, mime_type): """ Temporary folder is created, upload in it image, operation should be successful, file should be available and have expected name and mime type """ file_path = f'{base_folder}/{file_name}' response = helper.post_upload_resource_response( params=dict(path=file_path, url=link)) check.response_has_status_code(response, 202) check.response_has_fields(response, 'href') href = response.json().get('href') operation_id = href.split('/')[-1] helper.when_operation_status(operation_id, 'success') with allure.step("File information should be available"): response = helper.get_resources_response(params=dict(path=file_path)) check.response_has_status_code(response, 200) check.response_has_field_with_value(response, "mime_type", mime_type) check.response_has_field_with_value(response, "name", file_name)
def test_meta_for_file(module_file): path, file_name = module_file response = helper.get_resources_response(params=dict(path=path)) check.response_has_status_code(response, 200) check.response_has_fields( response, 'antivirus_status', 'file', 'sha256', 'name', 'exif', 'created', 'resource_id', 'modified', 'path', 'comment_ids', 'type', 'revision', 'media_type', 'md5', 'mime_type', 'size' ) check.response_has_field_with_value(response, "type", 'file') check.response_has_field_with_value(response, "mime_type", 'text/plain') check.response_has_field_with_value(response, "name", file_name)
def test_not_found(base_folder): response = helper.get_resources_response(params=dict(path=f'{base_folder}/nonexistent.txt')) check.response_has_status_code(response, 404) check.response_has_only_fields(response, 'message', 'description', 'error') check.response_has_field_with_value(response, field='error', value='DiskNotFoundError')
def test_unexpected_methods_are_not_allowed(method): response = helper.custom_disk_response(method=method, by_user='******') check.response_has_status_code(response, 405) check.response_has_field_with_value(response, field='error', value='MethodNotAllowedError')