Beispiel #1
0
    def test_query_schema_fail(self):
        self.callback = rest.schema(query_schema=volup.Schema({
            'a': rest.coerce_one(str),
            'b': rest.coerce_many(int),
        }))(self.callback)

        self.root_app.route('/foo', callback=self.callback)
        # There are two values for `a`. We only expect one.
        result = self.app.get('/foo?a=foo&b=bar&b=2&b=3', expect_errors=True)

        self.assertEqual(400, result.status_int)
Beispiel #2
0
    def test_query_schema(self):
        self.callback = rest.schema(
            query_schema=volup.Schema({
                'a': rest.coerce_one(str),
                'b': rest.coerce_many(int),
            }))(self.callback)

        self.root_app.route('/foo', callback=self.callback)
        result = self.app.get('/foo?a=foo&b=1&b=2&b=3')

        self.assertEqual(dict(query=dict(a='foo', b=[1, 2, 3])), result.json)
Beispiel #3
0
    def test_query_schema(self):
        self.callback = rest.schema(query_schema=volup.Schema({
            'a': rest.coerce_one(str),
            'b': rest.coerce_many(int),
        }))(self.callback)

        self.root_app.route('/foo', callback=self.callback)
        result = self.app.get('/foo?a=foo&b=1&b=2&b=3')

        self.assertEqual(
            dict(body=None, query=dict(a='foo', b=[1, 2, 3])),
            result.json
        )