def test_unique_items(self): A = array('not unique', unique_items=False) # no exception A([1, 1, 1, 2]) A = array('unique', unique_items=True) with pytest.raises(TypeSystemError, match='This item is not unique.'): A([1, 1, 1, 2])
def test_additional_items(self): A = array('a', items=[ string('string', max_length=1), integer('int', maximum=1234)], additional_items=True) # no exception A(['a', 2, 3, 4, True]) A = array('a', items=[ string('string', max_length=1), integer('int', maximum=1234)], additional_items=False) with pytest.raises(TypeSystemError, match='Too many items.'): A(['a', 2, 3, 4, True])
def test_get_example(self): A = array('No example of items') assert [1] == A.get_example() A = array('Defined example', example=['a', 'b']) assert ['a', 'b'] == A.get_example() A = array('No example, defined items', items=string('letter')) assert ['string'] == A.get_example() A = array('a', items=[ string('string', max_length=1, example='foo'), integer('int', maximum=1234, example=123)]) assert ['foo', 123] == A.get_example()
def test_max_items(self): A = array('a', max_items=3) # no exception A([1, 2, 3]) # Too many items with pytest.raises(TypeSystemError, match='Too many items'): A([1, 2, 3, 4])
def test_min_items(self): A = array('a', min_items=3) # no exception A([1, 2, 3]) # Too few items with pytest.raises(TypeSystemError, match='Not enough items'): A([1])
def test_items(self): A = array('array', items=string('string', max_length=1)) # no exception A(['a', 'b']) # Invalid type of items with pytest.raises(TypeSystemError, match="{0: 'Must have no more than 1 characters.'}"): A(['aa', 'b'])
def test_items_multiple_types(self): A = array('a', items=[ string('string', max_length=1, example='foo'), integer('int', maximum=1234, example=123)]) # no exception A(['b', 1234]) # Invalid type with pytest.raises(TypeSystemError, match="{1: 'Must be less than or equal to 1234.'}"): A(['b', 1235])
description = 'A note object' additional_properties = False properties = { 'note_id': NoteId, 'body': Body, 'done': Done, } required = ['body', 'done', 'note_id'] example = { 'body': 'Example Body', 'done': True, 'note_id': 1, } Notes = types.array('Array of notes', items=Note, example=[Note.example]) # -- mark-logic note = {'note_id': 1, 'body': 'Example body', 'done': True} # Note the type annotations on this function definition. This tells Doctor how # to parse and validate parameters for routes attached to this logic function. # The return type annotation will validate the response conforms to an # expected definition in development environments. In non-development # environments a warning will be logged. def get_note(note_id: NoteId, note_type: NoteType) -> Note: """Get a note by ID.""" if note_id != 1: raise NotFoundError('Note does not exist')
def test_nullable(self): A = array('array', items=string('string', max_length=1), nullable=True) # Just tests that this does not raise an exception. A(None)
""" from doctor.types import (array, boolean, enum, integer, new_type, number, string, Object, UnionType) def parse_comma_separated_str(value): return value.split(',') Age = integer('age', minimum=1, maximum=120, example=34) Auth = string('auth token', example='testtoken') Color = enum('Color', enum=['blue', 'green'], example='blue', case_insensitive=True) Colors = array('colors', items=Color, example=['green']) ExampleArray = array('ex description e', items=Auth, example=['ex', 'array']) TwoItems = array('two items', items=[Age, Color]) class ExampleObject(Object): description = 'ex description f' properties = {'str': Auth} additional_properties = False example = {'str': 'ex str'} ExampleObjects = array('ex objects', items=ExampleObject, example=[{ 'str': 'e'