<commit_before>"""
Tests suite for the models of the blog app.
"""

from django.test import TestCase
from django.core.urlresolvers import reverse
from django.contrib.auth import get_user_model


from ..models import (Article,
                      ArticleRevision,
                      ArticleNote,
                      ArticleTag,
                      ArticleCategory)
from ..constants import NOTE_TYPE_DEFAULT


class ArticleRevisionTestCase(TestCase):
    """
    Tests suite for the ``ArticleRevision`` data model class.
    """

    def _get_revision(self):
        """
        Create a new article revision with only required attributes set.
        :return: The newly created article revision instance.
        """
        author = get_user_model().objects.create_user(username='johndoe',
                                                      password='<PASSWORD>',
                                                      email='<EMAIL>')
        article = Article.objects.create(title='Test 1',
                                         slug='test-1',
                                         author=author,
                                         content='Hello World!')
        revision = ArticleRevision.objects.create(related_article=article,
                                                  title='Revision test',
                                                  content='Hello World!')
        return revision

    def test_default_values(self):
        """
        Test default values of the newly created revision.
        """
        revision = self._get_revision()
        self.assertEqual('', revision.subtitle)
        self.assertEqual('', revision.description)
        self.assertFalse(revision.revision_minor_change)
        self.assertEqual('', revision.revision_description)
        self.assertIsNone(revision.revision_author)
        self.assertIsNotNone(revision.revision_date)

    def test_str_method(self):
        """
        Test __str__ result for other tests.
        """
        revision = self._get_revision()
        self.assertEqual('Revision #%d' % revision.id, str(revision))


class ArticleNoteTestCase(TestCase):
    """
    Tests suite for the ``ArticleNote`` data model class.
    """

    def _get_note(self):
        """
        Create a new article note with only required attributes set.
        :return: The newly created article note instance.
        """
        note = ArticleNote.objects.create(title_internal='Test 1',
                                          description='Hello World!')
        return note

    def test_default_values(self):
        """
        Test default values of the newly created note.
        """
        note = self._get_note()
        self.assertEqual('', note.title)
        self.assertEqual(NOTE_TYPE_DEFAULT, note.type)

    def test_str_method(self):
        """
        Test __str__ result for other tests.
        """
        note = self._get_note()
        self.assertEqual(note.title_internal, str(note))


class ArticleTagTestCase(TestCase):
    """
    Tests suite for the ``ArticleTag`` data model class.
    """

    def _get_tag(self):
        """
        Create a new article tag with only required attributes set.
        :return: The newly created article tag instance.
        """
        tag = ArticleTag.objects.create(name='Test 1',
                                        slug='test-1')
        return tag

    def test_str_method(self):
        """
        Test __str__ result for other tests.
        """
        tag = self._get_tag()
        self.assertEqual(tag.name, str(tag))

    def test_get_absolute_url_method(self):
        """
        Test ``get_absolute_url`` method with a valid article tag.
        """
        tag = self._get_tag()
        excepted_url = reverse('blog:tag_detail', kwargs={'slug': tag.slug})
        self.assertEqual(excepted_url, tag.get_absolute_url())

    def test_get_latest_articles_rss_feed_url_method(self):
        """
        Test ``get_latest_articles_rss_feed_url`` method with a valid article tag.
        """
        tag = self._get_tag()
        excepted_url = reverse('blog:latest_tag_articles_rss', kwargs={'slug': tag.slug})
        self.assertEqual(excepted_url, tag.get_latest_articles_rss_feed_url())

    def test_get_latest_articles_atom_feed_url_method(self):
        """
        Test ``get_latest_articles_atom_feed_url`` method with a valid article tag.
        """
        tag = self._get_tag()
        excepted_url = reverse('blog:latest_tag_articles_atom', kwargs={'slug': tag.slug})
        self.assertEqual(excepted_url, tag.get_latest_articles_atom_feed_url())

    def test_slug_unique(self):
        """
        Test if the ``save()`` method handle non-unique slug.
        """
        tag1 = ArticleTag.objects.create(name='Test 1',
                                         slug='test-1')
        tag2 = ArticleTag.objects.create(name='Test 2',
                                         slug='test-1')
        tag3 = ArticleTag.objects.create(name='Test 3',
                                         slug='test-1')
        self.assertNotEqual(tag1.slug, tag2.slug)
        self.assertNotEqual(tag2.slug, tag3.slug)
        self.assertNotEqual(tag1.slug, tag3.slug)


class ArticleCategoryTestCase(TestCase):
    """
    Tests suite for the ``ArticleCategory`` data model class.
    """

    def _get_category(self):
        """
        Create a new article category with only required attributes set.
        :return: The newly created article category instance.
        """
        category = ArticleCategory.objects.create(name='Test 1',
                                                  slug='test-1')
        return category

    def test_default_values(self):
        """
        Test default values of the newly created category.
        """
        category = self._get_category()
        self.assertIsNone(category.parent)
        self.assertIsNone(category.logo.name)
        self.assertEqual('', category.description)

    def test_str_method(self):
        """
        Test __str__ result for other tests.
        """<commit_msg>Rework blog models tests suites<commit_after>"""
Tests suite for the models of the blog app.
"""

from django.test import TestCase
from django.core.urlresolvers import reverse
from django.contrib.auth import get_user_model
from django.conf import settings
from django.test.utils import override_settings


from ..models import (Article,
                      ArticleRevision,
                      ArticleNote,
                      ArticleTag,
                      ArticleCategory)
