<commit_before>from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.core.urlresolvers import reverse
from django.test import Client, TestCase
from mixer.backend.django import mixer
from unittest import skip

from accounts.utils import random_dpaw_email
from .models import Application, Task

User = get_user_model()


class ApplicationTest(TestCase):

    def setUp(self):
        self.client = Client()
        # Set up some non-superuser internal users.
        self.user1 = mixer.blend(User, email=random_dpaw_email, is_superuser=False, is_staff=True)
        self.user1.set_password('<PASSWORD>')
        self.user1.save()
        processor = Group.objects.get_or_create(name='Processor')[0]
        self.user1.groups.add(processor)
        self.superuser = mixer.blend(User, email=random_dpaw_email, is_superuser=True, is_staff=True)
        self.superuser.set_password('<PASSWORD>')
        self.superuser.save()
        self.customer = mixer.blend(User, is_superuser=False, is_staff=False)
        self.customer.set_password('<PASSWORD>')
        self.customer.save()
        # Log in user1, by default.
        self.client.login(email=self.user1.email, password='<PASSWORD>')
        # Generate test fixtures..
        self.app1 = mixer.blend(Application)
        self.task1 = mixer.blend(Task)

    def test_get_absolute_url(self):
        """Test that Application.get_absolute_url works
        """
        self.assertTrue(self.app1.get_absolute_url())

    def test_list_application_view_get(self):
        """Test the application list view renders
        """
        url = reverse('application_list')
        resp = self.client.get(url)
        self.assertEquals(resp.status_code, 200)

    def test_create_application_view_get_redirect(self):
        """Test the application create view redirects unauthorised users
        """
        self.client.logout()
        self.client.login(email=self.customer.email, password='<PASSWORD>')
        url = reverse('application_create')
        resp = self.client.get(url)
        self.assertEquals(resp.status_code, 302)

    def test_create_application_view_get(self):
        """Test the application create view renders for an authorised user
        """
        url = reverse('application_create')
        resp = self.client.get(url)
        self.assertEquals(resp.status_code, 200)
        # Test for a superuser.
        self.client.logout()
        self.client.login(email=self.superuser.email, password='<PASSWORD>')
        resp = self.client.get(url)
        self.assertEquals(resp.status_code, 200)

    def test_create_application_view_post(self):
        """Test the application create view accepts a valid POST
        """
        count = Application.objects.count()<commit_msg>Update unit tests.<commit_after>from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.core.urlresolvers import reverse
from django.test import Client, TestCase
from mixer.backend.django import mixer
from unittest import skip

from accounts.utils import random_dpaw_email
from .models import Application, Task

User = get_user_model()


class ApplicationTest(TestCase):

    def setUp(self):
        self.client = Client()
        # Set up some non-superuser internal users.
        self.user1 = mixer.blend(User, email=random_dpaw_email, is_superuser=False, is_staff=True)
        self.user1.set_password('<PASSWORD>')
        self.user1.save()
        processor = Group.objects.get_or_create(name='Processor')[0]
        self.user1.groups.add(processor)
        self.superuser = mixer.blend(User, email=random_dpaw_email, is_superuser=True, is_staff=True)
        self.superuser.set_password('<PASSWORD>')
        self.superuser.save()
        self.customer = mixer.blend(User, is_superuser=False, is_staff=False)
        self.customer.set_password('<PASSWORD>')
        self.customer.save()
        # Log in user1, by default.
        self.client.login(email=self.user1.email, password='<PASSWORD>')
        # Generate test fixtures..
        self.app1 = mixer.blend(Application)
        self.task1 = mixer.blend(Task)

    def test_get_absolute_url(self):
        """Test that Application.get_absolute_url works
        """
        self.assertTrue(self.app1.get_absolute_url())

    def test_list_application_view_get(self):
        """Test the application list view renders
        """
        url = reverse('application_list')
        resp = self.client.get(url)
        self.assertEquals(resp.status_code, 200)

    def test_create_application_view_get(self):
        """Test the application create view renders
        """
        url = reverse('application_create')
        resp = self.client.get(url)
        self.assertEquals(resp.status_code, 200)

    def test_create_application_view_post(self):
        """Test the application create view accepts a valid POST
        """
        count = Application.objects.count()
{'fraction_non_alphanumeric': 0.10225474683544304, 'fraction_numerical': 0.007515822784810127, 'mean_word_length': 3.1966804979253114, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3670454', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1439, 'n_words': 309}