forked from python/pythondotorg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_views.py
40 lines (32 loc) · 1.1 KB
/
test_views.py
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
from django.core.management import call_command
from django.test import TestCase
from django.urls import reverse
from .utils import get_test_rss_path
from ..models import (
BlogEntry,
Feed,
)
class BlogViewTest(TestCase):
def setUp(self):
self.test_file_path = get_test_rss_path()
def test_blog_home(self):
"""
Test our assignment tag, also ends up testing the update_blogs
management command
"""
Feed.objects.create(
id=1, name='psf default', website_url='example.org',
feed_url=self.test_file_path)
call_command('update_blogs')
resp = self.client.get(reverse('blog'))
self.assertEqual(resp.status_code, 200)
latest = BlogEntry.objects.latest()
self.assertEqual(resp.context['latest_entry'], latest)
def test_blog_redirects(self):
"""
Test that when '/blog/' is hit, it redirects '/blogs/'
"""
response = self.client.get('/blog/')
self.assertRedirects(response,
'/blogs/',
status_code=301)