Exemplo n.º 1
0
    def test_details(self):
        # Create an instance of a GET request.


        from django.test.client import RequestFactory
        from haystack.views import SearchView
        import urllib2
        url = '/search/?q=information'
        request = urllib2.Request(url)
        #request.add_header("Content-Type", "application/json") #
        sv = SearchView(request)
        sv.build_form()
        results = sv.get_results()
        # Test my_view() as if it were deployed at /customer/details
        self.assertEqual(len(results), 35)
Exemplo n.º 2
0
 def test_initial_data(self):
     sv = SearchView(form_class=InitialedSearchForm)
     sv.request = HttpRequest()
     form = sv.build_form()
     self.assert_(isinstance(form, InitialedSearchForm))
     self.assertEqual(form.fields['q'].initial, 'Search for...')
     self.assertEqual(form.as_p(), u'<p><label for="id_q">Search:</label> <input type="text" name="q" value="Search for..." id="id_q" /></p>')
Exemplo n.º 3
0
 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(u'<label for="id_q">Search:</label>' in para)
     self.assertTrue(u'value="Search for..."' in para)
Exemplo n.º 4
0
 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(u'<label for="id_q">Search:</label>' in para)
     self.assertTrue(u'value="Search for..."' in para)
Exemplo n.º 5
0
 def test_initial_data(self):
     sv = SearchView(form_class=InitialedSearchForm)
     sv.request = HttpRequest()
     form = sv.build_form()
     self.assert_(isinstance(form, InitialedSearchForm))
     self.assertEqual(form.fields['q'].initial, 'Search for...')
     self.assertEqual(
         form.as_p(),
         u'<p><label for="id_q">Search:</label> <input type="text" name="q" value="Search for..." id="id_q" /></p>'
     )
Exemplo n.º 6
0
    def build_form(self, form_kwargs=None):

        user = self.request.user
        kwargs = {'workspaces': None, 'user': user}

        if not user.is_anonymous and user.areatrabalho_set.exists():

            at = user.areatrabalho_set.all()
            #.union(
            #   AreaTrabalho.objects.areatrabalho_publica())
            kwargs['workspaces'] = at
        else:
            kwargs['workspaces'] = AreaTrabalho.objects.areatrabalho_publica()

        if form_kwargs:
            kwargs.update(form_kwargs)

        return SearchView.build_form(self, form_kwargs=kwargs)
Exemplo n.º 7
0
 def test_empty_results(self):
     sv = SearchView()
     sv.request = HttpRequest()
     sv.form = sv.build_form()
     self.assert_(isinstance(sv.get_results(), EmptySearchQuerySet))
Exemplo n.º 8
0
 def test_empty_results(self):
     sv = SearchView()
     sv.request = HttpRequest()
     sv.form = sv.build_form()
     self.assertTrue(isinstance(sv.get_results(), EmptySearchQuerySet))