Source

pentasubmitter / src / submitter / tests / models.py

"""
unittests for submitter application
"""

import sys
import unittest
import datetime
from markdown import markdown
from django.test import Client, TestCase
from django.contrib.auth.models import User
from django.db import IntegrityError
from submitter import admin, models, views
from pentasubmitter import settings, template
from show.models import PentaShow, ShowType

class SubmitterCheckSettings(unittest.TestCase):
    "general settings in settings.py"

    def test_installed_application(self):
        "Am I installed?"
        self.assertTrue(
            'submitter' in settings.INSTALLED_APPS,
            "Submitter app not registered in settings.py"
        )


class EntryCategoryTest(TestCase):
    """EntryCategory() Tests"""

    def setUp(self):
        self.entry_category1 = models.EntryCategory(
            title=u"Fnord",
            description=u"The ususal Fnords",
            tags_string=u"fnord general",
        )
        self.entry_category1.save()

        self.entry_category2 = models.EntryCategory(
            title="Fnord",
            description="The ususal Fnords",
            tags_string="fnord general"
        )
        self.entry_category2.save()

        self.entry_category3 = models.EntryCategory(
            title="Fnord",
            description="The ususal Fnords",
            tags_string="fnord general"
        )
        self.entry_category3.save()

    def test_entry_categories(self):
        "Test EntryCategory()"
        self.assertEquals(self.entry_category1.title, 'Fnord')
        self.assertNotEquals(self.entry_category1.title, 'Nnord')
        self.assertEquals(self.entry_category1.description,
                          'The ususal Fnords')
        self.assertEquals([t.name for t in self.entry_category1.tags],
                          [u'fnord', u'general'])
        self.assertEquals(self.entry_category1.slug, 'fnord')
        self.assertNotEquals(self.entry_category1.get_absolute_url(),
                          '/submit/news-category/fnord001/')
        self.assertEquals(self.entry_category1.get_absolute_url(),
                          '/submit/news-category/fnord/')
        self.entry_category2.save()
        self.assertEquals(self.entry_category2.slug, 'fnord001')
        # need to save again to see that slug doesn't get increased
        self.entry_category2.save()
        self.assertEquals(self.entry_category2.slug, 'fnord001')
        self.assertEquals(self.entry_category2.get_absolute_url(),
                          '/submit/news-category/fnord001/')
        self.entry_category3.save()
        self.assertEquals(self.entry_category3.slug, 'fnord002')


