コード例 #1
0
 def test_can_add_can_add_new_querystrings(self):
     # Setup
     qs = 'foo=bar?xyz=test'
     request = self.factory.get('/')
     middleware = SessionMiddleware()
     middleware.process_request(request)
     searches = SavedSearchList(request)
     # Run
     searches.add(qs, 100)
     # Check
     assert len(searches) == 1
     assert searches[0]['querystring'] == qs
     assert searches[0]['results_count'] == 100
     assert searches[0]['uuid']
     assert searches[0]['timestamp']
コード例 #2
0
ファイル: test_views.py プロジェクト: erudit/eruditorg
 def test_can_insert_the_saved_searches_into_the_context(self):
     # Setup
     url = reverse('public:search:advanced_search')
     request = self.factory.get(url)
     request.user = AnonymousUser()
     SessionMiddleware().process_request(request)
     view = AdvancedSearchView.as_view()
     searches = SavedSearchList(request)
     searches.add('foo=bar&xyz=test', 100)
     searches.save()
     # Run
     response = view(request)
     # Check
     assert response.status_code == 200
     assert len(response.context_data['saved_searches']) == 1
     assert response.context_data['saved_searches'][0]['querystring'] \
         == searches[0]['querystring']
     assert response.context_data['saved_searches'][0]['results_count'] == 100
コード例 #3
0
 def test_cannot_add_a_search_if_the_results_count_is_not_provided(self):
     # Setup
     request = self.factory.post('/', {'querystring': 'foo=bar&xyz=test'})
     request.user = AnonymousUser()
     SessionMiddleware().process_request(request)
     view = SavedSearchAddView.as_view()
     # Run
     view(request)
     # Check
     searches = SavedSearchList(request)
     assert not len(searches)
コード例 #4
0
 def test_can_remove_a_search_from_the_list_of_saved_searches_if_the_uuid_is_not_in_it(
         self):
     # Setup
     request = self.factory.post('/')
     request.user = AnonymousUser()
     SessionMiddleware().process_request(request)
     view = SavedSearchRemoveView.as_view()
     searches = SavedSearchList(request)
     searches.add('foo=bar&xyz=test', 100)
     searches.save()
     # Run
     response = view(request, 'unknown')
     # Check
     assert response.status_code == 200
     searches = SavedSearchList(request)
     assert len(searches) == 1
コード例 #5
0
 def test_cannot_add_a_search_if_the_querystring_is_not_a_valid_querystring(
         self):
     # Setup
     request = self.factory.post('/', {
         'querystring': 'bad',
         'results_count': 100
     })
     request.user = AnonymousUser()
     SessionMiddleware().process_request(request)
     view = SavedSearchAddView.as_view()
     # Run
     view(request)
     # Check
     searches = SavedSearchList(request)
     assert not len(searches)
コード例 #6
0
 def test_can_be_saved_in_the_user_session(self):
     # Setup
     qs = 'foo=bar?xyz=test'
     request = self.factory.get('/')
     middleware = SessionMiddleware()
     middleware.process_request(request)
     searches = SavedSearchList(request)
     searches.add(qs, 100)
     # Run
     searches.save()
     # Check
     assert request.session['saved-searches'] == list(searches)
コード例 #7
0
 def test_can_remove_an_existing_search_using_its_uuid(self):
     # Setup
     qs = 'foo=bar?xyz=test'
     request = self.factory.get('/')
     middleware = SessionMiddleware()
     middleware.process_request(request)
     searches = SavedSearchList(request)
     searches.add(qs, 100)
     uuid = searches[0]['uuid']
     # Run
     searches.remove(uuid)
     # Check
     assert not len(searches)
コード例 #8
0
 def test_can_add_a_search_to_the_list_of_saved_searches(self):
     # Setup
     request = self.factory.post('/', {
         'querystring': 'foo=bar&xyz=test',
         'results_count': 100
     })
     request.user = AnonymousUser()
     SessionMiddleware().process_request(request)
     view = SavedSearchAddView.as_view()
     # Run
     response = view(request)
     # Check
     assert response.status_code == 200
     searches = SavedSearchList(request)
     assert len(searches) == 1
     assert searches[0]['querystring'] == 'foo=bar&xyz=test'
     assert searches[0]['results_count'] == 100
     assert searches[0]['uuid']
     assert searches[0]['timestamp']
コード例 #9
0
ファイル: test_views.py プロジェクト: erudit/eruditorg
 def test_can_remove_a_search_from_the_list_of_saved_searches_if_the_uuid_is_not_in_it(self):
     # Setup
     request = self.factory.post('/')
     request.user = AnonymousUser()
     SessionMiddleware().process_request(request)
     view = SavedSearchRemoveView.as_view()
     searches = SavedSearchList(request)
     searches.add('foo=bar&xyz=test', 100)
     searches.save()
     # Run
     response = view(request, 'unknown')
     # Check
     assert response.status_code == 200
     searches = SavedSearchList(request)
     assert len(searches) == 1
コード例 #10
0
 def test_can_insert_the_saved_searches_into_the_context(self):
     # Setup
     url = reverse('public:search:advanced_search')
     request = self.factory.get(url)
     request.user = AnonymousUser()
     SessionMiddleware().process_request(request)
     view = AdvancedSearchView.as_view()
     searches = SavedSearchList(request)
     searches.add('foo=bar&xyz=test', 100)
     searches.save()
     # Run
     response = view(request)
     # Check
     assert response.status_code == 200
     assert len(response.context_data['saved_searches']) == 1
     assert response.context_data['saved_searches'][0]['querystring'] \
         == searches[0]['querystring']
     assert response.context_data['saved_searches'][0][
         'results_count'] == 100