def test_initial_data(self): sv = SearchView(form_class=InitialedSearchForm) sv.request = HttpRequest() form = sv.build_form() self.assertTrue(isinstance(form, InitialedSearchForm)) self.assertEqual(form.fields['q'].initial, 'Search for...') para = form.as_p() self.assertTrue('<label for="id_q">Search:</label>' in para) self.assertTrue('value="Search for..."' in para)
def test_spelling(self): # Stow. from django.conf import settings old = settings.SEARCHSTACK_CONNECTIONS['default'].get('INCLUDE_SPELLING', None) sv = SearchView() sv.query = 'Nothing' sv.results = [] sv.build_page = lambda: (None, None) output = sv.create_response() # Restore settings.SEARCHSTACK_CONNECTIONS['default']['INCLUDE_SPELLING'] = old if old is None: del settings.SEARCHSTACK_CONNECTIONS['default']['INCLUDE_SPELLING']
def test_empty_results(self): sv = SearchView() sv.request = HttpRequest() sv.form = sv.build_form() self.assertTrue(isinstance(sv.get_results(), EmptySearchQuerySet))