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