2 # This file is part of my.gpodder.org.
4 # my.gpodder.org is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or (at your
7 # option) any later version.
9 # my.gpodder.org is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
12 # License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with my.gpodder.org. If not, see <http://www.gnu.org/licenses/>.
22 from django
.test
import TestCase
23 from django
.core
.urlresolvers
import reverse
24 from django
.contrib
.auth
import get_user_model
26 from mygpo
.podcasts
.models
import Podcast
, Episode
, Slug
27 import mygpo
.web
.utils
28 from mygpo
.test
import create_auth_string
, anon_request
31 class SimpleWebTests(TestCase
):
35 User
= get_user_model()
36 self
.user
= User(username
='web-test', email
='web-test@example.com')
37 self
.user
.set_password('pwd')
40 self
.auth_string
= create_auth_string('test', 'pwd')
43 def tearDownClass(self
):
46 def test_access_parameterless_pages(self
):
66 self
.access_pages(pages
, [], True)
68 def test_access_podcast_pages(self
):
71 def access_pages(self
, pages
, args
, login
):
73 self
.client
.post('/login/', dict(
74 login_username
=self
.user
.username
, pwd
='pwd'))
77 response
= self
.client
.get(reverse(page
, args
=args
), follow
=True)
78 self
.assertEqual(response
.status_code
, 200)
81 class PodcastPageTests(TestCase
):
82 """ Test the podcast page """
85 # create a podcast and some episodes
86 podcast
= Podcast
.objects
.create(id=uuid
.uuid1(),
91 episode
= Episode
.objects
.get_or_create_for_url(
93 'http://www.example.com/episode%d.mp3' % (n
, ),
96 # we only need (the last) one
97 self
.episode_slug
= Slug
.objects
.create(content_object
=episode
,
99 scope
=podcast
.as_scope
,
103 self
.podcast_slug
= Slug
.objects
.create(content_object
=podcast
,
104 order
=n
, scope
=podcast
.scope
,
107 def test_podcast_queries(self
):
108 """ Test that the expected number of queries is executed """
109 url
= reverse('podcast-slug', args
=(self
.podcast_slug
.slug
, ))
110 # the number of queries must be independent of the number of episodes
112 with self
.assertNumQueries(5):
115 def test_episode_queries(self
):
116 """ Test that the expected number of queries is executed """
117 url
= reverse('episode-slug', args
=(self
.podcast_slug
.slug
,
118 self
.episode_slug
.slug
))
120 with self
.assertNumQueries(5):
124 def load_tests(loader
, tests
, ignore
):
125 tests
.addTest(doctest
.DocTestSuite(mygpo
.web
.utils
))
126 tests
.addTest(unittest
.TestLoader().loadTestsFromTestCase(SimpleWebTests
))
127 tests
.addTest(unittest
.TestLoader().loadTestsFromTestCase(PodcastPageTests
))