class SearchStateTests(TestCase): def setUp(self): self.state = SearchState() self.log = ViewLog() def visit_page(self, page_name): """page_name is name of the view function that is to be "visited" """ self.log.set_current(page_name) def update(self, data, user = None): self.visit_page('questions') if user is None: user = AnonymousUser() self.state.update(data, self.log, user) def add_tag(self, tag): self.update({'tags': set([tag])}) def remove_tag(self, tag): self.update({'remove_tag': tag}) def assert_tags_are(self, *args): self.assertEqual(self.state.tags, set(args)) def test_add_remove_tags(self): self.add_tag('tag1') self.assert_tags_are('tag1') self.add_tag('tag2') self.assert_tags_are('tag1', 'tag2') self.add_tag('tag3') self.assert_tags_are('tag1', 'tag2', 'tag3') self.remove_tag('tag3') self.assert_tags_are('tag1', 'tag2') self.remove_tag('tag2') self.assert_tags_are('tag1') self.remove_tag('tag1') self.assertEqual(len(self.state.tags), 0) def test_query_and_tags1(self): self.update({'query': 'hahaha'}) self.add_tag('tag1') self.assertEquals(self.state.query, 'hahaha') self.assert_tags_are('tag1') self.update({'reset_query':True}) self.assertEquals(self.state.query, None) self.assert_tags_are('tag1') def test_auto_reset_sort(self): self.update({'sort': 'age-asc'}) self.assertEquals(self.state.sort, 'age-asc') self.update({}) self.assertEquals(self.state.sort, DEFAULT_SORT)
class SearchStateTests(TestCase): def setUp(self): self.state = SearchState() self.log = ViewLog() def visit_page(self, page_name): """page_name is name of the view function that is to be "visited" """ self.log.set_current(page_name) def update(self, data, user=None): self.visit_page("questions") if user is None: user = AnonymousUser() self.state.update(data, self.log, user) def add_tag(self, tag): self.update({"tags": set([tag])}) def remove_tag(self, tag): self.update({"remove_tag": tag}) def assert_tags_are(self, *args): self.assertEqual(self.state.tags, set(args)) def test_add_remove_tags(self): self.add_tag("tag1") self.assert_tags_are("tag1") self.add_tag("tag2") self.assert_tags_are("tag1", "tag2") self.add_tag("tag3") self.assert_tags_are("tag1", "tag2", "tag3") self.remove_tag("tag3") self.assert_tags_are("tag1", "tag2") self.remove_tag("tag2") self.assert_tags_are("tag1") self.remove_tag("tag1") self.assertEqual(len(self.state.tags), 0) def test_query_and_tags1(self): self.update({"query": "hahaha"}) self.add_tag("tag1") self.assertEquals(self.state.query, "hahaha") self.assert_tags_are("tag1") self.update({"reset_query": True}) self.assertEquals(self.state.query, None) self.assert_tags_are("tag1") def test_auto_reset_sort(self): self.update({"sort": "age-asc"}) self.assertEquals(self.state.sort, "age-asc") self.update({}) self.assertEquals(self.state.sort, DEFAULT_SORT)
def process_view(self, request, view_func, view_args, view_kwargs): #send the site_visited signal for the authenticated users if request.user.is_authenticated(): signals.site_visited.send( None, #this signal has no sender user=request.user, timestamp=datetime.datetime.now()) #remaining stuff is for the search state if view_func == questions_view: view_str = 'questions' elif view_func in IGNORED_VIEWS: return else: view_str = view_func.__name__ if view_str == 'wrap': return if settings.DEBUG == True: #todo: dependency! try: from debug_toolbar.views import debug_media as debug_media_view if view_func == debug_media_view: return except ImportError: pass logging.debug('user %s, view %s' % (request.user.username, view_str)) logging.debug('next url is %s' % request.REQUEST.get('next', 'nothing')) if 'view_log' in request.session: view_log = request.session['view_log'] else: view_log = ViewLog() view_log.set_current(view_str) request.session['view_log'] = view_log
def process_view(self, request, view_func, view_args, view_kwargs): #send the site_visited signal for the authenticated users if request.user.is_authenticated(): signals.site_visited.send(None, #this signal has no sender user = request.user, timestamp = datetime.datetime.now() ) #remaining stuff is for the search state if view_func == questions_view: view_str = 'questions' elif view_func in IGNORED_VIEWS: return else: view_str = view_func.__name__ if view_str == 'wrap': return if settings.DEBUG == True: #todo: dependency! try: from debug_toolbar.views import debug_media as debug_media_view if view_func == debug_media_view: return except ImportError: pass logging.debug('user %s, view %s' % (request.user.username, view_str)) logging.debug('next url is %s' % request.REQUEST.get('next','nothing')) if 'view_log' in request.session: view_log = request.session['view_log'] else: view_log = ViewLog() view_log.set_current(view_str) request.session['view_log'] = view_log
class SearchStateTests(TestCase): def setUp(self): self.state = SearchState() self.log = ViewLog() def visit_page(self, page_name): """page_name is name of the view function that is to be "visited" """ self.log.set_current(page_name) def update(self, data, user = None): self.visit_page('questions') if user is None: user = AnonymousUser() self.state.update(data, self.log, user) def add_tag(self, tag): self.update({'tags': set([tag])}) def remove_tag(self, tag): self.update({'remove_tag': tag}) def assert_tags_are(self, *args): self.assertEqual(self.state.tags, set(args)) def test_add_remove_tags(self): self.add_tag('tag1') self.assert_tags_are('tag1') self.add_tag('tag2') self.assert_tags_are('tag1', 'tag2') self.add_tag('tag3') self.assert_tags_are('tag1', 'tag2', 'tag3') self.remove_tag('tag3') self.assert_tags_are('tag1', 'tag2') self.remove_tag('tag2') self.assert_tags_are('tag1') self.remove_tag('tag1') self.assertEqual(len(self.state.tags), 0) def test_query_and_tags1(self): self.update({'query': 'hahaha'}) self.add_tag('tag1') self.assertEquals(self.state.query, 'hahaha') self.assert_tags_are('tag1') self.update({'reset_query': True}) self.assertEquals(self.state.query, None) self.assert_tags_are('tag1') def test_start_over(self): self.update({'query': 'hahaha'}) self.add_tag('tag1') self.update({'start_over': True}) self.assertEquals(self.state.query, None) self.assertEquals(self.state.tags, None) def test_auto_reset_sort(self): self.update({'sort': 'age-asc'}) self.assertEquals(self.state.sort, 'age-asc') self.update({}) self.assertEquals(self.state.sort, DEFAULT_SORT)