3 from .models import Author, Work, Quote, QuoteTag
5 class Test_MassImport():
6 @pytest.fixture(scope='function')
8 a1 = Author.objects.create(name="JFK")
9 w1 = Work.objects.create(name="Berlin speech", author=a1)
10 q1 = Quote.objects.create(text="<p>Ich bin...</p>", work=w1)
13 @pytest.mark.django_db
14 def test_massimport_1(self, q1, c_adm):
22 To be or not to be, that is the question
28 To thine own self, be true
36 A rose by any other name...
45 results = c_adm.postPage('admin/massimport/', {'quotes': allquotes})
47 assert "rejected" not in results
49 assert Quote.objects.get(text="<p>To thine own self, be true</p>")
50 assert Quote.objects.get(text__contains="To be or not to be")
52 assert Author.objects.get(name="JFK")
53 assert Author.objects.get(name="William Shakespeare")
54 assert Author.objects.all().count() == 2
56 hamlet = Work.objects.get(name="Hamlet")
58 assert hamlet.author == Author.objects.get(name="William Shakespeare")
60 for quote in Quote.objects.all():
61 assert c_adm.getPage(quote.get_absolute_url())
63 @pytest.mark.django_db
64 def test_massimport_2(self, q1, c_adm):
66 <script>somethingevil()</script>
67 A rose by any other name...
76 results = c_adm.postPage('admin/massimport/', {'quotes': allquotes})
77 assert "<script>" not in results
78 with pytest.raises(Quote.DoesNotExist):
79 Quote.objects.get(text__contains="<script>")
81 @pytest.mark.django_db
82 def test_massimport_3(self, c_adm):
83 """Whitespace and stuff"""
85 A rose by any other name...
94 To be, or not to be, that is the question:
95 Whether 'tis Nobler in the mind to suffer
96 The Slings and Arrows of outrageous Fortune,
97 Or to take Arms against a Sea of troubles,
98 And by opposing end them: to die, to sleep
109 results = c_adm.postPage('admin/massimport/', {'quotes': allquotes})
110 assert "rejected" not in results
111 assert Quote.objects.get(text="<p>A rose by any other name...</p>")
112 assert Author.objects.get(name="William Shakespeare")
113 assert Work.objects.get(name="Romeo and Juliet")
114 assert QuoteTag.objects.get(tag="tag1")
115 assert QuoteTag.objects.get(tag="tag555")
117 tirade = Quote.objects.get(text__contains="To be, or not to be")
118 assert tirade.work.name == "Hamlet"
119 assert tirade.work.author.name == "William Shakespeare"
120 assert Author.objects.filter(name__contains="Shakespeare").count() == 1
122 def test_massimport_noaccess(self, c):
123 c.getPage('admin/massimport/', exp_status=302)
124 c.postPage('admin/massimport/', {}, exp_status=302)