def test_defaults(): api = BaseAPI(2) assert api.host == 'localhost' assert api.port == 8080 assert api.ssl is False assert api.ssl_key is None assert api.ssl_cert is None assert api.timeout == 10 assert api.protocol == 'http'
def connect(host='localhost', port=8080, ssl_verify=False, ssl_key=None, ssl_cert=None, timeout=10, protocol=None, url_path='/', username=None, password=None): """Connect with PuppetDB. This will return an object allowing you to query the API through its methods. :param host: (Default: 'localhost;) Hostname or IP of PuppetDB. :type host: :obj:`string` :param port: (Default: '8080') Port on which to talk to PuppetDB. :type port: :obj:`int` :param ssl_verify: (optional) Verify PuppetDB server certificate. :type ssl_verify: :obj:`bool` or :obj:`string` True, False or filesystem \ path to CA certificate. :param ssl_key: (optional) Path to our client secret key. :type ssl_key: :obj:`None` or :obj:`string` representing a filesystem\ path. :param ssl_cert: (optional) Path to our client certificate. :type ssl_cert: :obj:`None` or :obj:`string` representing a filesystem\ path. :param timeout: (Default: 10) Number of seconds to wait for a response. :type timeout: :obj:`int` :param protocol: (optional) Explicitly specify the protocol to be used (especially handy when using HTTPS with ssl_verify=False and without certs) :type protocol: :obj:`None` or :obj:`string` :param url_path: (Default: '/') The URL path where PuppetDB is served :type url_path: :obj:`None` or :obj:`string` :param username: (optional) The username to use for HTTP basic authentication :type username: :obj:`None` or :obj:`string` :param password: (optional) The password to use for HTTP basic authentication :type password: :obj:`None` or :obj:`string` """ return BaseAPI(host=host, port=port, timeout=timeout, ssl_verify=ssl_verify, ssl_key=ssl_key, ssl_cert=ssl_cert, protocol=protocol, url_path=url_path, username=username, password=password)
def test_query_with_count_filter(stub_get): api = BaseAPI(2) stub_get('http://localhost:8080/v2/nodes?count-filter=""', body='[]') response = api._query('nodes', count_filter="") assert response == []
def test_url_with_endpoint_with_path(): api = BaseAPI(2) assert api._url('facts', path='osfamily') == ('http://localhost:8080/' 'v2/facts/osfamily')
def test_query_with_order_by(stub_get): api = BaseAPI(2) stub_get('http://localhost:8080/v2/nodes?order-by=""', body='[]') response = api._query('nodes', order_by="") assert response == []
def test_api3_endpoints(): api = BaseAPI(3) assert api.version == 'v3' assert api.endpoints == ENDPOINTS[3]
def test_query_connection(): api = BaseAPI(2) with pytest.raises(requests.exceptions.ConnectionError): api._query('nodes')
def test_facts(): api = BaseAPI(2) with pytest.raises(NotImplementedError): api.facts()
def test_invalid_api_version(): with pytest.raises(UnsupportedVersionError): api = BaseAPI(1)
def test_query_endpoint(stub_get): api = BaseAPI(2) stub_get('http://localhost:8080/v2/nodes', body='[]') response = api._query('nodes') assert response == []
def test_url_with_endpoint(): api = BaseAPI(2) assert api._url('fact-names') == 'http://localhost:8080/v2/fact-names'
def test_url_with_unknown_endpoint(): api = BaseAPI(2) with pytest.raises(APIError): api._url('bananas')
def test_resources(): api = BaseAPI(2) with pytest.raises(NotImplementedError): api.resources()
def test_node(): api = BaseAPI(2) with pytest.raises(NotImplementedError): api.node()
def test_query_with_limit(stub_get): api = BaseAPI(2) stub_get('http://localhost:8080/v2/nodes?limit=""', body='[]') response = api._query('nodes', limit="") assert response == []
def test_with_invalid_ssl_config(): with pytest.raises(ImproperlyConfiguredError): api = BaseAPI(3, ssl=True, ssl_cert='ssl.cert')
def test_api2_endpoints(): api = BaseAPI(2) assert api.version == 'v2' assert api.endpoints == ENDPOINTS[2]
def test_with_valid_ssl_config(): api = BaseAPI(3, ssl=True, ssl_key='ssl.key', ssl_cert='ssl.cert') assert api.ssl is True assert api.ssl_key == 'ssl.key' assert api.ssl_cert == 'ssl.cert' assert api.protocol == 'https'
def test_query_empty_body(stub_get): api = BaseAPI(2) stub_get('http://localhost:8080/v2/nodes', body='null') with pytest.raises(EmptyResponseError): api._query('nodes')
def test_build_url(): api = BaseAPI(2) assert api.base_url == 'http://localhost:8080'
def test_query_with_include_total(stub_get): api = BaseAPI(2) stub_get('http://localhost:8080/v2/nodes?include-total=""', body='[]') response = api._query('nodes', include_total="") assert response == []