5 from django
.test
import TestCase
6 from django
.core
.urlresolvers
import reverse
7 from django
.contrib
.auth
import get_user_model
9 from mygpo
.podcasts
.models
import Podcast
, Episode
, Slug
10 import mygpo
.web
.utils
11 from mygpo
.test
import create_auth_string
, anon_request
14 class SimpleWebTests(TestCase
):
18 User
= get_user_model()
19 self
.user
= User(username
='web-test', email
='web-test@example.com')
20 self
.user
.set_password('pwd')
23 self
.auth_string
= create_auth_string('test', 'pwd')
26 def tearDownClass(self
):
29 def test_access_parameterless_pages(self
):
49 self
.access_pages(pages
, [], True)
51 def test_access_podcast_pages(self
):
54 def access_pages(self
, pages
, args
, login
):
56 self
.client
.post('/login/', dict(
57 login_username
=self
.user
.username
, pwd
='pwd'))
60 response
= self
.client
.get(reverse(page
, args
=args
), follow
=True)
61 self
.assertEqual(response
.status_code
, 200)
64 class PodcastPageTests(TestCase
):
65 """ Test the podcast page """
68 # create a podcast and some episodes
69 podcast
= Podcast
.objects
.create(id=uuid
.uuid1(),
74 episode
= Episode
.objects
.get_or_create_for_url(
76 'http://www.example.com/episode%d.mp3' % (n
, ),
79 # we only need (the last) one
80 self
.episode_slug
= Slug
.objects
.create(content_object
=episode
,
82 scope
=podcast
.as_scope
,
86 self
.podcast_slug
= Slug
.objects
.create(content_object
=podcast
,
87 order
=n
, scope
=podcast
.scope
,
90 def test_podcast_queries(self
):
91 """ Test that the expected number of queries is executed """
92 url
= reverse('podcast-slug', args
=(self
.podcast_slug
.slug
, ))
93 # the number of queries must be independent of the number of episodes
95 with self
.assertNumQueries(5):
98 def test_episode_queries(self
):
99 """ Test that the expected number of queries is executed """
100 url
= reverse('episode-slug', args
=(self
.podcast_slug
.slug
,
101 self
.episode_slug
.slug
))
103 with self
.assertNumQueries(5):