# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import json

from flask.ext import restplus

from . import TestCase


class ReqParseTestCase(TestCase):
    def setUp(self):
        super(ReqParseTestCase, self).setUp()
        self.api = restplus.Api(self.app)
        self.parser = self.api.parser()

    def post(self, url, data, status=200):
        headers = {
            'Content-Type': 'application/json'
        }

        with self.app.test_client() as client:
            response = client.post(url, data=json.dumps(data), headers=headers)
            print response.data
            self.assertEquals(response.status_code, status)
            return json.loads(response.data.decode('utf8'))

    def test_parse_model(self):
        fields = self.api.model('Todo', {
            'task': restplus.fields.String(required=True)
        })

        case = self
        parser = self.parser
        parser.add_argument('todo', type=fields, required=True)

        @self.api.route('/reqparse', endpoint='reqparse')
        class TestApi(restplus.Resource):
            def post(self):
                args = case.parser.parse_args()
                case.assertEqual(args['todo'], {'task': 'aaa'})
                return args['todo']

        data = self.post('/reqparse', {'todo': {'task': 'aaa'}})
        self.assertEqual(data, {'task': 'aaa'})

@@ -861,28 +861,8 @@
 %7D)%0A%0A
-        case = self%0A
     
@@ -1102,21 +1102,16 @@
  args = 
-case.
 parser.p
@@ -1126,72 +1126,8 @@
 s()%0A
-                case.assertEqual(args%5B'todo'%5D, %7B'task': 'aaa'%7D)%0A
     

Simplify a test