class NewsEntryTest(TestCase):
    """NewsEntry() Tests"""

    def setUp(self):
        "Fixtures"

        user = User()
        user.save()
        self.user = models.Submitter()
        self.user.user = user
        self.user.save()
        self.show_type1=ShowType(
            show_type=1,
        )
        self.show_type1.save()

        self.penta_show1 = PentaShow(
            title=u"Hacking is not a crime",
            excerpt=u"We talk about the motto: Hacking is not a crime.",
            description=(u'Fridolin is the next King of the Land of the free\n'
                  u'=================================================\n\n'
                  u'As we have learned from [c3d2](http://www.c3d2.de/ "c3d2") '
                  u'news Fridolin is the next King of Hacking.'),
            show_type=1,
        )
        self.penta_show1.save()

        self.entry_category1 = models.EntryCategory(
            title=u"Fnord",
            description=u"The ususal Fnords",
            tags_string=u"fnord general",
        )
        self.entry_category1.save()

        self.entry_category2 = models.EntryCategory(
            title="Fnord",
            description="The ususal Fnords",
            tags_string = "fnord general"
        )
        self.entry_category2.save()

        self.date_test=datetime.datetime.today()
        self.news_entry1 = models.NewsEntry(
            title=u"Fridolin got King",
            excerpt=u"Fridolin was made the next *King*",
            body=(u'Fridolin is the next King of the Land of the free\n'
                  u'=================================================\n\n'
                  u'As we have learned from [c3d2](http://www.c3d2.de/ "c3d2") '
                  u'news Fridolin is the next King of Hacking.'),
            author=self.user,
            enable_comments=False,
            show=self.penta_show1,
            featured=True,
            status=1,
            submit_date=self.date_test,
            external_url="http://www.c3d2.de",
        )
        self.news_entry1.save()
        self.news_entry1.tags = "Foo, Bar"
        self.news_entry1.categories.add(self.entry_category1,
                                        self.entry_category2)
        self.date_now = datetime.datetime.now()

    def test_news_entry(self):
        "Test NewsEntry()"

        self.assertEquals(self.news_entry1.title, u"Fridolin got King")
        self.assertEquals(self.news_entry1.excerpt,
                          u"Fridolin was made the next *King*")
        self.assertEquals(self.news_entry1.excerpt_html,
                          u"<p>Fridolin was made the next <em>King</em></p>")
        self.assertEquals(
            self.news_entry1.body_html,
            (u'<h1>Fridolin is the next King of the Land of the free</h1>\n'
             u'<p>As we have learned from <a href="http://www.c3d2.de/" '
             u'title="c3d2">c3d2</a> news Fridolin is the next King of '
             u'Hacking.</p>')
        )
        self.assertEquals(self.news_entry1.external_url, u"http://www.c3d2.de")
        self.assert_(self.entry_category1 in self.news_entry1.categories.all())
        self.assert_(self.entry_category2 in self.news_entry1.categories.all())
        self.assert_(u'Foo'.lower() in [ t.name for t in self.news_entry1.tags])
        self.assert_(u'Bar'.lower() in self.news_entry1.get_tag_list())
        self.assertEquals(self.news_entry1.slug, u"fridolingotking")
        self.assertEquals(
            self.news_entry1.get_absolute_url(),
            '/submit/%(year)s/%(month)s/%(day)s/fridolingotking/' % (
                {'year': self.date_test.strftime("%Y"),
                 'month': self.date_test.strftime("%m"),
                 'day': self.date_test.strftime("%d"),
                }
            )
        )

    def test_set_title_news_entry(self):
        "Test if NewsEntry.title is set automatically"

        self.news_entry2 = models.NewsEntry(
            excerpt=u"Fridolin was made the next *King*",
            body=(u'Fridolin is the next King of the Land of the free\n'
                  u'=================================================\n\n'
                  u'As we have learned from [c3d2](http://www.c3d2.de/ "c3d2") '
                  u'news Fridolin is the next King of Hacking.'),
            author=self.user,
            enable_comments=False,
            show=self.penta_show1,
            featured=False,
            status=1,
            submit_date=self.date_test,
            external_url="http://www.alien8.de",
            tags_string=u"a8 alien8",
        )
        self.news_entry2.save()
        self.news_entry2.categories.add(self.entry_category1,
                                        self.entry_category2)
        self.news_entry2.save()
        self.news_entry2 = models.NewsEntry(
            excerpt=u"Fridolin was made the next *King*",
            body=(u'Fridolin is the next King of the Land of the free\n'
                  u'=================================================\n\n'
                  u'As we have learned from [c3d2](http://www.c3d2.de/ "c3d2") '
                  u'news Fridolin is the next King of Hacking.'),
            author=self.user,
            enable_comments=False,
            show=self.penta_show1,
            featured=False,
            status=1,
            submit_date=self.date_test,
            external_url="http://www.alien8.de",
            tags_string=u"a8 alien8",
        )
        self.news_entry2.save()
        self.news_entry2.categories.add(self.entry_category1,
                                        self.entry_category2)
        self.assertEquals(self.news_entry2.title, u"Alien8: Home")


    def test_presented_date(self):
        """Test if the presented attr was set correctly"""

        self.news_entry1.presented_timestamp = self.date_now
        self.news_entry1.save()
        self.assertEqual(self.date_now, self.news_entry1.presented_timestamp)


# vim: ts=4 et sw=4 fileencoding=utf-8 :
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.