Esempio n. 1
0
def test_api_exception_status_code(mocker):
    instance = api.Api(config)
    mocker.patch('requests.post', return_value=mock_json_response(status_code=404))
    with pytest.raises(api.ApiException) as excinfo:
        instance.coinbase()
    assert excinfo.value.code == 404
    assert excinfo.value.message == 'Error Reason'
Esempio n. 2
0
def test_api_exception_error_response(mocker):
    instance = api.Api(config)
    mocker.patch('requests.post', return_value=mock_json_response(error={'code': 31337, 'message': 'Too Elite'}))
    with pytest.raises(api.ApiException) as excinfo:
        instance.coinbase()
    assert excinfo.value.code == 31337
    assert excinfo.value.message == 'Too Elite'
Esempio n. 3
0
def test_api_exception_status_code(mocker):
    instance = api.Api(config)
    mocker.patch('requests.post',
                 return_value=mock_json_response(status_code=404))
    with pytest.raises(api.ApiException) as excinfo:
        instance.coinbase()
    assert excinfo.value.code == 404
    assert excinfo.value.message == 'Error Reason'
Esempio n. 4
0
def mock_rpc(mocker, rpc_fun, rpc_args, json_result, rpc_method, rpc_params):
    instance = api.Api(config)

    mocker.patch('requests.post', return_value=mock_json_response(result=json_result))
    mock_rpc_post = mocker.patch.object(instance, '_rpc_post', side_effect=instance._rpc_post)

    result = getattr(instance, rpc_fun)(*rpc_args)
    mock_rpc_post.assert_called_with(rpc_method, rpc_params)
    return result
Esempio n. 5
0
def test_deploy(mocker):
    deployment = deploy.Deploy('test/fixtures/example.yaml.fixture', config)
    mocker.patch('requests.post', return_value=mock_json_response(status_code=200, result=None))
    mocker.patch('time.sleep')
    if not has_solc:
        with pytest.raises(Exception) as excinfo:
            deployment.deploy()
        assert excinfo.value.message == 'solc compiler not found'
    else:
        deployment.deploy()
Esempio n. 6
0
def test_api_exception_error_response(mocker):
    instance = api.Api(config)
    mocker.patch('requests.post',
                 return_value=mock_json_response(error={
                     'code': 31337,
                     'message': 'Too Elite'
                 }))
    with pytest.raises(api.ApiException) as excinfo:
        instance.coinbase()
    assert excinfo.value.code == 31337
    assert excinfo.value.message == 'Too Elite'
Esempio n. 7
0
def mock_rpc(mocker, rpc_fun, rpc_args, json_result, rpc_method, rpc_params):
    instance = api.Api(config)

    mocker.patch('requests.post',
                 return_value=mock_json_response(result=json_result))
    mock_rpc_post = mocker.patch.object(instance,
                                        '_rpc_post',
                                        side_effect=instance._rpc_post)

    result = getattr(instance, rpc_fun)(*rpc_args)
    mock_rpc_post.assert_called_with(rpc_method, rpc_params)
    return result