<commit_before>from django.test import TestCase
from django.core.cache import cache

import urlparse


class HttpCodeTestCase(TestCase):
    # TODO: this should be a private method.
    def assertHttpCode(self, response, code, code_description):
        self.assertEqual(
            response.status_code, code,
            "Expected an HTTP %s (%s) response, but got HTTP %s" %
            (code, code_description, response.status_code))

    def assertHttpOK(self, response):
        self.assertHttpCode(response, 200, "OK")

    def assertHttpCreated(self, response):
        self.assertHttpCode(response, 201, "Created")

    def assertHttpRedirect(self, response, location=None):
        """Assert that we had any redirect status code.

        """
        self.assertTrue(
            300 <= response.status_code < 400,
            "Expected an HTTP 3XX (redirect) response, but got HTTP %s" %
            response.status_code
        )

        if location:
            if location.startswith("http://testserver/"):
                absolute_location = location
            else:
                absolute_location = urlparse.urljoin("http://testserver/",  location)

            self.assertEqual(response['Location'], absolute_location)


    def assertHttpBadRequest(self, response):
        self.assertHttpCode(response, 400, "Bad Request")

    def assertHttpUnauthorized(self, response):
        self.assertHttpCode(response, 401, "Unauthorized")

    def assertHttpForbidden(self, response):<commit_msg>Fix urljoin import for Python 3<commit_after>from django.test import TestCase
from django.core.cache import cache

try:
    from urlparse import urljoin  # python2
except ImportError:
    from urllib.parse import urljoin  # python3


class HttpCodeTestCase(TestCase):
    # TODO: this should be a private method.
    def assertHttpCode(self, response, code, code_description):
        self.assertEqual(
            response.status_code, code,
            "Expected an HTTP %s (%s) response, but got HTTP %s" %
            (code, code_description, response.status_code))

    def assertHttpOK(self, response):
        self.assertHttpCode(response, 200, "OK")

    def assertHttpCreated(self, response):
        self.assertHttpCode(response, 201, "Created")

    def assertHttpRedirect(self, response, location=None):
        """Assert that we had any redirect status code.

        """
        self.assertTrue(
            300 <= response.status_code < 400,
            "Expected an HTTP 3XX (redirect) response, but got HTTP %s" %
            response.status_code
        )

        if location:
            if location.startswith("http://testserver/"):
                absolute_location = location
            else:
                absolute_location = urljoin("http://testserver/", location)

            self.assertEqual(response['Location'], absolute_location)


    def assertHttpBadRequest(self, response):
        self.assertHttpCode(response, 400, "Bad Request")

    def assertHttpUnauthorized(self, response):
        self.assertHttpCode(response, 401, "Unauthorized")

    def assertHttpForbidden(self, response):
{'fraction_non_alphanumeric': 0.09499521836149187, 'fraction_numerical': 0.01306981192221868, 'mean_word_length': 2.7446300715990453, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2446409', 'n_tokens_mistral': 861, 'n_tokens_neox': 801, 'n_words': 229}