Example #1
0
 def test_title(self):
     """A title is set on a file from filename is none is supplied"""
     # open file
     test_pdf = open('%s/ccnews/test.pdf' % settings.STATIC_ROOT)
     # make page and attachment
     a1 = Article()
     a1.title = '1'
     a1.slug = '1'
     a1.content = '# hello world of tests'
     a1.status = Article.VISIBLE
     a1.created = datetime(year=1970, month=1, day=2)
     a1.save()
     at1 = ArticleAttachment()
     at1.article = a1
     at1.src = File(test_pdf, 'ccnews/test.pdf')
     at1.save()
     # the title is 'test.pdf'
     self.assertEqual(at1.title, 'test.pdf')
     test_pdf.close()
     os.unlink(at1.src.path)
     # make another one, but this time with a title
     test_pdf = open('%s/ccnews/test.pdf' % settings.STATIC_ROOT)
     at2 = ArticleAttachment()
     at2.article = a1
     at2.src = File(test_pdf, 'ccnews/test.pdf')
     at2.title = 'Arther'
     at2.save()
     # title is now arther
     self.assertEqual(at2.title, 'Arther')
     # delete the files
     test_pdf.close()
     os.unlink(at2.src.path)
Example #2
0
 def test_excerpt(self):
     "The excerpt is correctly set and honours the config setting"""
     # set a very short length
     settings.CCNEWS_EXCERPT_LENGTH = 1
     reload(c_settings)
     a1 = Article()
     a1.title = '1'
     a1.slug = '1'
     a1.content = '# hello world of tests'
     a1.status = Article.VISIBLE
     a1.created = datetime(year=1970, month=1, day=2)
     a1.save()
     # we have one word in the excerpt
     self.assertEqual('hello ...', a1.excerpt)
     # remove our setting
     del(settings.CCNEWS_EXCERPT_LENGTH)
     reload(c_settings)
     # now we have the default length
     a1.save()
     self.assertEqual('hello world of tests', a1.excerpt)
Example #3
0
 def test_content_rendered(self):
     """the content is rendered as markdown when an article
     is saved"""
     a1 = Article()
     a1.title = '1'
     a1.slug = '1'
     a1.content = '# hello'
     a1.status = Article.VISIBLE
     a1.created = datetime(year=1970, month=1, day=2)
     a1.save()
     # we have html
     self.assertHTMLEqual(
             '<h1 id="hello">hello</h1>',
             a1.content_rendered)
Example #4
0
 def test_view_200(self):
     """The index page responds with a 200 ok"""
     # make article 1
     a1 = Article()
     a1.title = '1'
     a1.slug = '1'
     a1.content = '1111111'
     a1.status = Article.VISIBLE
     a1.created = datetime(year=2012, month=5, day=19)
     a1.save()
     request = self.rf.get(reverse(
                     'ccnews:view',
                     args=[2012,05,'1']))
     response = view(request, 2012, 5, 1)
     self.assertEqual(200, response.status_code)
Example #5
0
 def test_set_created(self):
     """a created date is set if none is supplied"""
     # make article 1
     a1 = Article()
     a1.title = '1'
     a1.slug = '1'
     a1.content = '1111111'
     a1.status = Article.VISIBLE
     a1.created = datetime(year=1970, month=1, day=2)
     a1.save()
     # make article 2
     a2 = Article()
     a2.title = '2'
     a2.slug = '2'
     a2.content = '2222222'
     a2.status = Article.HIDDEN
     a2.save()
     # both have dates
     self.assertTrue(a1.created)
     self.assertTrue(a2.created)
     # but a1 is 1970
     self.assertEqual(1970, a1.created.year)
     self.assertEqual(1, a1.created.month)
     self.assertEqual(2, a1.created.day)
Example #6
0
    def test_index(self):
        """Index returns only visible items and the total 
        amount returned is dependant on the value of
        c_settings.CCNEWS_INDEX_ITEMS"""
        # make article 1
        a1 = Article()
        a1.title = '1'
        a1.slug = '1'
        a1.content = '1111111'
        a1.status = Article.VISIBLE
        a1.created = datetime(year=2012, month=5, day=19)
        a1.save()
        # make article 2
        a2 = Article()
        a2.title = '2'
        a2.slug = '2'
        a2.content = '2222222'
        a2.status = Article.HIDDEN
        a2.created = datetime(year=2012, month=4, day=20)
        a2.save()
        # make article 3
        a3 = Article()
        a3.title = '3'
        a3.slug = '3'
        a3.content = '3333333'
        a3.status = Article.VISIBLE
        a3.created = datetime(year=2012, month=5, day=20)
        a3.save()
        # the default is ten, but we only have three, one is hidden
        self.assertEqual(2, Article.objects.index().count())
        # unhide the hidden and we have three
        a2.status = Article.VISIBLE
        a2.save()
        # now we have three
        self.assertEqual(3, Article.objects.index().count())
        # adjust the setting to 1
        settings.CCNEWS_INDEX_ITEMS = 1
        reload(c_settings)
        # now we have one
        self.assertEqual(1, Article.objects.index().count())
        # and it the latest one
        self.assertEqual(a3.pk, Article.objects.index()[0].pk)
        # remove the custom setting and reload

        del(settings.CCNEWS_INDEX_ITEMS)
        reload(c_settings)
