Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_url_invalid_endpoint(api3):
with pytest.raises(APIError):
api3._url('I-will_never+exist%really')
def test_url_invalid_endpoint(api2):
with pytest.raises(APIError):
api2._url('I-will_never+exist%really')
def test_cmd_bad_command(self, baseapi):
httpretty.enable()
stub_request('http://localhost:8080/pdb/cmd/v1')
with pytest.raises(pypuppetdb.errors.APIError):
baseapi._cmd('incorrect command', {})
httpretty.disable()
httpretty.reset()
class ImproperlyConfiguredError(APIError):
"""This exception is thrown when the API is initialised
and it detects incompatible configuration such as SSL turned
on but no certificates provided."""
pass
class EmptyResponseError(APIError):
"""Will be thrown when we did receive a response but the
response is empty."""
pass
class DoesNotComputeError(APIError):
"""This error will be thrown when a function is called with
an incompatible set of optional parameters. This is the 'you are
being a naughty developer, go read the docs' error.
"""
pass
class APIError(Exception):
"""Our base exception the other errors inherit from."""
pass
class ImproperlyConfiguredError(APIError):
"""This exception is thrown when the API is initialised
and it detects incompatible configuration such as SSL turned
on but no certificates provided."""
pass
class EmptyResponseError(APIError):
"""Will be thrown when we did receive a response but the
response is empty."""
pass
class DoesNotComputeError(APIError):
"""This error will be thrown when a function is called with
an incompatible set of optional parameters. This is the 'you are
being a naughty developer, go read the docs' error.
r = self._session.get(url, params=payload,
verify=self.ssl_verify,
cert=(self.ssl_cert, self.ssl_key),
timeout=self.timeout,
auth=auth)
elif request_method.upper() == 'POST':
r = self._session.post(url,
data=json.dumps(payload, default=str),
verify=self.ssl_verify,
cert=(self.ssl_cert, self.ssl_key),
timeout=self.timeout,
auth=auth)
else:
log.error("Only GET or POST supported, {0} unsupported".format(
request_method))
raise APIError
r.raise_for_status()
# get total number of results if requested with include-total
# just a quick hack - needs improvement
if 'X-Records' in r.headers:
self.last_total = r.headers['X-Records']
else:
self.last_total = None
json_body = r.json()
if json_body is not None:
return json_body
else:
del json_body
raise EmptyResponseError
class APIError(Exception):
"""Our base exception the other errors inherit from."""
pass
class ImproperlyConfiguredError(APIError):
"""This exception is thrown when the API is initialised
and it detects incompatible configuration such as SSL turned
on but no certificates provided."""
pass
class EmptyResponseError(APIError):
"""Will be thrown when we did receive a response but the
response is empty."""
pass
class DoesNotComputeError(APIError):
"""This error will be thrown when a function is called with
an incompatible set of optional parameters. This is the 'you are
being a naughty developer, go read the docs' error.
"""
pass