]> gitweb.fperrin.net Git - djsite.git/commitdiff
Add a search page
authorFrédéric Perrin <frederic.perrin@resel.fr>
Thu, 3 Nov 2016 19:36:55 +0000 (19:36 +0000)
committerFrédéric Perrin <frederic.perrin@resel.fr>
Thu, 3 Nov 2016 19:36:55 +0000 (19:36 +0000)
quotes/test_search.py [new file with mode: 0644]

diff --git a/quotes/test_search.py b/quotes/test_search.py
new file mode 100644 (file)
index 0000000..3a06d3e
--- /dev/null
@@ -0,0 +1,32 @@
+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