

@override_settings(DEBUG=True)
def test_api_returns_decorator_debug(self):
    '\n        Test that the @api_returns decorator (in debug mode)\n        '

    @api_returns({
        200: 'OK',
        403: 'Permission denied',
    })
    def simple_view(request):
        if ('ok' in request.GET):
            return JsonResponse()
        elif ('noperm' in request.GET):
            return JsonResponseForbidden()
        else:
            return JsonResponseAccepted()
    rf = RequestFactory()
    request = rf.get('/simple_view', data={
        'ok': '1',
    })
    response = simple_view(request)
    self.assertEquals(response.status_code, 200)
    request = rf.get('/simple_view', data={
        'noperm': '1',
    })
    response = simple_view(request)
    self.assertEquals(response.status_code, 403)
    request = rf.get('/simple_view', data={
        'bad': '1',
    })
    response = simple_view(request)
    self.assertEquals(response.status_code, 400)

    @api_returns({
        200: 'OK',
    })
    def datetime_view(request):
        user = User.objects.create()
        users = User.objects.all()
        return JsonResponse({
            'date': datetime.date(2010, 2, 17),
            'datetime': datetime.datetime(2006, 11, 21, 16, 30),
            'time': datetime.time(16, 30),
            'user': user,
            'users': users,
        })
    request = rf.get('/datetime_view')
    response = datetime_view(request)
    self.assertEquals(response.status_code, 200)

dataset/ETHPy150Open bipsandbytes/django-api/django_api/tests.py SimpleTest.test_api_returns_decorator_debug/original