| 1 |
# vim: fileencoding=utf-8 : |
|---|
| 2 |
|
|---|
| 3 |
from datetime import datetime |
|---|
| 4 |
from lxml import etree |
|---|
| 5 |
|
|---|
| 6 |
from django.conf import settings |
|---|
| 7 |
from django.test import TestCase |
|---|
| 8 |
from plugins.views import ContentsManager, Content, ArchiveContent,\ |
|---|
| 9 |
TagCloudContent, RecentEntriesContent, RecentCommentsContent |
|---|
| 10 |
|
|---|
| 11 |
class SimpleTest(TestCase): |
|---|
| 12 |
def setUp(self): |
|---|
| 13 |
settings.SUB_CONTENTS = ( |
|---|
| 14 |
'plugins.views.TagCloudContent', |
|---|
| 15 |
'plugins.views.RecentEntriesContent', |
|---|
| 16 |
) |
|---|
| 17 |
settings.EXTRA_CONTENTS = ( |
|---|
| 18 |
'plugins.views.RecentCommentsContent', |
|---|
| 19 |
'plugins.views.ArchiveContent', |
|---|
| 20 |
) |
|---|
| 21 |
|
|---|
| 22 |
def test_contents_manager(self): |
|---|
| 23 |
settings.SUB_CONTENTS = ( |
|---|
| 24 |
'plugins.views.TagCloudContent', |
|---|
| 25 |
'plugins.views.RecentEntriesContent', |
|---|
| 26 |
'plugins.views.RecentCommentsContent', |
|---|
| 27 |
'plugins.views.ArchiveContent', |
|---|
| 28 |
) |
|---|
| 29 |
sub_contents = ContentsManager("SUB_CONTENTS") |
|---|
| 30 |
rendered = sub_contents.render() |
|---|
| 31 |
|
|---|
| 32 |
html = etree.fromstring(rendered, parser=etree.HTMLParser()) |
|---|
| 33 |
self.assertEqual(len(html.xpath('//div[@class="content-box"]')), 4) |
|---|
| 34 |
|
|---|
| 35 |
def test_content(self): |
|---|
| 36 |
c = Content() |
|---|
| 37 |
try: |
|---|
| 38 |
c.render() |
|---|
| 39 |
self.fail("expected exception, but uncaught.") |
|---|
| 40 |
except NotImplementedError, e: |
|---|
| 41 |
pass |
|---|
| 42 |
|
|---|
| 43 |
def test_archive_content(self): |
|---|
| 44 |
rendered = ArchiveContent().render() |
|---|
| 45 |
html = etree.fromstring(rendered, parser=etree.HTMLParser()) |
|---|
| 46 |
|
|---|
| 47 |
self.assertEqual(len(html.xpath('//div[@class="content-box"]')), 1) |
|---|
| 48 |
self.assertEqual(len(html.xpath('//div[@class="content-box"]/ul/li')), 1) |
|---|
| 49 |
|
|---|
| 50 |
def test_tagcloud_content(self): |
|---|
| 51 |
rendered = TagCloudContent().render() |
|---|
| 52 |
html = etree.fromstring(rendered, parser=etree.HTMLParser()) |
|---|
| 53 |
|
|---|
| 54 |
self.assertEqual(len(html.xpath('//div[@class="content-box"]')), 1) |
|---|
| 55 |
self.assertEqual(len(html.xpath('//div[@class="content-box"]/ul/li')), 6) |
|---|
| 56 |
|
|---|
| 57 |
def test_recent_entries_content(self): |
|---|
| 58 |
rendered = RecentEntriesContent().render() |
|---|
| 59 |
html = etree.fromstring(rendered, parser=etree.HTMLParser()) |
|---|
| 60 |
|
|---|
| 61 |
self.assertEqual(len(html.xpath('//div[@class="content-box"]')), 1) |
|---|
| 62 |
self.assertEqual(len(html.xpath('//div[@class="content-box"]/ul/li')), 10) |
|---|
| 63 |
|
|---|
| 64 |
def test_recent_comments_content(self): |
|---|
| 65 |
rendered = RecentCommentsContent().render() |
|---|
| 66 |
html = etree.fromstring(rendered, parser=etree.HTMLParser()) |
|---|
| 67 |
|
|---|
| 68 |
self.assertEqual(len(html.xpath('//div[@class="content-box"]')), 1) |
|---|
| 69 |
self.assertEqual(len(html.xpath('//div[@class="content-box"]/ul/li')), 10) |
|---|