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
.assertEquals(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().hex,
89 episode
= Episode
.objects
.create(id=uuid
.uuid1().hex,
92 # we only need (the last) one
93 self
.episode_slug
= Slug
.objects
.create(content_object
=episode
,
95 scope
=podcast
.as_scope
,
99 self
.podcast_slug
= Slug
.objects
.create(content_object
=podcast
,
100 order
=n
, scope
=podcast
.scope
,
103 def test_podcast_queries(self
):
104 """ Test that the expected number of queries is executed """
105 url
= reverse('podcast-slug', args
=(self
.podcast_slug
.slug
, ))
106 # the number of queries must be independent of the number of episodes
108 with self
.assertNumQueries(6):
111 def test_episode_queries(self
):
112 """ Test that the expected number of queries is executed """
113 url
= reverse('episode-slug', args
=(self
.podcast_slug
.slug
,
114 self
.episode_slug
.slug
))
116 with self
.assertNumQueries(5):
120 def load_tests(loader
, tests
, ignore
):
121 tests
.addTest(doctest
.DocTestSuite(mygpo
.web
.utils
))
122 tests
.addTest(unittest
.TestLoader().loadTestsFromTestCase(SimpleWebTests
))
123 tests
.addTest(unittest
.TestLoader().loadTestsFromTestCase(PodcastPageTests
))