<commit_before>from django.test import TestCase
from django.db.utils import IntegrityError
from django.contrib.auth import get_user_model
from django.utils import timezone
User = get_user_model()

from frontend.models import EditorMaterial


class EditorMaterialTest(TestCase):

    @classmethod
    def setUpTestData(cls):

        cls.user = User.objects.create_user(username='haxor', password='<PASSWORD>')

        cls.em1 = EditorMaterial.objects.create(title='Заголовок 1',
            slug='slug1', section='news', status='draft', announce='Анонс 1',
            contents='Текст 1', user=cls.user
        )

        cls.em2 = EditorMaterial.objects.create(title='Заголовок 2',
            slug='slug2', section='news', status='draft', announce='Анонс 2',
            contents='Текст 2', user=cls.user
        )

        cls.em3 = EditorMaterial.objects.create(title='Заголовок 3',
            slug='slug3', section='landing', status='draft', announce='Анонс 3',
            contents='Текст 3', user=cls.user
        )

    def test_str(self):

        self.assertEqual(str(self.em1), 'Заголовок 1')

    def test_slug_and_section_is_unique_together(self):

        self.em2.slug = 'slug1'
        self.em2.section = 'news'

        with self.assertRaises(IntegrityError):
            self.em2.save()

    def test_link_if_section_is_not_landing(self):

        self.assertEqual(self.em1.link, '/news/slug1/')

    def test_link_if_section_is_landing(self):

        self.assertEqual(self.em3.link, '/slug3/')

    def test_created_at_field_is_auto_now_add(self):

        past = timezone.now()
        em = EditorMaterial.objects.create(title='Заголовок',
            slug='slug', section='landing', status='draft', announce='Анонс',
            contents='Текст', user=self.user
        )

        self.assertGreater(em.created_at, past)


class TipTest(TestCase):

    def test_str(self):
        pass

    def test_active_default_value(self):
        pass<commit_msg>Тесты для модели Tip<commit_after>from django.test import TestCase
from django.db.utils import IntegrityError
from django.contrib.auth import get_user_model
from django.utils import timezone
User = get_user_model()

from frontend.models import EditorMaterial, Tip


class EditorMaterialTest(TestCase):

    @classmethod
    def setUpTestData(cls):

        cls.user = User.objects.create_user(username='haxor', password='<PASSWORD>')

        cls.em1 = EditorMaterial.objects.create(title='Заголовок 1',
            slug='slug1', section='news', status='draft', announce='Анонс 1',
            contents='Текст 1', user=cls.user
        )

        cls.em2 = EditorMaterial.objects.create(title='Заголовок 2',
            slug='slug2', section='news', status='draft', announce='Анонс 2',
            contents='Текст 2', user=cls.user
        )

        cls.em3 = EditorMaterial.objects.create(title='Заголовок 3',
            slug='slug3', section='landing', status='draft', announce='Анонс 3',
            contents='Текст 3', user=cls.user
        )

    def test_str(self):

        self.assertEqual(str(self.em1), 'Заголовок 1')

    def test_slug_and_section_is_unique_together(self):

        self.em2.slug = 'slug1'
        self.em2.section = 'news'

        with self.assertRaises(IntegrityError):
            self.em2.save()

    def test_link_if_section_is_not_landing(self):

        self.assertEqual(self.em1.link, '/news/slug1/')

    def test_link_if_section_is_landing(self):

        self.assertEqual(self.em3.link, '/slug3/')

    def test_created_at_field_is_auto_now_add(self):

        past = timezone.now()
        em = EditorMaterial.objects.create(title='Заголовок',
            slug='slug', section='landing', status='draft', announce='Анонс',
            contents='Текст', user=self.user
        )

        self.assertGreater(em.created_at, past)


class TipTest(TestCase):

    @classmethod
    def setUpTestData(cls):

        cls.tip1 = Tip.objects.create(text='advice 1')
        cls.tip2 = Tip.objects.create(text='advice 2', active=False)

    def test_str(self):

        self.assertEqual(str(self.tip1), 'advice 1')
{'fraction_non_alphanumeric': 0.12545498665372481, 'fraction_numerical': 0.013588934724581413, 'mean_word_length': 3.0731225296442686, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2335748', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1328, 'n_words': 226}