[Publisher] incorrect number of new/existing publisher permissions
[mygpo.git] / mygpo / web / tests.py
blobfc5db80a7c5ec6140c21b94e45c7a5ebb1b613bf
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/>.
18 import unittest
19 import doctest
20 import uuid
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):
33 @classmethod
34 def setUpClass(self):
35 User = get_user_model()
36 self.user = User(username='web-test', email='web-test@example.com')
37 self.user.set_password('pwd')
38 self.user.save()
40 self.auth_string = create_auth_string('test', 'pwd')
42 @classmethod
43 def tearDownClass(self):
44 self.user.delete()
46 def test_access_parameterless_pages(self):
47 pages = [
48 'history',
49 'suggestions',
50 'tags',
51 'subscriptions',
52 'subscriptions-opml',
53 'favorites',
54 'account',
55 'privacy',
56 'delete-account',
57 'share',
58 'toplist',
59 'episode-toplist',
60 'devices',
61 'device-create',
62 'login',
63 'logout',
64 'home']
66 self.access_pages(pages, [], True)
68 def test_access_podcast_pages(self):
69 pages = ['podcast', ]
71 def access_pages(self, pages, args, login):
72 if login:
73 self.client.post('/login/', dict(
74 login_username=self.user.username, pwd='pwd'))
76 for page in pages:
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 """
84 def setUp(self):
85 # create a podcast and some episodes
86 podcast = Podcast.objects.create(id=uuid.uuid1().hex,
87 title='My Podcast')
88 for n in range(20):
89 episode = Episode.objects.create(id=uuid.uuid1().hex,
90 podcast=podcast,
92 # we only need (the last) one
93 self.episode_slug = Slug.objects.create(content_object=episode,
94 order=0,
95 scope=podcast.as_scope,
96 slug=str(n),
99 self.podcast_slug = Slug.objects.create(content_object=podcast,
100 order=n, scope=podcast.scope,
101 slug='podcast')
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):
109 anon_request(url)
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):
117 anon_request(url)
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))
124 return tests