1 # -*- encoding: utf-8 -*-
5 from .models import QuoteTag, Author, Work, Quote
8 class Test_QuoteTest():
9 @pytest.fixture(scope='function')
11 a1 = Author.objects.create(name="JFK")
12 w1 = Work.objects.create(name="Berlin speech", author=a1)
13 q1 = Quote.objects.create(text="<p>Ich bin...</p>", work=w1)
16 @pytest.mark.django_db
17 def test_one(self, q1):
18 q = Quote.objects.filter(text__startswith="<p>Ich")
22 assert q.work.author.name == 'JFK'
25 @pytest.fixture(autouse=True, scope='function')
27 a1 = Author.objects.create(name="Author with notes",
28 notes="<script>Some notes for the author</script>")
29 w1 = Work.objects.create(name="Context with some notes",
31 notes="<p>Some notes for the work</p>")
32 q1 = Quote.objects.create(text="<p>Quote01, two tags</p>",
34 notes="<p>Some notes for the quote</p>")
35 t1 = QuoteTag.objects.create(tag="tag01-1")
36 t2 = QuoteTag.objects.create(tag="tag01-2")
39 a2 = Author.objects.create(name="Author without notes")
40 w2 = Work.objects.create(name="Work without notes", author=a2)
41 q2 = Quote.objects.create(text="<p>Quote02, no tags</p>", work=w2)
42 assert q2.tags.all().count() == 0
44 def test_all(self, c):
45 content = c.getPage('all/')
46 for a in Author.objects.all():
47 assert a.name in content
48 assert a.notes in content
49 for w in Work.objects.all():
50 assert w.name in content
51 assert w.notes in content
52 for q in Quote.objects.all():
53 assert q.text in content
54 assert q.notes in content
56 c.checkAllLinks('all/', content)
59 def test_random(self, c):
61 for q in Quote.objects.all():
64 # <a href="{% url 'quotes:onequote' quote.id %}">Permalink</a>
65 permalinkre = re.compile(r'([0-9]+).*Permalink')
68 content = c.getPage('random')
69 m = permalinkre.search(content)
70 assert m is not None, "Did not find the permalink in: "+content
71 quoteid = int(m.group(1))
72 assert quoteid in seen
74 for q in Quote.objects.all():
77 def test_views_all_data(self, c):
78 q = Quote.objects.filter(text__startswith="<p>Quote01")
79 assert q.count() == 1, "Couldn't find Quote01 after insertion"
82 # check the individual quote page; each of the note type is displayed
83 quotepage = c.getPage('show/%s/' % q.id)
84 assert q.text in quotepage
85 assert "author_notes" in quotepage
86 assert "work_notes" in quotepage
87 assert "tag_link" in quotepage
88 assert quotepage.count("tag_link") == 2
90 # check the work page; each of the note type is displayed, and
91 # the work notes are shown only once
92 workpage = c.getPage('work/%s/' % q.work.id)
93 assert q.text in workpage
94 assert "author_notes" in workpage
95 assert "work_notes" in workpage
96 assert workpage.count("work_notes") == 1
97 assert "tag_link" in workpage
99 # check the author page; each of the note type is displayed, and
100 # the author notes are shown only once
101 authorpage = c.getPage('author/%s/' % q.work.author.id)
102 assert q.text in authorpage
103 assert "author_notes" in authorpage
104 assert authorpage.count("author_notes") == 1
105 assert "work_notes" in authorpage
106 assert "tag_link" in authorpage
109 for tag in q.tags.all():
110 tagpage = c.getPage('tag/%s/' % tag.id)
111 assert q.text in tagpage
113 def test_views_minimal_data(self, c):
114 q = Quote.objects.filter(text__startswith="<p>Quote02")
115 assert q.count() == 1, \
116 "Couldn't find Quote02 after insertion"
119 quotepage = c.getPage('show/%s/' % q.id)
120 assert q.text in quotepage
121 assert "author_notes" not in quotepage
122 assert "work_notes" not in quotepage
123 assert "tag_link" not in quotepage
125 workpage = c.getPage('work/%s/' % q.work.id)
126 assert q.text in workpage
127 assert "author_notes" not in quotepage
128 assert "work_notes" not in quotepage
129 assert "tag_link" not in quotepage
131 authorpage = c.getPage('author/%s/' % q.work.author.id)
132 assert q.text in authorpage
133 assert "author_notes" not in authorpage
134 assert "work_notes" not in authorpage
135 assert "tag_link" not in authorpage
136 assert 'Quote01, two tags' not in authorpage
138 def test_view_author_notes_once(self, c):
139 # check that on the per-author view, the author notes aren't display
141 a = Author.objects.filter(name="Author with notes")
142 assert a.count() == 1
145 authorpage = c.getPage('author/%s/' % a.id)
146 assert authorpage.count("Some notes for the author") == 1
148 class Test_Unicode():
149 def test_unicode(self, db):
150 a = Author.objects.create(name="ê è “smart ''quotes,”")
151 w = Work.objects.create(name="¿who?If you’re creati'' ng a", author=a)
152 q = Quote.objects.create(text="µqwer If you’r'' ¨ë ẽ « or » e ", work=w)
153 t = QuoteTag.objects.create(tag=", “s tag 'a’ ß")
155 for t in QuoteTag.objects.all():
157 for w in Work.objects.all():
159 for a in Author.objects.all():
161 for q in Quote.objects.all():