def test_bad_request(self):
        request = RequestFactory().get('/')
        e = exceptions.BadRequest()

        response = e.get_response(request)
        self.assertIsInstance(response, http.HttpResponseBadRequest)
        self.assertEqual(response.status_code, 400)
 def test_bad_request_1(self):
     request = RequestFactory().get('/')
     handler = init_handler(BaseHandler(), request)
     
     try:
         raise exceptions.BadRequest('')
     except Exception, e:
         response = handler.handle_exception(e)
    def test_bad_request_3(self):
        request = RequestFactory().get('/')
        handler = init_handler(BaseHandler(), request)

        content = {'error1': 'description', 'error2': 'description'}
        try:
            raise exceptions.BadRequest(content)
        except Exception, e:
            response = handler.handle_exception(e)
    def test_bad_request_2(self):
        request = RequestFactory().get('/')
        handler = init_handler(BaseHandler(), request)

        content = 'some error here'
        try:
            raise exceptions.BadRequest(content)
        except Exception, e:
            response = handler.handle_exception(e)
예제 #5
0
    def validate(self):
        user = authenticate(
            username=self.request.data.get('username', ''),
            password=self.request.data.get('password', ''),
        )
        if not user or not user.is_active:
            raise exceptions.BadRequest('Incorrect credentials')

        self.request.data = user