]> gitweb.fperrin.net Git - djsite.git/blob - quotes/test_search.py
Add a search page
[djsite.git] / quotes / test_search.py
1 from django.test import Client
2
3 # Create your tests here.
4 import pytest
5
6 from .models import Author, Work, Quote
7 import lxml.etree
8
9 class Test_Search():
10     @pytest.fixture(scope='function')
11     def q1(self, db):
12         a1 = Author.objects.create(name="JFK")
13         w1 = Work.objects.create(name="Berlin speech", author=a1)
14         q1 = Quote.objects.create(text="<p>Ich bin...</p>", work=w1)
15         return q1
16
17     def postPage(self, url, params, exp_status=200):
18         c = Client()
19         response = c.post('/quotes/' + url, params)
20         assert response.status_code == 200
21         assert response.charset == 'utf-8'
22         document = response.content.decode(response.charset)
23         lxml.etree.fromstring(document)
24         assert '<script>' not in document
25         print document
26         return document
27
28     @pytest.mark.django_db
29     def test_search(self, q1):
30         results = self.postPage('search/', {'q': 'Ich'})
31
32         assert 'JFK' in results