Exemplo n.º 1
0
    def test_method_param(self):
        # non-AJAX
        response = self.client.get('/test_jsonify/method_param/')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['content-type'], 'text/html; charset=utf-8')
        self.assertEqual(response.content, 'In a method')

        # AJAX
        response = self.client.get('/test_jsonify/method_param/',
                                   HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['content-type'], 'application/json')
        self.assertEqual(json.loads(response.content), {
            'content': 'In a method',
        })
Exemplo n.º 2
0
    def test_basic_dict(self):
        # non-AJAX
        response = self.client.get('/test_jsonify/basic/dict/')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['content-type'], 'text/html; charset=utf-8')
        self.assertEqual(response.content, 'In a dict')

        # AJAX
        response = self.client.get('/test_jsonify/basic/dict/',
                                   HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['content-type'], 'application/json')
        self.assertEqual(json.loads(response.content), {
            'content': 'In a dict',
            'other': 'miscellaneous',
        })
Exemplo n.º 3
0
 def test_render_to_json(self):
     response = self.client.get('/test_render/')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response['content-type'], 'application/json')
     self.assertEqual(json.loads(response.content), 'hello')