def test_bad_status_code_matcher(self): """Schema:: GET /users x00 [ {"id": i32, "name": string(32)}, ... ] """ with self.assertRaises(m._InternalGrammarError): m.parse(self.test_bad_status_code_matcher.__doc__)
def test_string_escape(self): """Schema:: POST /user {"specialkey\\"\\t\\r": i8} 200/4XX/5XX """ schema = m.parse(self.test_string_escape.__doc__) assert schema['request']['schema'] == { 'specialkey"\t\r': (m.T_I8, False), }
def test_simple(self): """Schema:: POST/PUT /item { "name": string, "number": i16, // a simple number "children": [ {"id": i32}, ... ] } 200 { "id": i32, "name": string, "number": i16, "children": [ {"id": i32}, ... ] } 4XX/5XX {"message": string} """ schema = m.parse(self.test_simple.__doc__) assert schema == { 'request': { 'route': ['/item', {}], 'methods': [m.M_POST, m.M_PUT], 'schema': { 'name': ((m.T_STRING, None), False), 'number': (m.T_I16, False), 'children': ([({'id': (m.T_I32, False)}, False), m.S_ELLIPSIS], False) }, }, 'responses': [ {'status_code': [200], 'schema': { 'id': (m.T_I32, False), 'name': ((m.T_STRING, None), False), 'number': (m.T_I16, False), 'children': ([({'id': (m.T_I32, False)}, False), m.S_ELLIPSIS], False) }}, {'status_code': ['4XX', '5XX'], 'schema': {'message': ((m.T_STRING, None), False)}} ] }
def test_no_content(self): """Schema:: GET /user/<i32:id> 201 """ schema = m.parse(self.test_no_content.__doc__) assert schema == { 'request': { 'route': ['/user/<id>', {'id': m.T_I32}], 'methods': [m.M_GET], 'schema': None, }, 'responses': [{'status_code': [201], 'schema': None}] }
def test_empty_response(self): """Schema:: DELETE /user/<i32:id> 201 4XX/5XX {"error": string} """ schema = m.parse(self.test_empty_response.__doc__) assert schema == {'request': {'methods': [4], 'route': ['/user/<id>', {'id': 8}], 'schema': None}, 'responses': [{'schema': None, 'status_code': [201]}, {'schema': {'error': ((11, None), False)}, 'status_code': ['4XX', '5XX']}]}
def test_nullable_schema(self): """Schema:: GET /users {"name": string(33)*} 201 """ schema = m.parse(self.test_nullable_schema.__doc__) assert schema == { 'request': { 'methods': [m.M_GET], 'route': ['/users', {}], 'schema': { 'name': ((m.T_STRING, 33), True) } }, 'responses': [ { 'status_code': [201], 'schema': None } ] }
def test_schema_array(self): """Schema: GET /users 200 [ {"id": i32, "name": string(32)}, ... ] """ schema = m.parse(self.test_schema_array.__doc__) assert schema == { 'request': { 'route': ['/users', {}], 'methods': [m.M_GET], 'schema': None, }, 'responses': [ {'status_code': [200], 'schema': [({'id': (m.T_I32, False), 'name': ( (m.T_STRING, 32), False)}, False), m.S_ELLIPSIS]} ] }
def test_alternative_schema_sign(self): """Schema: GET /user/<i32:id> 200 { "id": i32, "name": string(33) } """ schema = m.parse(self.test_alternative_schema_sign.__doc__) assert schema == { 'request': { 'route': ['/user/<id>', {'id': m.T_I32}], 'methods': [m.M_GET], 'schema': None, }, 'responses': [ {'status_code': [200], 'schema': {'id': (m.T_I32, False), 'name': ((m.T_STRING, 33), False)}} ], }
def test_empty(self): assert m.parse(None) is None assert m.parse('test') is None