Beispiel #1
0
def test_download(testserver):
    """test download"""
    cli = JsonWspClient(testserver.url,
                        services=['TransferService'],
                        events=[('file.read', download_event)])
    cli.download(name=FILENAME).save_all(DOWN_PATH)
    assert filecmp.cmpfiles(RES_PATH, DOWN_PATH, FILENAME)
Beispiel #2
0
def test_response_two(testserver):
    """test response one"""
    cli = JsonWspClient(testserver.url, ['ClacService'])
    numbers_list = [[1, 2, 3, 4, 5], [10, 20, 5, 7], [12, 4, 32, 6], [40, 2]]
    for numbers in numbers_list:
        with cli.sum(numbers=numbers) as res:
            assert res.result == sum(numbers)
Beispiel #3
0
def test_params_mapping_error_one(testserver, cleandir):
    """params_mapping"""
    cli = JsonWspClient(testserver.url, services=['TransferService'])
    with pytest.raises(ParamsError):
        cli.secure_download(raise_for_fault=True,
                            name=FILENAME).save_all(DOWN_PATH)
        pytest.fail("Expecting ParamsError")
Beispiel #4
0
def test_upload(testserver):
    """test uploads"""
    cli = JsonWspClient(testserver.url,
                        services=['TransferService'],
                        events=[('file.read', all_events)])
    cli.upload(incoming=get_fileitem(join(RES_PATH, FILENAME)))
    assert filecmp.cmpfiles(RES_PATH, UP_PATH, FILENAME)
Beispiel #5
0
def test_params_mapping_one(testserver):
    """params_mapping"""
    cli = JsonWspClient(testserver.url,
                        services=['Authenticate'],
                        params_mapping={'token': 'token'})
    res = cli.get_user()
    cli.token = res.response_dict['result']['token']
    assert cli.check_token()
Beispiel #6
0
def test_response_three(testserver):
    """test response one"""
    cli = JsonWspClient(testserver.url, ['TransferService'])
    res = cli.multi_download(names=['test-20-1.txt', 'test-20-2.txt'])
    for attach in res:
        filename = "down-file{}".format(attach.index)
        attach.save('/tmp/', filename=filename)
        assert filecmp.cmpfiles(RES_PATH, DOWN_PATH, filename)
Beispiel #7
0
def test_params_mapping_error_three(testserver, cleandir):
    """params_mapping"""
    cli = JsonWspClient(testserver.url,
                        raise_for_fault=True,
                        services=['TransferService'])
    with pytest.raises(JsonWspFault):
        cli.secure_download(name=FILENAME, token=4321).save_all(DOWN_PATH)
        pytest.fail("Expecting JsonWspFault")
Beispiel #8
0
def test_response1(testserver):
    """test download"""
    cli = JsonWspClient(testserver.url, ['TransferService'])
    res = cli.multi_download(names=['test-20-1.txt', 'test-20-2.txt'])
    for attach in res:
        filename = "down-file{}".format(attach.index)
        print("Saving", filename)
        attach.save('/tmp/', filename=filename)
Beispiel #9
0
def test_error_one(testserver):
    """params_mapping"""
    cli = JsonWspClient(testserver.url, services=['TransferService'])
    try:
        cli.secure_download(
            name=FILENAME).raise_for_fault().save_all(DOWN_PATH)
    except JsonWspFault as error:
        print('Error ', error.description)
Beispiel #10
0
def test_calc(testserver):
    """test download"""
    cli = JsonWspClient(testserver.url, ['ClacService'])
    numbers_list = [
        [1, 2, 3, 4, 5],
        [10, 20, 5, 7],
        [12, 4, 32, 6],
        [40, 2],
    ]
    for numbers in numbers_list:
        print("numbers to add up ", " + ".join([str(a) for a in numbers]))
        with cli.sum(numbers=numbers) as res:
            if res.result == 42:
                print("the result is: The answer to the ultimate question of "
                      "life, the universe and everything")
            else:
                print("the result is:", res.result)
Beispiel #11
0
def test_process_response(testserver):
    """test processors"""
    mp_msg = "Yes i'm multi part"
    nmp_msg = "No i'm not multi part"

    def add_info(response, **dummy_kwargs):
        """add info"""
        if response.is_multipart:
            response.response_dict['testinfo'] = mp_msg
        else:
            response.response_dict['testinfo'] = nmp_msg
        return response

    def objectify(response, **dummy_kwargs):
        """objectify"""
        response.objpart = type('ObjPart', (object, ), response.response_dict)
        return response

    cli = JsonWspClient(testserver.url,
                        services=['TransferService'],
                        processors=[add_info, objectify])
    res = cli.get_info()
    assert hasattr(res.objpart, '__name__')
    assert res.objpart.testinfo == nmp_msg
Beispiel #12
0
def test_download(testserver, cleandir):
    """test download"""
    cli = JsonWspClient(testserver.url, services=['TransferService'])
    cli.download(name=FILENAME).save_all(DOWN_PATH)
    assert filecmp.cmpfiles(RES_PATH, DOWN_PATH, FILENAME)
Beispiel #13
0
def test_upload(testserver, cleandir):
    """test uploads"""
    cli = JsonWspClient(testserver.url, services=['TransferService'])
    cli.upload(incoming=get_fileitem(join(RES_PATH, FILENAME)))
    assert filecmp.cmpfiles(RES_PATH, UP_PATH, FILENAME)
Beispiel #14
0
def test_response_one(testserver):
    """test response one"""
    cli = JsonWspClient(testserver.url, ['ClacService'])
    assert cli.sum(numbers=[1, 2, 3]).result == 6
Beispiel #15
0
def test_nonzero(testserver, cleandir):
    """params_mapping"""
    cli = JsonWspClient(testserver.url, services=['FaultService'])
    assert cli.raise_fault(ftype='none')
    assert not cli.raise_fault(ftype='server')
    assert not cli.raise_fault(ftype='client')
Beispiel #16
0
def test_info(testserver):
    """test download"""
    with JsonWspClient(testserver.url, services=['Authenticate']) as cli:
        with cli.get_user() as res:
            print(res.response_dict)
            print(res.result)