-
-
Notifications
You must be signed in to change notification settings - Fork 672
Expand file tree
/
Copy pathtest_templatetags.py
More file actions
57 lines (48 loc) · 1.94 KB
/
test_templatetags.py
File metadata and controls
57 lines (48 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from django.core.management import call_command
from django.template import Context, Template
from django.test import TestCase
from django.utils.timezone import now
from apps.blogs.models import BlogEntry, Feed, FeedAggregate
from apps.blogs.templatetags.blogs import get_latest_blog_entries
from apps.blogs.tests.utils import get_test_rss_path
class BlogTemplateTagTest(TestCase):
def setUp(self):
self.test_file_path = get_test_rss_path()
def test_get_latest_entries(self):
"""
Test our assignment tag, also ends up testing the update_blogs
management command
"""
Feed.objects.create(name="psf default", website_url="https://example.org", feed_url=self.test_file_path)
call_command("update_blogs")
entries = get_latest_blog_entries()
self.assertEqual(len(entries), 5)
self.assertEqual(entries[0].pub_date.isoformat(), "2013-03-04T15:00:00+00:00")
def test_feed_list(self):
f1 = Feed.objects.create(
name="psf blog",
website_url="psf.example.org",
feed_url="feed.psf.example.org",
)
BlogEntry.objects.create(title="test1", summary="", pub_date=now(), url="path/to/foo", feed=f1)
f2 = Feed.objects.create(
name="django blog",
website_url="django.example.org",
feed_url="feed.django.example.org",
)
BlogEntry.objects.create(title="test2", summary="", pub_date=now(), url="path/to/foo", feed=f2)
fa = FeedAggregate.objects.create(
name="test",
slug="test",
description="testing",
)
fa.feeds.add(f1, f2)
t = Template("""
{% load blogs %}
{% feed_list 'test' as entries %}
{% for entry in entries %}
{{ entry.title }}
{% endfor %}
""")
rendered = t.render(Context())
self.assertEqual(rendered.strip().replace(" ", ""), "test2\n\ntest1")