Esempio n. 1
0
def test_json_view_already_httpresponse(rf):
    request = rf.get('/')

    def func(request):
        return HttpResponse('something')

    func = utils.json_view(func)
    response = func(request)
    assert isinstance(response, HttpResponse)
    assert smart_text(response.content) == 'something'
    assert response.status_code == 200
Esempio n. 2
0
def test_json_view_custom_status(rf):
    request = rf.get('/')

    def func(request):
        return {'one': 'One'}, 403

    func = utils.json_view(func)
    response = func(request)
    assert isinstance(response, HttpResponse)
    assert json.loads(response.content) == {'one': 'One'}
    assert response.status_code == 403
Esempio n. 3
0
    def test_json_view_custom_status(self):
        request = RequestFactory().get('/')

        def func(request):
            return {'one': 'One'}, 403

        func = utils.json_view(func)
        response = func(request)
        ok_(isinstance(response, HttpResponse))
        eq_(json.loads(response.content), {'one': 'One'})
        eq_(response.status_code, 403)
Esempio n. 4
0
def test_json_view_indented(rf):
    request = rf.get('/?pretty=print')

    def func(request):
        return {'one': 'One'}

    func = utils.json_view(func)
    response = func(request)
    assert isinstance(response, HttpResponse)
    assert json.dumps({'one': 'One'}, indent=2) == smart_text(response.content)
    assert response.status_code == 200
Esempio n. 5
0
    def test_json_view_indented(self):
        request = RequestFactory().get('/?pretty=print')

        def func(request):
            return {'one': 'One'}

        func = utils.json_view(func)
        response = func(request)
        ok_(isinstance(response, HttpResponse))
        eq_(json.dumps({'one': 'One'}, indent=2), response.content)
        eq_(response.status_code, 200)
Esempio n. 6
0
    def test_json_view_already_httpresponse(self):
        request = RequestFactory().get('/')

        def func(request):
            return HttpResponse('something')

        func = utils.json_view(func)
        response = func(request)
        ok_(isinstance(response, HttpResponse))
        eq_(response.content, 'something')
        eq_(response.status_code, 200)
Esempio n. 7
0
def test_json_view_custom_status(rf):
    request = rf.get('/')

    def func(request):
        return {'one': 'One'}, 403

    func = utils.json_view(func)
    response = func(request)
    assert isinstance(response, HttpResponse)
    assert json.loads(response.content) == {'one': 'One'}
    assert response.status_code == 403
Esempio n. 8
0
def test_json_view_basic(rf):
    request = rf.get("/")

    def func(request):
        return {"one": "One"}

    func = utils.json_view(func)
    response = func(request)
    assert isinstance(response, HttpResponse)
    assert json.loads(response.content) == {"one": "One"}
    assert response.status_code == 200
Esempio n. 9
0
def test_json_view_indented(rf):
    request = rf.get('/?pretty=print')

    def func(request):
        return {'one': 'One'}

    func = utils.json_view(func)
    response = func(request)
    assert isinstance(response, HttpResponse)
    assert json.dumps({'one': 'One'}, indent=2) == smart_text(response.content)
    assert response.status_code == 200
Esempio n. 10
0
def test_json_view_already_httpresponse(rf):
    request = rf.get('/')

    def func(request):
        return HttpResponse('something')

    func = utils.json_view(func)
    response = func(request)
    assert isinstance(response, HttpResponse)
    assert smart_text(response.content) == 'something'
    assert response.status_code == 200
Esempio n. 11
0
    def test_json_view_custom_status(self):
        request = RequestFactory().get('/')

        def func(request):
            return {'one': 'One'}, 403

        func = utils.json_view(func)
        response = func(request)
        ok_(isinstance(response, HttpResponse))
        eq_(json.loads(response.content), {'one': 'One'})
        eq_(response.status_code, 403)
Esempio n. 12
0
    def test_json_view_already_httpresponse(self):
        request = RequestFactory().get('/')

        def func(request):
            return HttpResponse('something')

        func = utils.json_view(func)
        response = func(request)
        ok_(isinstance(response, HttpResponse))
        eq_(response.content, 'something')
        eq_(response.status_code, 200)
Esempio n. 13
0
    def test_json_view_indented(self):
        request = RequestFactory().get('/?pretty=print')

        def func(request):
            return {'one': 'One'}

        func = utils.json_view(func)
        response = func(request)
        ok_(isinstance(response, HttpResponse))
        eq_(json.dumps({'one': 'One'}, indent=2), response.content)
        eq_(response.status_code, 200)
Esempio n. 14
0
    def test_json_view_already_httpresponse(self):
        request = RequestFactory().get('/')

        def func(request):
            return HttpResponse('something')

        func = utils.json_view(func)
        response = func(request)
        assert isinstance(response, HttpResponse)
        assert response.content == 'something'
        assert response.status_code == 200
Esempio n. 15
0
    def test_json_view_basic(self):
        request = RequestFactory().get('/')

        def func(request):
            return {'one': 'One'}

        func = utils.json_view(func)
        response = func(request)
        assert isinstance(response, HttpResponse)
        assert json.loads(response.content) == {'one': 'One'}
        assert response.status_code == 200