예제 #1
0
    def test_read_only(self):
        """ make sure read-only for property works """
        op = self.app.s('/k').post
        self.assertRaises(Exception, op, p1=dict(protected=1))

        resp = io.Response(op)
        resp.apply_with(0, '{"protected":1}') # allowed
예제 #2
0
파일: test_io.py 프로젝트: manatlan/appswag
 def test_raw_in_utf8(self):
     """ utf-8 encoding should support by default
     """
     resp = io.Response(self.app.s('/resp2').get)
     resp.apply_with(
         status=200,
         raw=six.BytesIO(
             six.u('{"message":"測試資料A"}').encode('utf8')).getvalue())
예제 #3
0
 def test_raw_body_only(self):
     """ an option skip passing body byte stream to swagger-primitive-factory
     """
     r = '{"id": 0, "message": "test string 2"}'
     resp = io.Response(self.app.s('/resp').get)
     resp.raw_body_only = True
     resp.apply_with(404, r)
     self.assertEqual(resp.status, 404)
     self.assertEqual(resp.raw, r)
     self.assertFalse(isinstance(resp.data, primitives.Model))
예제 #4
0
    def test_response_schema_with_status(self):
        """ make sure schema works as expected """

        # make sure exception raised
        resp = io.Response(self.app.s('/resp').get)
        self.assertRaises(Exception, resp.apply_with, None, 'some string')

        # test for 'default'
        resp = io.Response(self.app.s('/resp').get)
        resp.apply_with(0, 'test string', {'content-type': 'text/plain'})
        self.assertEqual(resp.status, 0)
        self.assertEqual(resp.raw, 'test string')
        self.assertEqual(resp.data, 'test string')

        # test for specific status code
        r = '{"id": 0, "message": "test string 2"}'
        resp = io.Response(self.app.s('/resp').get)
        resp.apply_with(404, r)
        self.assertEqual(resp.status, 404)
        self.assertEqual(resp.raw, r)
        self.assertTrue(isinstance(resp.data, primitives.Model))
예제 #5
0
    def test_header_in_response(self):
        """ header in response """
        resp = io.Response(self.app.s('/t').get)

        resp.apply_with(status=200,
                        raw=None,
                        header=dict(test='1|2,3|4,5|6 7|8,9|10 11|12,13|14'))
        # note that the test case here is the same as the one above,
        # difference is we would wrap an additional array in header
        self.assertEqual(resp.header['test'],
                         [[[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10]],
                           [[11, 12], [13, 14]]]])
예제 #6
0
    def test_error_only_status(self):
        """ it's legal for a Swagger without any successful status Response object.
        in this case, users need to access response via Response.raw
        """
        resp = io.Response(self.app.s('/resp').post)

        # make sure we are ok when no matching status and without a 'default'
        resp.apply_with(200, 'some data')
        self.assertEqual(resp.status, 200)
        self.assertEqual(resp.raw, 'some data')
        self.assertEqual(resp.data, None)

        # make sure header also works fine
        header = {'A': 1, 'B': '222'}
        resp.apply_with(200, None, header)
        self.assertEqual(resp.header, {'A': [1], 'B': ['222']})