<commit_before># Copyright (c) 2011 Resolver Systems Ltd.
# All Rights Reserved
#

from urlparse import urljoin

from mock import Mock

from resolver_test import ResolverTestMixins

import django
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User
from django.http import HttpRequest




class ResolverDjangoTestCase(django.test.TestCase, ResolverTestMixins):
    maxDiff = None


class ResolverViewTestCase(ResolverDjangoTestCase):

    def setUp(self):
        self.user = User(username='cherie')
        self.user.save()

        self.request = HttpRequest()
        self.request.session = Mock()
        self.request.user = self.user

        self.client.force_login(self.user)


    def assert_login_required(self, view_to_call):
        self.owner = self.request.user = AnonymousUser()
        self.request.get_full_path = lambda: "my_path"
        self.request.build_absolute_uri = lambda: "my_path"

        response = view_to_call()

        self.assertEquals(response.status_code, 302)
        self.assertEquals(
            response['Location'],
            urljoin(settings.LOGIN_URL, '?next=my_path')
        )

<commit_msg>Use different usernames for each test.  by: <NAME><commit_after># Copyright (c) 2017 PythonAnywhere LLP.
# All Rights Reserved
#

from urlparse import urljoin

from mock import Mock

from resolver_test import ResolverTestMixins

import django
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User
from django.http import HttpRequest




class ResolverDjangoTestCase(django.test.TestCase, ResolverTestMixins):
    maxDiff = None



usernumber = 0

class ResolverViewTestCase(ResolverDjangoTestCase):

    def setUp(self):
        global usernumber
        self.user = User.objects.create(username='cherie{}'.format(usernumber))
        usernumber += 1

        self.request = HttpRequest()
        self.request.session = Mock()
        self.request.user = self.user

        self.client.force_login(self.user)


    def assert_login_required(self, view_to_call):
        self.owner = self.request.user = AnonymousUser()
        self.request.get_full_path = lambda: "my_path"
        self.request.build_absolute_uri = lambda: "my_path"

        response = view_to_call()

        self.assertEquals(response.status_code, 302)
        self.assertEquals(
            response['Location'],
            urljoin(settings.LOGIN_URL, '?next=my_path')
        )


{'fraction_non_alphanumeric': 0.0883664369679773, 'fraction_numerical': 0.0064856100526955816, 'mean_word_length': 3.2332761578044598, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '4984024', 'n_tokens_mistral': 738, 'n_tokens_neox': 695, 'n_words': 163}