Ejemplo n.º 1
0
def create_schema(type='object',
                  default=None,
                  format=None,
                  title=None,
                  description=None,
                  readonly=None,
                  example=None,
                  **kwargs):

    required = kwargs.pop('required', False)
    discriminator = kwargs.pop('discriminator', None)

    schema = not_none({
        'type': type,
        'format': format,
        'title': title,
        'description': description,
        'readOnly': readonly,
        'default': _eval(default),
        'example': example,
        **kwargs
    })

    return immutable({
        '__schema__': schema,
        'schema': lambda: schema,
        'required': required,
        'discriminator': discriminator,
        'description': description
    })
Ejemplo n.º 2
0
def meta(version='1.0',
         title='API',
         host=None,
         description=None,
         terms_url=None,
         contact=None,
         contact_url=None,
         contact_email=None,
         license=None,
         license_url=None,
         authorizations=None,
         security=None,
         tags=None,
         base_path='/',
         representations=None):

    return immutable(
        dict(version=version,
             title=title,
             host=host,
             description=description,
             terms_url=terms_url,
             contact=contact,
             contact_url=contact_url,
             contact_email=contact_email,
             license=license,
             license_url=license_url,
             authorizations=authorizations,
             security=security,
             tags=tags or [],
             base_path=base_path,
             representations=representations or ['application/json']))
Ejemplo n.º 3
0
def test_create_header_object():
    result = openapi.create_header_object('X-Mock-Header')
    assert result == {'description': 'X-Mock-Header', 'type': 'string'}

    result = openapi.create_header_object({
        'type':
        int,
        'description':
        'MOCK_HEADER_DESCRIPTION'
    })
    assert result == {
        'type': 'integer',
        'description': 'MOCK_HEADER_DESCRIPTION',
    }

    result = openapi.create_header_object({
        'type': [int],
        'description':
        'MOCK_HEADER_DESCRIPTION'
    })
    assert result == {
        'type': 'array',
        'items': {
            'type': 'integer'
        },
        'description': 'MOCK_HEADER_DESCRIPTION',
    }

    mock_mock = immutable(__schema__={'MOCK_KEY': 'MOCK_KEY_VALUE'})
    result = openapi.create_header_object({'type': mock_mock})
    assert result == {'type': mock_mock, 'MOCK_KEY': 'MOCK_KEY_VALUE'}
Ejemplo n.º 4
0
def test_immutable_raises_when_set():
    obj = immutable(x=2, y=23)

    with pytest.raises(TypeError):
        obj['x'] = 5

    with pytest.raises(TypeError):
        obj.x = 5

    with pytest.raises(TypeError):
        del obj['x']

    with pytest.raises(TypeError):
        del obj.x
Ejemplo n.º 5
0
def schema(handlers=None, metadata=None):

    handlers = handlers or []
    metadata = metadata or {}
    metadata = meta(**metadata)

    def register(handler):
        return schema(handlers=[*handlers, handler], metadata=metadata)

    def generate():
        return OpenApi(metadata, handlers).as_dict()

    return immutable(
        dict(register=register,
             generate=generate,
             handlers=handlers,
             metadata=metadata))
Ejemplo n.º 6
0
def test_expected_params():

    mock_apidoc = immutable(expect=[('ProblemDetails', 'MOCK_DESCRIPTION')])

    result = openapi.expected_params(mock_apidoc)
    expected = {
        'payload': {
            'name': 'payload',
            'required': True,
            'in': 'body',
            'schema': {
                '$ref': '#/definitions/ProblemDetails'
            },
            'description': 'MOCK_DESCRIPTION'
        }
    }

    assert result == expected
Ejemplo n.º 7
0
def make_mock_metadata(**overrides):
    return immutable({
        **{
            'title': 'mock title',
            'version': '1.0.0',
            'description': 'test mock api description',
            'terms_url': 'test mock terms url',
            'contact': 'test mock contact',
            'contact_email': '*****@*****.**',
            'contact_url': 'notreal.com/test/mock',
            'license': 'mock test license',
            'license_url': 'notreal.com/test/mock',
            'tags': ['mock', 'tag'],
            'representations': None,
            'authorizations': None,
            'security': None,
            'host': 'mock test host'
        },
        **overrides
    })
Ejemplo n.º 8
0
def test_immutable_equality():
    a = immutable(x=2, y=23)
    b = immutable(x=2, y=23)

    assert a == b
Ejemplo n.º 9
0
def test_immutable_str_dumps_json():
    obj = immutable(x=2, y=23)
    s = str(obj)
    json.loads(s)
Ejemplo n.º 10
0
def test_immutable_repr_dumps_json():
    obj = immutable(x=2, y=23)
    r = repr(obj)
    json.loads(r)
Ejemplo n.º 11
0
def test_immutable_none_comparison():
    obj = immutable(x=2, y=23)
    isEqual = obj == None
    assert isEqual is not True