<commit_before># -*- coding: utf8 -*-

from django.test import TestCase
from django.test.client import Client
from django.test.utils import override_settings
from django.contrib.auth.models import User
from django.conf import settings
from django.core.urlresolvers import reverse

from models import Structure, UserProfile


@override_settings(LOGIN_URL='/login/')
class LoginTestCase(TestCase):

    def test_login(self):
        response = self.client.get('/')
        self.assertRedirects(response, '/login/?next=/')


class StructureTest(TestCase):
    def test_basic(self):
        s = Structure(name="Mercantour")
        self.assertEqual(unicode(s), "Mercantour")


class UserProfileTest(TestCase):
    def setUp(self):
        self.user = User.objects.create_user('Joe', email='<EMAIL>', password='<PASSWORD>')
        self.user.set_password('<PASSWORD>')
        self.user.save()

    def test_profile(self):
        self.assertTrue(isinstance(self.user.profile, UserProfile))
        self.assertEqual(self.user.profile.structure.name, settings.DEFAULT_STRUCTURE_NAME)
        self.assertEqual(self.user.profile.language, settings.LANGUAGE_CODE)
        
    def test_language(self):
        c = Client()
        success = c.login(username="Joe", password="<PASSWORD>")
        self.assertTrue(success)
        response = c.get(reverse('home'))
        self.assertEqual(200, response.status_code)
        self.assertTrue("déconnecter" in response.content)
        
        # Change user lang
        self.user.profile.language = "en"
        self.assertEqual(settings.LANGUAGE_CODE, self.user.profile.language)
        self.user.profile.save()
        # No effect if no logout
        response = c.get(reverse('home'))
        self.assertTrue("déconnecter" in response.content)
        
        c.logout()
        response = c.get(reverse('home'))
        self.assertEqual(response.status_code, 302)
        
        c.login(username="Joe", password="<PASSWORD>")
        response = c.get(reverse('home'))
        self.assertEqual(c.session['django_language'], self.user.profile.language)
        self.assertTrue("Logout" in response.content)<commit_msg>Fix one test, not both (refs #84)<commit_after># -*- coding: utf8 -*-

from django.test import TestCase
from django.test.client import Client
from django.test.utils import override_settings
from django.contrib.auth.models import User
from django.conf import settings
from django.core.urlresolvers import reverse

from models import Structure, UserProfile


@override_settings(LOGIN_URL='/login/')
class LoginTestCase(TestCase):

    def test_login(self):
        response = self.client.get('/')
        _next = settings.FORCE_SCRIPT_NAME + '/'
        self.assertRedirects(response, '/login/?next=' + _next)


class StructureTest(TestCase):
    def test_basic(self):
        s = Structure(name="Mercantour")
        self.assertEqual(unicode(s), "Mercantour")


class UserProfileTest(TestCase):
    def setUp(self):
        self.user = User.objects.create_user('Joe', email='<EMAIL>', password='<PASSWORD>')
        self.user.set_password('<PASSWORD>')
        self.user.save()

    def test_profile(self):
        self.assertTrue(isinstance(self.user.profile, UserProfile))
        self.assertEqual(self.user.profile.structure.name, settings.DEFAULT_STRUCTURE_NAME)
        self.assertEqual(self.user.profile.language, settings.LANGUAGE_CODE)
        
    def test_language(self):
        c = Client()
        success = c.login(username="Joe", password="<PASSWORD>")
        self.assertTrue(success)
        response = c.get(reverse('home'))
        self.assertEqual(200, response.status_code)
        self.assertTrue("déconnecter" in response.content)
        
        # Change user lang
        self.user.profile.language = "en"
        self.assertEqual(settings.LANGUAGE_CODE, self.user.profile.language)
        self.user.profile.save()
        # No effect if no logout
        response = c.get(reverse('home'))
        self.assertTrue("déconnecter" in response.content)
        
        c.logout()
        response = c.get(reverse('home'))
        self.assertEqual(response.status_code, 302)
        
        c.login(username="Joe", password="<PASSWORD>")
        response = c.get(reverse('home'))
        self.assertEqual(c.session['django_language'], self.user.profile.language)
        self.assertFalse("déconnecter" in response.content)
{'fraction_non_alphanumeric': 0.12568058076225044, 'fraction_numerical': 0.003629764065335753, 'mean_word_length': 3.2030505243088654, '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': '729736', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1260, 'n_words': 236}