<commit_before>from django.contrib.auth import get_user_model
from django.db import DataError
from django.db import IntegrityError
from django.test import TestCase

from foodsaving.users.factories import UserFactory
from foodsaving.groups.factories import GroupFactory
from foodsaving.users.models import User


class TestUserModel(TestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.user = UserFactory()
        cls.group = GroupFactory(members=[cls.user, ])
        cls.exampleuser = {
            'display_name': 'bla',
            'email': '<EMAIL>',
            'password': '<PASSWORD>',
            'current_group': cls.group,
        }

    def test_create_fails_if_email_is_not_unique(self):
        get_user_model().objects.create_user(**self.exampleuser)
        with self.assertRaises(IntegrityError):
            get_user_model().objects.create_user(**self.exampleuser)

    def test_create_fails_if_name_too_long(self):
        with self.assertRaises(DataError):
            too_long = self.exampleuser
            too_long['display_name'] = 'a' * 81
            get_user_model().objects.create_user(**too_long)

    def test_user_representation(self):
        r = repr(self.user)
        self.assertTrue(self.user.display_name in r)

    def test_create_fails_if_default_language_is_not_set(self):
        default_language = get_user_model().objects.create_user(**self.exampleuser).language
        self.assertTrue(default_language, 'en-us')

<commit_msg>add unit test for language field in user model<commit_after>from django.contrib.auth import get_user_model
from django.db import DataError
from django.db import IntegrityError
from django.test import TestCase

from foodsaving.users.factories import UserFactory
from foodsaving.groups.factories import GroupFactory
from foodsaving.users.models import User


class TestUserModel(TestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.user = UserFactory()
        cls.group = GroupFactory(members=[cls.user, ])
        cls.exampleuser = {
            'display_name': 'bla',
            'email': '<EMAIL>',
            'password': '<PASSWORD>',
            'current_group': cls.group,
        }

    def test_create_fails_if_email_is_not_unique(self):
        get_user_model().objects.create_user(**self.exampleuser)
        with self.assertRaises(IntegrityError):
            get_user_model().objects.create_user(**self.exampleuser)

    def test_create_fails_if_name_too_long(self):
        with self.assertRaises(DataError):
            too_long = self.exampleuser
            too_long['display_name'] = 'a' * 81
            get_user_model().objects.create_user(**too_long)

    def test_user_representation(self):
        r = repr(self.user)
        self.assertTrue(self.user.display_name in r)

    def test_create_fails_if_default_language_is_not_set(self):
        default_language = get_user_model().objects.create_user(**self.exampleuser).language
        self.assertEqual(default_language, 'en-us')


{'fraction_non_alphanumeric': 0.10013089005235602, 'fraction_numerical': 0.0013089005235602095, 'mean_word_length': 3.323903818953324, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5698194', 'n_tokens_mistral': 913, 'n_tokens_neox': 894, 'n_words': 160}