Example #7
0
 def test_nav_local(self):
     """test thati nav_local method behaves as expected"""
     # make article 1
     a1 = Article()
     a1.title = '1'
     a1.slug = '1'
     a1.content = '1111111'
     a1.status = Article.VISIBLE
     a1.created = datetime(year=2012, month=5, day=20)
     a1.save()
     # make article 2
     a2 = Article()
     a2.title = '2'
     a2.slug = '2'
     a2.content = '2222222'
     a2.status = Article.HIDDEN
     a2.created = datetime(year=1970, month=1, day=2)
     a2.save()
     # make article 3
     a3 = Article()
     a3.title = '3'
     a3.slug = '3'
     a3.content = '3333333'
     a3.status = Article.VISIBLE
     a3.created = datetime(year=2012, month=5, day=20)
     a3.save()
     # test the return 
     n = Article.objects.nav_local()
     # our dict has one item 
     self.assertEqual(1, len(n.items()))
     # and the key is 2012_05
     self.assertEqual(n.keys()[0], '2012_05')
     # and the value is [datetime(2012,5,20,0,0,0), 2]
     self.assertEqual(n['2012_05'], [datetime(2012,5,20,0,0,0), 2])
     # make a2 visible
     a2.status = Article.VISIBLE
     a2.save()
     # now it returns two items
     n = Article.objects.nav_local()
     # our dict has one item 
     self.assertEqual(2, len(n.items()))
     # the keys are in order
     self.assertEqual(n.keys()[0], '2012_05')
     self.assertEqual(n.keys()[1], '1970_01')
     # and the items are correct
     self.assertEqual(n['2012_05'], [datetime(2012,5,20,0,0,0), 2])
     self.assertEqual(n['1970_01'], [datetime(1970,1,2,0,0,0), 1])
Example #8
0
 def test_visible(self):
     """only visible news articles are returned"""
     # make article 1
     a1 = Article()
     a1.title = '1'
     a1.slug = '1'
     a1.content = '1111111'
     a1.status = Article.VISIBLE
     a1.save()
     # make article 2
     a2 = Article()
     a2.title = '2'
     a2.slug = '2'
     a2.content = '2222222'
     a2.status = Article.HIDDEN
     a2.save()
     # make article 3
     a3 = Article()
     a3.title = '3'
     a3.slug = '3'
     a3.content = '3333333'
     a3.status = Article.VISIBLE
     a3.save()
     # visible only returns two
     self.assertEqual(2, Article.objects.visible().count())
     # make a2 visible and now we have three
     a2.status = Article.VISIBLE
     a2.save()
     # visible only returns three
     self.assertEqual(3, Article.objects.visible().count())
Example #9
0
 def test_for_month(self):
     """ test that the for month returns only articles that are
     visible and for that month"""
     # make article 1
     a1 = Article()
     a1.title = '1'
     a1.slug = '1'
     a1.content = '1111111'
     a1.status = Article.VISIBLE
     a1.created = datetime(year=2012, month=5, day=20)
     a1.save()
     # make article 2
     a2 = Article()
     a2.title = '2'
     a2.slug = '2'
     a2.content = '2222222'
     a2.status = Article.HIDDEN
     a2.created = datetime(year=2012, month=4, day=20)
     a2.save()
     # make article 3
     a3 = Article()
     a3.title = '3'
     a3.slug = '3'
     a3.content = '3333333'
     a3.status = Article.VISIBLE
     a3.created = datetime(year=2012, month=5, day=20)
     a3.save()
     # 5, 2012 returns 2
     self.assertEqual(2, Article.objects.for_month(
                             month=5,
                             year=2012).count())
     # 4, 2012 returns 0
     self.assertEqual(0, Article.objects.for_month(
                             month=4,
                             year=2012).count())
     # make a2 visible
     a2.status = Article.VISIBLE
     a2.save()
     # 4, 2012 now returns 1
     self.assertEqual(1, Article.objects.for_month(
                             month=4,
                             year=2012).count())