+from django.test import Client
+
+# Create your tests here.
+import pytest
+
+from .models import Author, Work, Quote
+import lxml.etree
+
+class Test_Search():
+ @pytest.fixture(scope='function')
+ def q1(self, db):
+ a1 = Author.objects.create(name="JFK")
+ w1 = Work.objects.create(name="Berlin speech", author=a1)
+ q1 = Quote.objects.create(text="<p>Ich bin...</p>", work=w1)
+ return q1
+
+ def postPage(self, url, params, exp_status=200):
+ c = Client()
+ response = c.post('/quotes/' + url, params)
+ assert response.status_code == 200
+ assert response.charset == 'utf-8'
+ document = response.content.decode(response.charset)
+ lxml.etree.fromstring(document)
+ assert '<script>' not in document
+ print document
+ return document
+
+ @pytest.mark.django_db
+ def test_search(self, q1):
+ results = self.postPage('search/', {'q': 'Ich'})
+
+ assert 'JFK' in results