def test_empty_prefix_detail(self):
     response = self.client.get('/empty-prefix/1/')
     assert response.status_code == 200
     assert json.loads(response.content.decode('utf-8')) == {
         'uuid': '111',
         'text': 'First'
     }
Ejemplo n.º 2
0
    def test_renders_openapi_json_schema(self):
        expected_out = {
            "openapi": "3.0.0",
            "info": {
                "version": "",
                "title": "",
                "description": ""
            },
            "servers": [
                {
                    "url": ""
                }
            ],
            "paths": {
                "/": {
                    "get": {
                        "operationId": "list"
                    }
                }
            }
        }
        call_command('generateschema',
                     '--format=openapi-json',
                     stdout=self.out)
        out_json = json.loads(self.out.getvalue())

        self.assertDictEqual(out_json, expected_out)
    def test_render_dict_abc_obj(self):
        class Dict(MutableMapping):
            def __init__(self):
                self._dict = {}

            def __getitem__(self, key):
                return self._dict.__getitem__(key)

            def __setitem__(self, key, value):
                return self._dict.__setitem__(key, value)

            def __delitem__(self, key):
                return self._dict.__delitem__(key)

            def __iter__(self):
                return self._dict.__iter__()

            def __len__(self):
                return self._dict.__len__()

            def keys(self):
                return self._dict.keys()

        x = Dict()
        x['key'] = 'string value'
        x[2] = 3
        ret = JSONRenderer().render(x)
        data = json.loads(ret.decode('utf-8'))
        self.assertEqual(data, {'key': 'string value', '2': 3})
 def test_regex_url_path_detail(self):
     pk = '1'
     kwarg = '1234'
     response = self.client.get('/regex/{}/detail/{}/'.format(pk, kwarg))
     assert response.status_code == 200
     assert json.loads(response.content.decode('utf-8')) == {
         'pk': pk,
         'kwarg': kwarg
     }
 def test_empty_prefix_list(self):
     response = self.client.get('/empty-prefix/')
     assert response.status_code == 200
     assert json.loads(response.content.decode('utf-8')) == [{
         'uuid': '111',
         'text': 'First'
     }, {
         'uuid':
         '222',
         'text':
         'Second'
     }]
 def test_regex_url_path_list(self):
     kwarg = '1234'
     response = self.client.get('/regex/list/{}/'.format(kwarg))
     assert response.status_code == 200
     assert json.loads(response.content.decode('utf-8')) == {'kwarg': kwarg}
Ejemplo n.º 7
0
    def test_loads(self):
        with self.assertRaises(ValueError):
            json.loads("Infinity")

        with self.assertRaises(ValueError):
            json.loads("NaN")
 def test_render_queryset_values_list(self):
     o = DummyTestModel.objects.create(name='dummy')
     qs = DummyTestModel.objects.values_list('id', 'name')
     ret = JSONRenderer().render(qs)
     data = json.loads(ret.decode('utf-8'))
     self.assertEqual(data, [[o.id, o.name]])