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'
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'
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
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()
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'