0

Tastypie を使用して POST API を作成しようとしています。郵便配達員から実行しているときは正常に動作しています。しかし、同じもののためにdjangoテストを作成したとき、データは入ってきませrequest.POSTrequest.body. ジャンゴテストを使用して郵便配達員と同様にテストする方法はありますか? 私はそれが入ってくることを知っていますがrequest.body、なぜそれは郵便配達員から働いているのですか? これ(https://django-tastypie.readthedocs.org/en/latest/testing.html)もフォローしましたが、同じ問題です。

api.py

class CustResource(Resource):
    class Meta:
        resource_name = 'customer'
        authentication = ApiKeyAuthentication()

    def prepend_urls(self):
        return [
            url(r"^(?P<resource_name>%s)/register%s$" %
                (self._meta.resource_name, trailing_slash()),
                self.wrap_view('register_me'), name="api_register_me")
                ]

    def register_me(self, request, **kwargs):
        self.method_check(request, allowed=['post'])
        self.is_authenticated(request)

        response = {"status": 'error', 'data':{'error_code': '9999'},
                'message':'some issue'}

        return self.create_response(request, response)

tests.py

class RestApiTests(TestCase):

    def setUp(self):
        """
        create
        """
        self.user = User.objects.create_user(username="anuj",email="anuj@gmail.com",password="testing")
        self.apikey = ApiKey.objects.get(user=self.user)

    def test1(self):
        """
        """
        client = Client()
        json_str = json.dumps({'format':'json','username':'anuj','api_key':'fc32bd921bb6386c945229e675704818b29dadf0'})
        response = client.post('/api/v1/customer/register/',data=json_str, content_type='application/json')
        print response.status_code
        self.assertEqual(response.status_code, 200, msg="Wrong status code")
4

0 に答える 0