from ..constants import NOTE_TYPE_DEFAULT


@override_settings(MEDIA_ROOT=settings.DEBUG_MEDIA_ROOT)
class ArticleRevisionTestCase(TestCase):
    """
    Tests suite for the ``ArticleRevision`` data model class.
    """

    def _get_revision(self):
        """
        Create a new article revision with only required attributes set.
        :return: The newly created article revision instance.
        """
        author = get_user_model().objects.create_user(username='johndoe',
                                                      password='<PASSWORD>',
                                                      email='<EMAIL>')
        article = Article.objects.create(title='Test 1',
                                         slug='test-1',
                                         author=author,
                                         content='Hello World!')
        revision = ArticleRevision.objects.create(related_article=article,
                                                  title='Revision test',
                                                  content='Hello World!')
        return revision

    def test_default_values(self):
        """
        Test default values of the newly created revision.
        """
        revision = self._get_revision()
        self.assertEqual('', revision.subtitle)
        self.assertEqual('', revision.description)
        self.assertFalse(revision.revision_minor_change)
        self.assertEqual('', revision.revision_description)
        self.assertIsNone(revision.revision_author)
        self.assertIsNotNone(revision.revision_date)

    def test_str_method(self):
        """
        Test __str__ result for other tests.
        """
        revision = self._get_revision()
        self.assertEqual('Revision #%d' % revision.id, str(revision))


@override_settings(MEDIA_ROOT=settings.DEBUG_MEDIA_ROOT)
class ArticleNoteTestCase(TestCase):
    """
    Tests suite for the ``ArticleNote`` data model class.
    """

    def _get_note(self):
        """
        Create a new article note with only required attributes set.
        :return: The newly created article note instance.
        """
        note = ArticleNote.objects.create(title_internal='Test 1',
                                          description='Hello World!')
        return note

    def test_default_values(self):
        """
        Test default values of the newly created note.
        """
        note = self._get_note()
        self.assertEqual('', note.title)
        self.assertEqual(NOTE_TYPE_DEFAULT, note.type)

    def test_str_method(self):
        """
        Test __str__ result for other tests.
        """
        note = self._get_note()
        self.assertEqual(note.title_internal, str(note))


@override_settings(MEDIA_ROOT=settings.DEBUG_MEDIA_ROOT)
class ArticleTagTestCase(TestCase):
    """
    Tests suite for the ``ArticleTag`` data model class.
    """

    def _get_tag(self):
        """
        Create a new article tag with only required attributes set.
        :return: The newly created article tag instance.
        """
        tag = ArticleTag.objects.create(name='Test 1',
                                        slug='test-1')
        return tag

    def test_str_method(self):
        """
        Test __str__ result for other tests.
        """
        tag = self._get_tag()
        self.assertEqual(tag.name, str(tag))

    def test_get_absolute_url_method(self):
        """
        Test ``get_absolute_url`` method with a valid article tag.
        """
        tag = self._get_tag()
        excepted_url = reverse('blog:tag_detail', kwargs={'slug': tag.slug})
        self.assertEqual(excepted_url, tag.get_absolute_url())

    def test_get_latest_articles_rss_feed_url_method(self):
        """
        Test ``get_latest_articles_rss_feed_url`` method with a valid article tag.
        """
        tag = self._get_tag()
        excepted_url = reverse('blog:latest_tag_articles_rss', kwargs={'slug': tag.slug})
        self.assertEqual(excepted_url, tag.get_latest_articles_rss_feed_url())

    def test_get_latest_articles_atom_feed_url_method(self):
        """
        Test ``get_latest_articles_atom_feed_url`` method with a valid article tag.
        """
        tag = self._get_tag()
        excepted_url = reverse('blog:latest_tag_articles_atom', kwargs={'slug': tag.slug})
        self.assertEqual(excepted_url, tag.get_latest_articles_atom_feed_url())

    def test_slug_unique(self):
        """
        Test if the ``save()`` method handle non-unique slug.
        """
        tag1 = ArticleTag.objects.create(name='Test 1',
                                         slug='test-1')
        tag2 = ArticleTag.objects.create(name='Test 2',
                                         slug='test-1')
        tag3 = ArticleTag.objects.create(name='Test 3',
                                         slug='test-1')
        self.assertNotEqual(tag1.slug, tag2.slug)
        self.assertNotEqual(tag2.slug, tag3.slug)
        self.assertNotEqual(tag1.slug, tag3.slug)


@override_settings(MEDIA_ROOT=settings.DEBUG_MEDIA_ROOT)
class ArticleCategoryTestCase(TestCase):
    """
    Tests suite for the ``ArticleCategory`` data model class.
    """

    def _get_category(self):
        """
        Create a new article category with only required attributes set.
        :return: The newly created article category instance.
        """
        category = ArticleCategory.objects.create(name='Test 1',
                                                  slug='test-1')
        return category

    def test_default_values(self):
        """
        Test default values of the newly created category.
        """
        category = self._get_category()
        self.assertIsNone(category.parent)
        self.assertIsNone(category.logo.name)
        self.assertEqual('', category.description)

    def test_str_method(self):
        """
        Test __str__ result for other tests.
        """
{'fraction_non_alphanumeric': 0.09760178471834914, 'fraction_numerical': 0.0035056967572304996, 'mean_word_length': 1.9673758865248228, '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': 50, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3814024', 'n_tokens_mistral': 3220, 'n_tokens_neox': 3137, 'n_words': 754}