<commit_before>import httplib
from contextlib import contextmanager

from django.test import TestCase
from django.test.client import Client
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from purl import URL


@contextmanager
def patch_settings(**kwargs):
    from django.conf import settings
    backup = {}
    for key, value in kwargs.items():
        if hasattr(settings, key):
            backup[key] = getattr(settings, key)
        setattr(settings, key, value)
    yield
    for key, value in backup.items():
        setattr(settings, key, value)


class ClientTestCase(TestCase):
    username = 'dummyuser'
    email = '<EMAIL>'
    password = '<PASSWORD>'
    is_anonymous = False
    is_staff = False
    is_superuser = False

    def setUp(self):
        self.client = Client()
        if not self.is_anonymous:
            self.user = self.create_user()
            self.client.login(username=self.username,
                              password=self.password)

    def create_user(self):
        user = User.objects.create_user(self.username,
                                        self.email,
                                        self.password)
        user.is_staff = self.is_staff
        user.is_superuser = self.is_superuser
        user.save()
        return user

    def assertIsRedirect(self, response, expected_url=None):
        self.assertTrue(response.status_code in (httplib.FOUND,
                                                 httplib.MOVED_PERMANENTLY))
        if expected_url:
            location = URL.from_string(response['Location'])
            self.assertEqual(expected_url, location.path())

    def assertRedirectUrlName(self, response, name):
        self.assertIsRedirect(response)
        location = response['Location'].replace('http://testserver', '')
        self.assertEqual(location, reverse(name))

    def assertIsOk(self, response):
        self.assertEqual(httplib.OK, response.status_code)

    def assertInContext(self, response, key):
        self.assertTrue(key in response.context, "Context should contain a variable '%s'" % key)<commit_msg>Updated test client to make logging in explicit<commit_after>import httplib
from contextlib import contextmanager

from django.test import TestCase
from django.test.client import Client
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from purl import URL


@contextmanager
def patch_settings(**kwargs):
    from django.conf import settings
    backup = {}
    for key, value in kwargs.items():
        if hasattr(settings, key):
            backup[key] = getattr(settings, key)
        setattr(settings, key, value)
    yield
    for key, value in backup.items():
        setattr(settings, key, value)


class ClientTestCase(TestCase):
    username = 'dummyuser'
    email = '<EMAIL>'
    password = '<PASSWORD>'
    is_anonymous = False
    is_staff = False
    is_superuser = False

    def setUp(self):
        self.client = Client()
        if not self.is_anonymous:
            self.login()

    def login(self):
        self.user = self.create_user()
        self.client.login(username=self.username,
                          password=self.password)

    def create_user(self):
        user = User.objects.create_user(self.username,
                                        self.email,
                                        self.password)
        user.is_staff = self.is_staff
        user.is_superuser = self.is_superuser
        user.save()
        return user

    def assertIsRedirect(self, response, expected_url=None):
        self.assertTrue(response.status_code in (httplib.FOUND,
                                                 httplib.MOVED_PERMANENTLY))
        if expected_url:
            location = URL.from_string(response['Location'])
            self.assertEqual(expected_url, location.path())

    def assertRedirectUrlName(self, response, name):
        self.assertIsRedirect(response)
        location = response['Location'].replace('http://testserver', '')
        self.assertEqual(location, reverse(name))

    def assertIsOk(self, response):
        self.assertEqual(httplib.OK, response.status_code)

    def assertInContext(self, response, key):
        self.assertTrue(key in response.context, "Context should contain a variable '%s'" % key)
{'fraction_non_alphanumeric': 0.09301260022909508, 'fraction_numerical': 0.0, 'mean_word_length': 2.3976653696498054, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6400621', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1137, 'n_words': 283}