Fundraising in PDF.
[wolnelektury.git] / src / catalogue / tests / test_visit.py
1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 from catalogue import models
5 from catalogue.test_utils import BookInfoStub, PersonStub, WLTestCase, info_args
6 from django.core.files.base import ContentFile
7
8
9 class VisitTest(WLTestCase):
10     """Simply create some objects and visit some views."""
11
12     def setUp(self):
13         WLTestCase.setUp(self)
14         author = PersonStub(("Jane",), "Doe")
15         book_info = BookInfoStub(author=author, genre="Sielanka",
16             epoch='Epoch', kind="Kind", **info_args("A book"))
17         self.book = models.Book.from_text_and_meta(ContentFile('''
18             <utwor>
19             <opowiadanie>
20                 <akap>
21                     <begin id="b1" />
22                     <motyw id="m1">Sielanka</motyw>
23                     Test
24                     <end id="e1" />
25                 </akap>
26             </opowiadanie>
27             </utwor>
28             '''), book_info)
29         self.collection = models.Collection.objects.create(
30             title='Biblioteczka Boya', slug='boy', book_slugs='a-book')
31
32     def test_visit_urls(self):
33         """ book description should return authors, ancestors, book """
34         url_map = {
35             200: [
36                 '',
37                 'lektury/',
38                 'lektury/boy/',
39                 'nowe/',
40                 'lektura/a-book/',
41                 'lektura/a-book.html',
42                 'lektura/a-book/motyw/sielanka/',
43                 'motyw/sielanka/',
44                 'sielanka/',
45                 'autor/jane-doe/',
46                 'daisy/',
47                 # 'autor/jane-doe/gatunek/genre/',
48                 # 'autor/jane-doe/gatunek/genre/motyw/sielanka/',
49                 ],
50             404: [
51                 'lektury/nonexistent/',  # Nonexistent Collection.
52                 'lektura/nonexistent/',  # Nonexistent Book.
53                 'lektura/nonexistent.html',  # Nonexistent Book's HTML.
54                 'lektura/nonexistent/motyw/sielanka/',  # Nonexistent Book's theme.
55                 'lektura/a-book/motyw/nonexistent/',  # Nonexistent theme in a Book.
56                 'autor/nonexistent/',  # Nonexistent author.
57                 'motyw/nonexistent/',  # Nonexistent theme.
58                 'zh.json',  # Nonexistent language.
59                 ]
60             }
61         prefix = '/katalog/'
62         for expected_status, urls in url_map.items():
63             for url in urls:
64                 status = self.client.get(prefix + url).status_code
65                 self.assertEqual(
66                     status, expected_status,
67                     "Wrong status code for '%s'. Expected %d, got %d." % (prefix + url, expected_status, status))