Пример #1
0
 def test_home_adsearchview(self):
     # client just get the adsearchview
     TestAdFactory.create_batch(12)
     request = self.factory.get('/')
     response = views.AdSearchView.as_view(model=TestAd)(request)
     self.assertEqual(response.status_code, 200)
     # check that we set initial_ads
     self.assertTrue('initial_ads' in response.context_data)
     # check that ad_search_form is None
     # so that user can't save initial search
     self.assertTrue('ad_search_form' not in response.context_data)
     # check that filter is instance of AdFilterSet
     self.assertTrue(isinstance(response.context_data['filter'], AdFilterSet))
Пример #2
0
 def test_home_adsearchview(self):
     # client just get the adsearchview
     TestAdFactory.create_batch(12)
     request = self.factory.get('/')
     response = views.AdSearchView.as_view(model=TestAd)(request)
     self.assertEqual(response.status_code, 200)
     # check that we set initial_ads
     self.assertTrue('initial_ads' in response.context_data)
     # check that ad_search_form is None
     # so that user can't save initial search
     self.assertTrue('ad_search_form' not in response.context_data)
     # check that filter is instance of AdFilterSet
     self.assertTrue(
         isinstance(response.context_data['filter'], AdFilterSet))
Пример #3
0
 def test_filterads(self):
     # Filter without results
     request = self.factory.get('/', data={'brand': 'nobrand'})
     user = UserFactory.create()
     request.user = user
     response = views.AdSearchView.as_view(model=TestAd, no_results_msg="no", results_msg="yes")(request)
     # Be sure that no is in messages 
     self.assertTrue('no' in [i.message for i in request._messages])
     # Filter with results
     test_ads = TestAdFactory.create_batch(12)
     # client try to filter search
     # and get at lead one result
     request = self.factory.get('/', data={'brand': test_ads[0].brand})
     user = UserFactory.create()
     request.user = user
     response = views.AdSearchView.as_view(model=TestAd, no_results_msg="no", results_msg="yes")(request)
     # Be sure that yes is in messages 
     self.assertTrue('yes' in [i.message for i in request._messages])
     # check that we don't return initial ads
     self.assertTrue('initial_ads' not in response.context_data)
     # check that the user have a form to save it search
     self.assertTrue('ad_search_form' in response.context_data)
     # or get 0 results
     request = self.factory.get('/', data={'brand': 'nologo'})
     request.user = user
     response = views.AdSearchView.as_view(model=TestAd)(request)
Пример #4
0
 def test_filterads(self):
     # Filter without results
     request = self.factory.get('/', data={'brand': 'nobrand'})
     user = UserFactory.create()
     request.user = user
     response = views.AdSearchView.as_view(model=TestAd,
                                           no_results_msg="no",
                                           results_msg="yes")(request)
     # Be sure that no is in messages
     self.assertTrue('no' in [i.message for i in request._messages])
     # Filter with results
     test_ads = TestAdFactory.create_batch(12)
     # client try to filter search
     # and get at lead one result
     request = self.factory.get('/', data={'brand': test_ads[0].brand})
     user = UserFactory.create()
     request.user = user
     response = views.AdSearchView.as_view(model=TestAd,
                                           no_results_msg="no",
                                           results_msg="yes")(request)
     # Be sure that yes is in messages
     self.assertTrue('yes' in [i.message for i in request._messages])
     # check that we don't return initial ads
     self.assertTrue('initial_ads' not in response.context_data)
     # check that the user have a form to save it search
     self.assertTrue('ad_search_form' in response.context_data)
     # or get 0 results
     request = self.factory.get('/', data={'brand': 'nologo'})
     request.user = user
     response = views.AdSearchView.as_view(model=TestAd)(request)
Пример #5
0
 def test_filterads(self):
     test_ads = TestAdFactory.create_batch(12)
     # client try to filter search
     # and get at lead one result
     request = self.factory.get('/', data={'brand': test_ads[0].brand})
     user = UserFactory.create()
     request.user = user
     response = views.AdSearchView.as_view(model=TestAd)(request)
     # check that we don't return initial ads
     self.assertTrue('initial_ads' not in response.context_data)
     # check that the user have a form to save it search
     self.assertTrue('ad_search_form' in response.context_data)
     # or get 0 results
     request = self.factory.get('/', data={'brand': 'nologo'})
     request.user = user
     response = views.AdSearchView.as_view(model=TestAd)(request)