<commit_before>"""
Test for JsonResponse and JsonResponseBadRequest util classes.
"""

from __future__ import absolute_import

import json
import unittest

import mock
from django.http import HttpResponse, HttpResponseBadRequest

from util.json_request import JsonResponse, JsonResponseBadRequest


class JsonResponseTestCase(unittest.TestCase):
    """
    A set of tests to make sure that JsonResponse Class works correctly.
    """
    def test_empty(self):
        resp = JsonResponse()
        self.assertIsInstance(resp, HttpResponse)
        self.assertEqual(resp.content.decode('utf-8'), "")
        self.assertEqual(resp.status_code, 204)
        self.assertEqual(resp["content-type"], "application/json")

    def test_empty_string(self):
        resp = JsonResponse("")
        self.assertIsInstance(resp, HttpResponse)
        self.assertEqual(resp.content.decode('utf-8'), "")
        self.assertEqual(resp.status_code, 204)
        self.assertEqual(resp["content-type"], "application/json")

    def test_string(self):
        resp = JsonResponse("foo")
        self.assertEqual(resp.content, '"foo"')
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp["content-type"], "application/json")

    def test_dict(self):
        obj = {"foo": "bar"}
        resp = JsonResponse(obj)
        compare = json.loads(resp.content.decode('utf-8'))
        self.assertEqual(obj, compare)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp["content-type"], "application/json")

    def test_set_status_kwarg(self):
        obj = {"error": "resource not found"}
        resp = JsonResponse(obj, status=404)
        compare = json.loads(resp.content.decode('utf-8'))
        self.assertEqual(obj, compare)
        self.assertEqual(resp.status_code, 404)<commit_msg>python 3 fixes<commit_after>"""
Test for JsonResponse and JsonResponseBadRequest util classes.
"""

from __future__ import absolute_import

import json
import unittest

import mock
from django.http import HttpResponse, HttpResponseBadRequest

from util.json_request import JsonResponse, JsonResponseBadRequest


class JsonResponseTestCase(unittest.TestCase):
    """
    A set of tests to make sure that JsonResponse Class works correctly.
    """
    def test_empty(self):
        resp = JsonResponse()
        self.assertIsInstance(resp, HttpResponse)
        self.assertEqual(resp.content.decode('utf-8'), "")
        self.assertEqual(resp.status_code, 204)
        self.assertEqual(resp["content-type"], "application/json")

    def test_empty_string(self):
        resp = JsonResponse("")
        self.assertIsInstance(resp, HttpResponse)
        self.assertEqual(resp.content.decode('utf-8'), "")
        self.assertEqual(resp.status_code, 204)
        self.assertEqual(resp["content-type"], "application/json")

    def test_string(self):
        resp = JsonResponse("foo")
        self.assertEqual(resp.content.decode('utf-8'), '"foo"')
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp["content-type"], "application/json")

    def test_dict(self):
        obj = {"foo": "bar"}
        resp = JsonResponse(obj)
        compare = json.loads(resp.content.decode('utf-8'))
        self.assertEqual(obj, compare)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp["content-type"], "application/json")

    def test_set_status_kwarg(self):
        obj = {"error": "resource not found"}
        resp = JsonResponse(obj, status=404)
        compare = json.loads(resp.content.decode('utf-8'))
        self.assertEqual(obj, compare)
        self.assertEqual(resp.status_code, 404)
{'fraction_non_alphanumeric': 0.12373391732822338, 'fraction_numerical': 0.012592389816589104, 'mean_word_length': 3.439854191980559, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '669137', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1005, 'n_words': 211}