コード例 #1
0
def test_resource_client_send_message():

    # prepare to send messages
    config = load_config('local.yaml')
    resource_client = ResourceClient(config)
    params = {
        'abc': 'test',
        'xyz': 777,
    }

    # check sending message to valid testing folder
    resource_client.send_message(config.server_test_path, 'testMessage',
                                 params)

    # check non-existent path
    try:
        resource_client.send_message('/path/does/not/exist', 'testMessage',
                                     params)
        assert False
    except ApiError as e:
        assert e.status == 404

    # check non-authorized path
    try:
        resource_client.send_message('/system', 'testMessage', params)
        assert False
    except ApiError as e:
        assert e.status == 403
コード例 #2
0
def test_resource_client_create_folder():
    config = load_config('local.yaml')
    resource_client = ResourceClient(config)
    path = config.server_test_path + '/folder%06d/folder%06d' % (
        random.randint(1, 999999), random.randint(1, 999999))
    resource_client.create_folder(path)
    assert resource_client.file_exists(path) == True
コード例 #3
0
def test_resource_client_read_write_file():
    for new_version in [False]:
        config = load_config('local.yaml')
        resource_client = ResourceClient(config)
        contents = 'This is a test.\n%d.\n' % random.randint(1, 1000)
        resource_client.write_file(config.server_test_path + '/test.txt',
                                   contents,
                                   new_version=new_version)
        server_contents = resource_client.read_file(config.server_test_path +
                                                    '/test.txt').decode()
        assert contents == server_contents
コード例 #4
0
def test_resource_client_read_write_sequence():
    for new_version in [False, False]:
        config = load_config('local.yaml')
        resource_client = ResourceClient(config)
        resource_client.write_file(config.server_test_path + '/test-text-seq',
                                   'ok',
                                   new_version=new_version)
        assert 'ok' == resource_client.read_file(config.server_test_path +
                                                 '/test-text-seq').decode()
        resource_client.write_file(config.server_test_path + '/test-text-seq',
                                   'test',
                                   new_version=new_version)
        assert 'test' == resource_client.read_file(config.server_test_path +
                                                   '/test-text-seq').decode()
コード例 #5
0
def test_resource_client_read_write_large_file():
    for binary in [False, True]:
        config = load_config('local.yaml')
        resource_client = ResourceClient(config)
        if binary:
            contents = bytearray(list(range(256)) * 100)
        else:
            contents = ('This is a test.\n%d.\n' %
                        random.randint(1, 1000)) * 1000
        resource_client.write_file(config.server_test_path + '/testLarge.txt',
                                   contents)
        data = resource_client.read_file(config.server_test_path +
                                         '/testLarge.txt')
        if not binary:
            data = data.decode()
        assert contents == data
コード例 #6
0
def test_resource_client_file_exists():
    config = load_config('local.yaml')
    resource_client = ResourceClient(config)
    assert resource_client.file_exists(config.server_test_path + '/test.txt')
    assert not resource_client.file_exists(config.server_test_path +
                                           '/test12345.txt')
コード例 #7
0
def test_folder():
    config = load_config('local.yaml')
    resource_client = ResourceClient(config)
コード例 #8
0
ファイル: test_config.py プロジェクト: sgrimm/rhizo-client
def _load_test_config(filename, use_environ=False):
    """Load a config file from the test_data subdirectory."""
    path = Path(__file__).parent / 'test_data' / filename
    return load_config(str(path), use_environ)