Пример #1
0
def test_format_action(openapi_specs, action_factory):
    formatter = DefaultFormatter(openapi_specs)
    action = action_factory(path='products/PRD-000/endsale')
    formatted = formatter.format(action)
    assert 'Endsale action' in formatted
    assert 'path: /products/PRD-000/endsale' in formatted

    action = action_factory(path='does-not-exists')
    formatted = formatter.format(action)
    assert 'does not exist' in formatted
Пример #2
0
def test_format_resource(openapi_specs, res_factory):
    formatter = DefaultFormatter(openapi_specs)
    res = res_factory(path='products/PRD-000')
    formatted = formatter.format(res)
    assert 'Product resource' in formatted
    assert 'path: /products/PRD-000' in formatted

    res = res_factory(path='subscriptions/assets/AS-0000')
    formatted = formatter.format(res)
    assert 'Asset resource' in formatted
    assert 'path: /subscriptions/assets/AS-0000' in formatted

    res = res_factory(path='does-not-exists')
    formatted = formatter.format(res)
    assert 'does not exist' in formatted
Пример #3
0
def test_format_rs(openapi_specs, rs_factory):
    formatter = DefaultFormatter(openapi_specs)
    rs = rs_factory(path='products')
    formatted = formatter.format(rs)
    assert 'Search the Products collection' in formatted
    assert 'path: /products' in formatted
    assert 'Available filters' in formatted

    rs = rs_factory(path='products/PRD-000/items')
    formatted = formatter.format(rs)
    assert 'Search the Items collection' in formatted
    assert 'path: /products/PRD-000/items' in formatted
    assert 'Available filters' in formatted

    rs = rs_factory(path='does-not-exists')
    formatted = formatter.format(rs)
    assert 'does not exist' in formatted
Пример #4
0
    def __init__(
        self,
        api_key,
        endpoint=None,
        use_specs=True,
        specs_location=None,
        validate_using_specs=True,
        default_headers=None,
        default_limit=100,
        max_retries=0,
    ):
        """
        Create a new instance of the ConnectClient.

        :param api_key: The API key used for authentication.
        :type api_key: str
        :param endpoint: The API endpoint, defaults to CONNECT_ENDPOINT_URL
        :type endpoint: str, optional
        :param specs_location: The Connect OpenAPI specification local path or URL, defaults to
                               CONNECT_SPECS_URL
        :type specs_location: str, optional
        :param default_headers: Http headers to apply to each request, defaults to {}
        :type default_headers: dict, optional
        """
        if default_headers and 'Authorization' in default_headers:
            raise ValueError(
                '`default_headers` cannot contains `Authorization`')

        self.endpoint = endpoint or CONNECT_ENDPOINT_URL
        self.api_key = api_key
        self.default_headers = default_headers or {}
        self.default_limit = default_limit
        self.max_retries = max_retries
        self._use_specs = use_specs
        self._validate_using_specs = validate_using_specs
        self.specs_location = specs_location or CONNECT_SPECS_URL
        self.specs = None
        if self._use_specs:
            self.specs = OpenAPISpecs(self.specs_location)
        self.response = None
        self._help_formatter = DefaultFormatter(self.specs)
Пример #5
0
def test_format_collection_not_exists(openapi_specs, col_factory):
    formatter = DefaultFormatter(openapi_specs)
    col = col_factory(path='does-not-exists')
    formatted = formatter.format(col)
    assert 'does not exist' in formatted
Пример #6
0
def test_no_specs():
    formatter = DefaultFormatter(None)
    formatted = formatter.format(None)
    assert 'No OpenAPI specs available.' in formatted
Пример #7
0
def test_format_collection(openapi_specs, col_factory, title, path):
    formatter = DefaultFormatter(openapi_specs)
    col = col_factory(path=path)
    formatted = formatter.format(col)
    assert f'{title} collection' in formatted
    assert f'path: /{path}' in formatted
Пример #8
0
def test_format_ns_not_exist(openapi_specs, ns_factory):
    formatter = DefaultFormatter(openapi_specs)
    ns = ns_factory(path='does-not-exists')
    formatted = formatter.format(ns)
    assert 'does not exist' in formatted
Пример #9
0
def test_format_ns(openapi_specs, ns_factory, title, path):
    formatter = DefaultFormatter(openapi_specs)
    ns = ns_factory(path=path)
    formatted = formatter.format(ns)
    assert f'{title} namespace' in formatted
    assert f'path: /{path}' in formatted
Пример #10
0
def test_format_client(openapi_specs):
    formatter = DefaultFormatter(openapi_specs)
    formatted = formatter.format(None)
    assert openapi_specs.title in formatted
    assert openapi_specs.version in formatted