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.
5 from catalogue import models
6 from catalogue.test_utils import BookInfoStub, PersonStub, WLTestCase, info_args
7 from django.core.files.base import ContentFile
10 class VisitTest(WLTestCase):
11 """Simply create some objects and visit some views."""
14 WLTestCase.setUp(self)
15 author = PersonStub(("Jane",), "Doe")
16 book_info = BookInfoStub(author=author, genre="Sielanka",
17 epoch='Epoch', kind="Kind", **info_args(u"A book"))
18 self.book = models.Book.from_text_and_meta(ContentFile('''
23 <motyw id="m1">Sielanka</motyw>
30 self.collection = models.Collection.objects.create(
31 title='Biblioteczka Boya', slug='boy', book_slugs='a-book')
33 def test_visit_urls(self):
34 """ book description should return authors, ancestors, book """
42 'lektura/a-book.html',
43 'lektura/a-book/motyw/sielanka/',
48 # 'autor/jane-doe/gatunek/genre/',
49 # 'autor/jane-doe/gatunek/genre/motyw/sielanka/',
50 'b/%d/mini.pl.html' % self.book.pk,
51 'b/%d/mini_nolink.pl.html' % self.book.pk,
52 'b/%d/short.pl.html' % self.book.pk,
53 'b/%d/wide.pl.html' % self.book.pk,
54 'f/%d/promo.pl.html' % self.book.fragments.all()[0].pk,
55 'f/%d/short.pl.html' % self.book.fragments.all()[0].pk,
58 'lektury/nonexistent/', # Nonexistent Collection.
59 'lektura/nonexistent/', # Nonexistent Book.
60 'lektura/nonexistent.html', # Nonexistent Book's HTML.
61 'lektura/nonexistent/motyw/sielanka/', # Nonexistent Book's theme.
62 'lektura/a-book/motyw/nonexistent/', # Nonexistent theme in a Book.
63 'autor/nonexistent/', # Nonexistent author.
64 'motyw/nonexistent/', # Nonexistent theme.
65 'zh.json', # Nonexistent language.
66 'b/%d/mini.pl.html' % (self.book.pk + 100), # Nonexistent book.
67 'b/%d/mini_nolink.pl.html' % (self.book.pk + 100), # Nonexistent book.
68 'b/%d/short.pl.html' % (self.book.pk + 100), # Nonexistent book.
69 'b/%d/wide.pl.html' % (self.book.pk + 100), # Nonexistent book.
70 'f/%d/promo.pl.html' % (self.book.fragments.all()[0].pk + 100), # Nonexistent fragment.
71 'f/%d/short.pl.html' % (self.book.fragments.all()[0].pk + 100), # Nonexistent fragment.
75 for expected_status, urls in url_map.items():
77 status = self.client.get(prefix + url).status_code
79 status, expected_status,
80 "Wrong status code for '%s'. Expected %d, got %d." % (prefix + url, expected_status, status))