def test_filter_fields_for_folder(module_folder):
    folder, *_ = module_folder

    response = helper.get_resources_response(params=dict(path=folder, fields='_embedded'))

    check.response_has_status_code(response, 200)
    check.response_has_only_fields(response, '_embedded')
def test_filter_fields_for_file(module_file):
    file, *_ = module_file

    response = helper.get_resources_response(params=dict(path=file, fields='size'))

    check.response_has_status_code(response, 200)
    check.response_has_only_fields(response, 'size')
Esempio n. 3
0
def test_publish_and_filter_fields(module_folder):
    folder_path, folder_name, *_ = module_folder

    response = helper.put_publish_resource_response(params=dict(path=folder_path, fields='href,method'))

    check.response_has_status_code(response, 200)
    check.response_has_only_fields(response, 'href', 'method')
def test_delete_published_folder(published_folder):
    path, folder_name, *_ = published_folder

    response = helper.delete_resources_response(params=dict(path=path))

    check.response_has_status_code(response, 202, 204)

    with allure.step("Waiting when folder will be deleted"):
        wait(predicate=lambda: helper.get_resources_response(params=dict(
            path=path)).status_code == 404,
             timeout_seconds=30,
             sleep_seconds=(1, 2, 4))

    with allure.step("Deleted folder should be in trash folder"):
        folder_in_trash = helper.get_trash_resources(params=dict(
            path=folder_name))
        assert folder_in_trash[
            'name'] == folder_name, 'Unable to find deleted folder in trash'

    with allure.step("Deleted folder should be unpublished"):
        items = helper.get_public_resources().get('items')
        items_by_name = [
            item for item in items if item.get('name') == folder_name
        ]
        assert len(items_by_name) == 0, "Deleted file still published"
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')
Esempio n. 6
0
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_upload_file_and_get_existent_fields(base_folder, fields):
    link = config.data.TEST_DATA_URL['test_txt.txt']
    file_path = f'{base_folder}/fields_test{fields}.txt'
    response = helper.post_upload_resource_response(
        params=dict(path=file_path, url=link, fields=','.join(fields)))

    check.response_has_status_code(response, 202)
    check.response_has_only_fields(response, *fields)
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_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')
Esempio n. 11
0
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_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_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_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_limit_nested_resources(folder_with_two_files, limit, expected_items, expected_limit):
    folder, *_ = folder_with_two_files

    response = helper.get_resources_response(params=dict(path=folder, limit=limit))

    check.response_has_status_code(response, 200)
    check.response_has_fields(response, '_embedded')

    with allure.step("Check expected amount of resources were given"):
        json = response.json()
        embedded = json['_embedded']
        assert len(embedded.get('items')) == expected_items
        assert embedded.get('limit') == expected_limit
def test_sort_resources(folder_with_two_files, sorting_type):
    folder, *_ = folder_with_two_files

    response = helper.get_resources_response(params=dict(path=folder, sort=sorting_type))
    check.response_has_status_code(response, 200)
    check.response_has_fields(response, '_embedded')

    with allure.step("Check sorting is correct"):
        json = response.json()
        embedded = json['_embedded']
        items = embedded['items']
        expected_items = sorted(items, key=lambda item: item[sorting_type])
        assert items == expected_items
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_delete_folder_force_async(temp_folder):
    path, folder_name, *_ = temp_folder()

    response = helper.delete_resources_response(
        params=dict(path=path, force_async=True))
    check.response_has_status_code(response, 202)

    operation_id = helper.get_operation_id_from_response(response)
    helper.when_operation_status(operation_id=operation_id, status='success')

    with allure.step("Deleted folder should be in trash folder"):
        file_in_trash = helper.get_trash_resources(params=dict(
            path=folder_name))
        assert file_in_trash[
            'name'] == folder_name, 'Unable to find deleted folder in trash'
def test_offset_nested_resources(folder_with_two_files):
    folder, file_1, file_2, *_ = folder_with_two_files

    response = helper.get_resources_response(params=dict(path=folder, offset=1, sort='created'))
    check.response_has_status_code(response, 200)
    check.response_has_fields(response, '_embedded')

    with allure.step("Check expected amount of files"):
        json = response.json()
        embedded = json['_embedded']
        items = embedded.get('items')
        assert len(items) == 1, "Should be only one file (2 files in directory and offset is 1)"

    with allure.step("Check expected file is taken"):
        item = items[0]
        assert file_2 in item['path'], "Files should be sorted by created date (default sorting type)"
Esempio n. 22
0
def test_publish_file(module_file):
    file_path, file_name, *_ = module_file

    response = helper.put_publish_resource_response(params=dict(path=file_path))

    check.response_has_status_code(response, 200)
    check.response_has_only_fields(response, 'href', 'method', 'templated')
    check.response_has_field_contains_value(response, 'href', file_name)

    with allure.step("There is should be only one copy of published file"):
        items = helper.get_public_resources().get('items')
        items_by_name = [item for item in items if item.get('name') == file_name]
        assert len(items_by_name) == 1, "There is should be only one copy of published file"

    with allure.step("Published file should be available even for unauthorized user"):
        response = http_session.send_custom_request(method='get', by_user='******', url=items_by_name[0]['file'])
        check.response_has_status_code(response, 200)
def test_delete_file_permanently(temp_file):
    path, file_name, *_ = temp_file()

    response = helper.delete_resources_response(
        params=dict(path=path, permanently=True))
    check.response_has_status_code(response, 202, 204)

    with allure.step("Waiting when file will be deleted"):
        wait(predicate=lambda: helper.get_resources_response(params=dict(
            path=path)).status_code == 404,
             timeout_seconds=30,
             sleep_seconds=(1, 2, 4))

    with allure.step("Deleted permanently file should not be in trash folder"):
        response = helper.get_trash_resources_response(params=dict(
            path=file_name))
        assert response.status_code == 404, 'Deleted permanently file should not be in trash'
def test_delete_file(temp_file):
    path, file_name, *_ = temp_file()

    response = helper.delete_resources_response(params=dict(path=path))

    check.response_has_status_code(response, 202, 204)

    with allure.step("Waiting when file will be deleted"):
        wait(predicate=lambda: helper.get_resources_response(params=dict(
            path=path)).status_code == 404,
             timeout_seconds=30,
             sleep_seconds=(1, 2, 4))

    with allure.step("Deleted file should be in trash folder"):
        file_in_trash = helper.get_trash_resources(params=dict(path=file_name))
        assert file_in_trash[
            'name'] == file_name, 'Unable to find deleted file in trash'
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)
Esempio n. 27
0
def test_get_disk_info():
    response = helper.get_disk_info_response()
    check.response_has_status_code(response, 200)
    check.response_has_fields(response, 'system_folders', 'user',
                              'max_file_size', 'is_paid', 'used_space')
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')
Esempio n. 29
0
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')