示例#1
0
 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__)
示例#2
0
    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),
        }
示例#3
0
    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)}}
            ]
        }
示例#4
0
 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}]
     }
示例#5
0
    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']}]}
示例#6
0
 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
             }
         ]
     }
示例#7
0
 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]}
         ]
     }
示例#8
0
    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)}}
            ],
        }
示例#9
0
 def test_empty(self):
     assert m.parse(None) is None
     assert m.parse('test') is None