def test_thread_summary_locmem_cache(self): cache.cache = LocMemCache('', {}) # Enable local caching thread = self.q.thread key = thread.get_summary_cache_key() self.assertTrue(thread.summary_html_cached()) self.assertIsNotNone(thread.get_cached_summary_html()) ### cache.cache.delete(key) # let's start over self.assertFalse(thread.summary_html_cached()) self.assertIsNone(thread.get_cached_summary_html()) context = { 'thread': thread, 'question': self.q, 'search_state': DummySearchState(), 'visitor': None } html = get_template('widgets/question_summary.html').render(Context(context)) filled_html = html.replace('<<<tag1>>>', SearchState.get_empty().add_tag('tag1').full_url())\ .replace('<<<tag2>>>', SearchState.get_empty().add_tag('tag2').full_url())\ .replace('<<<tag3>>>', SearchState.get_empty().add_tag('tag3').full_url()) self.assertEqual(filled_html, thread.get_summary_html(search_state=SearchState.get_empty())) self.assertTrue(thread.summary_html_cached()) self.assertEqual(html, thread.get_cached_summary_html()) ### cache.cache.set(key, 'Test <<<tag1>>>', timeout=100) self.assertTrue(thread.summary_html_cached()) self.assertEqual('Test <<<tag1>>>', thread.get_cached_summary_html()) self.assertEqual( 'Test %s' % SearchState.get_empty().add_tag('tag1').full_url(), thread.get_summary_html(search_state=SearchState.get_empty()) ) ### cache.cache.set(key, 'TestBBB <<<tag1>>>', timeout=100) self.assertTrue(thread.summary_html_cached()) self.assertEqual('TestBBB <<<tag1>>>', thread.get_cached_summary_html()) self.assertEqual( 'TestBBB %s' % SearchState.get_empty().add_tag('tag1').full_url(), thread.get_summary_html(search_state=SearchState.get_empty()) ) ### cache.cache.delete(key) thread.update_summary_html = lambda dummy: "Monkey-patched <<<tag2>>>" self.assertFalse(thread.summary_html_cached()) self.assertIsNone(thread.get_cached_summary_html()) self.assertEqual( 'Monkey-patched %s' % SearchState.get_empty().add_tag('tag2').full_url(), thread.get_summary_html(search_state=SearchState.get_empty()) )
def test_thread_summary_locmem_cache(self): cache.cache = LocMemCache('', {}) # Enable local caching thread = self.q.thread key = Thread.SUMMARY_CACHE_KEY_TPL % thread.id self.assertTrue(thread.summary_html_cached()) self.assertIsNotNone(thread.get_cached_summary_html()) ### cache.cache.delete(key) # let's start over self.assertFalse(thread.summary_html_cached()) self.assertIsNone(thread.get_cached_summary_html()) context = { 'thread': thread, 'question': self.q, 'search_state': DummySearchState(), } html = get_template('widgets/question_summary.html').render(context) filled_html = html.replace('<<<tag1>>>', SearchState.get_empty().add_tag('tag1').full_url())\ .replace('<<<tag2>>>', SearchState.get_empty().add_tag('tag2').full_url())\ .replace('<<<tag3>>>', SearchState.get_empty().add_tag('tag3').full_url()) self.assertEqual( filled_html, thread.get_summary_html(search_state=SearchState.get_empty())) self.assertTrue(thread.summary_html_cached()) self.assertEqual(html, thread.get_cached_summary_html()) ### cache.cache.set(key, 'Test <<<tag1>>>', timeout=100) self.assertTrue(thread.summary_html_cached()) self.assertEqual('Test <<<tag1>>>', thread.get_cached_summary_html()) self.assertEqual( 'Test %s' % SearchState.get_empty().add_tag('tag1').full_url(), thread.get_summary_html(search_state=SearchState.get_empty())) ### cache.cache.set(key, 'TestBBB <<<tag1>>>', timeout=100) self.assertTrue(thread.summary_html_cached()) self.assertEqual('TestBBB <<<tag1>>>', thread.get_cached_summary_html()) self.assertEqual( 'TestBBB %s' % SearchState.get_empty().add_tag('tag1').full_url(), thread.get_summary_html(search_state=SearchState.get_empty())) ### cache.cache.delete(key) thread.update_summary_html = lambda dummy: "Monkey-patched <<<tag2>>>" self.assertFalse(thread.summary_html_cached()) self.assertIsNone(thread.get_cached_summary_html()) self.assertEqual( 'Monkey-patched %s' % SearchState.get_empty().add_tag('tag2').full_url(), thread.get_summary_html(search_state=SearchState.get_empty()))
def test_thread_summary_locmem_cache(self): cache.cache = LocMemCache("", {}) # Enable local caching thread = self.q.thread key = thread.get_summary_cache_key() self.assertTrue(thread.summary_html_cached()) self.assertIsNotNone(thread.get_cached_summary_html()) ### cache.cache.delete(key) # let's start over self.assertFalse(thread.summary_html_cached()) self.assertIsNone(thread.get_cached_summary_html()) context = {"thread": thread, "question": self.q, "search_state": DummySearchState(), "visitor": None} html = get_template("widgets/question_summary.html").render(Context(context)) filled_html = ( html.replace("<<<tag1>>>", SearchState.get_empty().add_tag("tag1").full_url()) .replace("<<<tag2>>>", SearchState.get_empty().add_tag("tag2").full_url()) .replace("<<<tag3>>>", SearchState.get_empty().add_tag("tag3").full_url()) ) self.assertEqual(filled_html, thread.get_summary_html(search_state=SearchState.get_empty())) self.assertTrue(thread.summary_html_cached()) self.assertEqual(html, thread.get_cached_summary_html()) ### cache.cache.set(key, "Test <<<tag1>>>", timeout=100) self.assertTrue(thread.summary_html_cached()) self.assertEqual("Test <<<tag1>>>", thread.get_cached_summary_html()) self.assertEqual( "Test %s" % SearchState.get_empty().add_tag("tag1").full_url(), thread.get_summary_html(search_state=SearchState.get_empty()), ) ### cache.cache.set(key, "TestBBB <<<tag1>>>", timeout=100) self.assertTrue(thread.summary_html_cached()) self.assertEqual("TestBBB <<<tag1>>>", thread.get_cached_summary_html()) self.assertEqual( "TestBBB %s" % SearchState.get_empty().add_tag("tag1").full_url(), thread.get_summary_html(search_state=SearchState.get_empty()), ) ### cache.cache.delete(key) thread.update_summary_html = lambda dummy: "Monkey-patched <<<tag2>>>" self.assertFalse(thread.summary_html_cached()) self.assertIsNone(thread.get_cached_summary_html()) self.assertEqual( "Monkey-patched %s" % SearchState.get_empty().add_tag("tag2").full_url(), thread.get_summary_html(search_state=SearchState.get_empty()), )
def get_context_data(self, **kwargs): context = QuestionView.get_context_data(self, **kwargs) self.context_instance = self.get_context_object_instance(**kwargs) try: self.current_question = SpecificQuestion.objects.get(type__in=self.get_specific_types(), content_type=ContentType.objects.get_for_model(self.context_instance), object_id=self.context_instance.id, thread=Post.objects.get(id=kwargs["question_id"]).thread) except SpecificQuestion.DoesNotExist: raise Http404 search_state = SearchState.get_empty() search_state._questions_url = self.get_questions_url() context.update({ 'current_question': self.current_question, 'current_question_url': self.get_question_url(), 'form_answer_url': self.get_answer_url(), 'edit_question_url': self.get_edit_url(), 'search_state': search_state, 'disable_retag': True, }) return context
def get_context_data(self, **kwargs): context = QuestionView.get_context_data(self, **kwargs) self.context_instance = self.get_context_object_instance(**kwargs) try: self.current_question = SpecificQuestion.objects.get( type__in=self.get_specific_types(), content_type=ContentType.objects.get_for_model( self.context_instance), object_id=self.context_instance.id, thread=Post.objects.get(id=kwargs["question_id"]).thread) except SpecificQuestion.DoesNotExist: raise Http404 search_state = SearchState.get_empty() search_state._questions_url = self.get_questions_url() context.update({ 'current_question': self.current_question, 'current_question_url': self.get_question_url(), 'form_answer_url': self.get_answer_url(), 'edit_question_url': self.get_edit_url(), 'search_state': search_state, 'disable_retag': True, }) return context
def tag_widget(tag, **kwargs): kwargs['tag'] = tag kwargs.setdefault('html_tag', 'div') kwargs.setdefault('is_link', True) if kwargs.get('search_state') is None: kwargs['search_state'] = SearchState.get_empty() return kwargs
def test_run_adv_search_ANDing_tags(self): ss = SearchState.get_empty() qs, meta_data = Thread.objects.run_advanced_search( request_user=self.user, search_state=ss.add_tag('tag1')) self.assertEqual(2, qs.count()) qs, meta_data = Thread.objects.run_advanced_search( request_user=self.user, search_state=ss.add_tag('tag1').add_tag('tag3')) self.assertEqual(2, qs.count()) qs, meta_data = Thread.objects.run_advanced_search( request_user=self.user, search_state=ss.add_tag('tag1').add_tag('tag3').add_tag('tag6')) self.assertEqual(1, qs.count()) ss = SearchState(scope=None, sort=None, query="#tag3", tags='tag1, tag6', author=None, page=None, user_logged_in=None) qs, meta_data = Thread.objects.run_advanced_search( request_user=self.user, search_state=ss) self.assertEqual(1, qs.count())
def test_deep_copy_2(self): # Regression test: a special case of deepcopy() when `tags` list is empty, # there was a bug before where this empty list in original and copy pointed # to the same list object ss = SearchState.get_empty() ss2 = ss.deepcopy() self.assertFalse(ss.tags is ss2.tags) self.assertCountEqual(ss.tags, ss2.tags) self.assertCountEqual([], ss2.tags)
def test_deep_copy_2(self): # Regression test: a special case of deepcopy() when `tags` list is empty, # there was a bug before where this empty list in original and copy pointed # to the same list object ss = SearchState.get_empty() ss2 = ss.deepcopy() self.assertFalse(ss.tags is ss2.tags) self.assertItemsEqual(ss.tags, ss2.tags) self.assertItemsEqual([], ss2.tags)
def test_thread_caching_1(self): ss = SearchState.get_empty() qs, meta_data = Thread.objects.run_advanced_search(request_user=self.user, search_state=ss) qs = list(qs) for thread in qs: self.assertIsNone(getattr(thread, '_question_cache', None)) self.assertIsNone(getattr(thread, '_last_activity_by_cache', None)) post = Post.objects.get(post_type='question', thread=thread.id) self.assertEqual(post, thread._question_post()) self.assertEqual(post, thread._question_cache) self.assertTrue(thread._question_post() is thread._question_cache)
def test_thread_caching_1(self): ss = SearchState.get_empty() qs, meta_data = Thread.objects.run_advanced_search(request_user=self.user, search_state=ss) qs = list(qs) for thread in qs: self.assertIsNone(getattr(thread, "_question_cache", None)) self.assertIsNone(getattr(thread, "_last_activity_by_cache", None)) post = Post.objects.get(post_type="question", thread=thread.id) self.assertEqual(post, thread._question_post()) self.assertEqual(post, thread._question_cache) self.assertTrue(thread._question_post() is thread._question_cache)
def test_thread_summary_rendering_dummy_cache(self): cache.cache = DummyCache('', {}) # Disable caching ss = SearchState.get_empty() thread = self.q.thread test_html = thread.get_summary_html(search_state=ss) context = { 'thread': thread, 'question': thread._question_post(), 'search_state': ss, 'visitor': None } proper_html = get_template('widgets/question_summary.html').render( context) self.assertEqual(test_html, proper_html) # Make double-check that all tags are included self.assertTrue(ss.add_tag('tag1').full_url() in test_html) self.assertTrue(ss.add_tag('tag2').full_url() in test_html) self.assertTrue(ss.add_tag('tag3').full_url() in test_html) self.assertFalse(ss.add_tag('mini-mini').full_url() in test_html) # Make sure that title and body text are escaped properly. # This should be obvious at this point, if the above test passes, but why not be explicit # UPDATE: And voila, these tests catched double-escaping bug in template, where `<` was `&lt;` # And indeed, post.summary is escaped before saving, in parse_and_save() # UPDATE 2:Weird things happen with question summary (it's double escaped etc., really weird) so # let's just make sure that there are no tag placeholders left self.assertTrue( '<<<tag1>>> fake title' in proper_html) #self.assertTrue('<<<tag2>>> <<<tag3>>> cheating' in proper_html) self.assertFalse('<<<tag1>>>' in proper_html) self.assertFalse('<<<tag2>>>' in proper_html) self.assertFalse('<<<tag3>>>' in proper_html) ### ss = ss.add_tag('mini-mini') context['search_state'] = ss test_html = thread.get_summary_html(search_state=ss) proper_html = get_template('widgets/question_summary.html').render( context) self.assertEqual(test_html, proper_html) # Make double-check that all tags are included (along with `mini-mini` tag) self.assertTrue(ss.add_tag('tag1').full_url() in test_html) self.assertTrue(ss.add_tag('tag2').full_url() in test_html) self.assertTrue(ss.add_tag('tag3').full_url() in test_html)
def test_run_adv_search_ANDing_tags(self): ss = SearchState.get_empty() qs, meta_data = Thread.objects.run_advanced_search(request_user=self.user, search_state=ss.add_tag('tag1')) self.assertEqual(2, qs.count()) qs, meta_data = Thread.objects.run_advanced_search(request_user=self.user, search_state=ss.add_tag('tag1').add_tag('tag3')) self.assertEqual(2, qs.count()) qs, meta_data = Thread.objects.run_advanced_search(request_user=self.user, search_state=ss.add_tag('tag1').add_tag('tag3').add_tag('tag6')) self.assertEqual(1, qs.count()) ss = SearchState(scope=None, sort=None, query="#tag3", tags='tag1, tag6', author=None, page=None, user_logged_in=None) qs, meta_data = Thread.objects.run_advanced_search(request_user=self.user, search_state=ss) self.assertEqual(1, qs.count())
def test_thread_caching_2_precache_view_data_hack(self): ss = SearchState.get_empty() qs, meta_data = Thread.objects.run_advanced_search(request_user=self.user, search_state=ss) qs = list(qs) Thread.objects.precache_view_data_hack(threads=qs) for thread in qs: post = Post.objects.get(post_type='question', thread=thread.id) self.assertEqual(post.id, thread._question_cache.id) # Cannot compare models instances with deferred model instances self.assertEqual(post.id, thread._question_post().id) self.assertTrue(thread._question_post() is thread._question_cache) user = User.objects.get(id=thread.last_activity_by_id) self.assertEqual(user.id, thread._last_activity_by_cache.id) self.assertTrue(thread.last_activity_by is thread._last_activity_by_cache)
def test_thread_summary_rendering_dummy_cache(self): cache.cache = DummyCache('', {}) # Disable caching ss = SearchState.get_empty() thread = self.q.thread test_html = thread.get_summary_html(search_state=ss) context = { 'thread': thread, 'question': thread._question_post(), 'search_state': ss, 'visitor': None } proper_html = get_template('widgets/question_summary.html').render(context) self.assertEqual(test_html, proper_html) # Make double-check that all tags are included self.assertTrue(ss.add_tag('tag1').full_url() in test_html) self.assertTrue(ss.add_tag('tag2').full_url() in test_html) self.assertTrue(ss.add_tag('tag3').full_url() in test_html) self.assertFalse(ss.add_tag('mini-mini').full_url() in test_html) # Make sure that title and body text are escaped properly. # This should be obvious at this point, if the above test passes, but why not be explicit # UPDATE: And voila, these tests catched double-escaping bug in template, where `<` was `&lt;` # And indeed, post.summary is escaped before saving, in parse_and_save() # UPDATE 2:Weird things happen with question summary (it's double escaped etc., really weird) so # let's just make sure that there are no tag placeholders left self.assertTrue('<<<tag1>>> fake title' in proper_html) #self.assertTrue('<<<tag2>>> <<<tag3>>> cheating' in proper_html) self.assertFalse('<<<tag1>>>' in proper_html) self.assertFalse('<<<tag2>>>' in proper_html) self.assertFalse('<<<tag3>>>' in proper_html) ### ss = ss.add_tag('mini-mini') context['search_state'] = ss test_html = thread.get_summary_html(search_state=ss) proper_html = get_template('widgets/question_summary.html').render(context) self.assertEqual(test_html, proper_html) # Make double-check that all tags are included (along with `mini-mini` tag) self.assertTrue(ss.add_tag('tag1').full_url() in test_html) self.assertTrue(ss.add_tag('tag2').full_url() in test_html) self.assertTrue(ss.add_tag('tag3').full_url() in test_html)
def application_settings(request): """The context processor function""" # if not request.path.startswith('/' + settings.ASKBOT_URL): # #todo: this is a really ugly hack, will only work # #when askbot is installed not at the home page. # #this will not work for the # #heavy modders of askbot, because their custom pages # #will not receive the askbot settings in the context # #to solve this properly we should probably explicitly # #add settings to the context per page # return {} my_settings = askbot_settings.as_dict() my_settings['LANGUAGE_CODE'] = getattr(request, 'LANGUAGE_CODE', settings.LANGUAGE_CODE) my_settings['LANGUAGE_MODE'] = askbot.get_lang_mode() my_settings['MULTILINGUAL'] = askbot.is_multilingual() my_settings['LANGUAGES_DICT'] = dict(getattr(settings, 'LANGUAGES', [])) my_settings[ 'ALLOWED_UPLOAD_FILE_TYPES'] = settings.ASKBOT_ALLOWED_UPLOAD_FILE_TYPES my_settings['ASKBOT_URL'] = settings.ASKBOT_URL my_settings['STATIC_URL'] = settings.STATIC_URL my_settings['IP_MODERATION_ENABLED'] = getattr( settings, 'ASKBOT_IP_MODERATION_ENABLED', False) my_settings['USE_LOCAL_FONTS'] = getattr(settings, 'ASKBOT_USE_LOCAL_FONTS', False) my_settings['CSRF_COOKIE_NAME'] = settings.CSRF_COOKIE_NAME my_settings['DEBUG'] = settings.DEBUG my_settings['USING_RUNSERVER'] = 'runserver' in sys.argv my_settings['ASKBOT_VERSION'] = askbot.get_version() my_settings['LOGIN_URL'] = url_utils.get_login_url() my_settings['LOGOUT_URL'] = url_utils.get_logout_url() if my_settings['EDITOR_TYPE'] == 'tinymce': tinymce_plugins = settings.TINYMCE_DEFAULT_CONFIG.get('plugins', '').split(',') my_settings['TINYMCE_PLUGINS'] = [v.strip() for v in tinymce_plugins] my_settings[ 'TINYMCE_EDITOR_DESELECTOR'] = settings.TINYMCE_DEFAULT_CONFIG[ 'editor_deselector'] my_settings['TINYMCE_CONFIG_JSON'] = json.dumps( settings.TINYMCE_DEFAULT_CONFIG) else: my_settings['TINYMCE_PLUGINS'] = [] my_settings['TINYMCE_EDITOR_DESELECTOR'] = '' my_settings['LOGOUT_REDIRECT_URL'] = url_utils.get_logout_redirect_url() current_language = get_language() # for some languages we will start searching for shorter words if current_language == 'ja': # we need to open the search box and show info message about # the japanese lang search min_search_word_length = 1 else: min_search_word_length = my_settings['MIN_SEARCH_WORD_LENGTH'] need_scope_links = askbot_settings.ALL_SCOPE_ENABLED or \ askbot_settings.UNANSWERED_SCOPE_ENABLED or \ (request.user.is_authenticated and askbot_settings.FOLLOWED_SCOPE_ENABLED) context = { 'base_url': site_url(''), 'csrf_token': csrf.get_token(request), 'empty_search_state': SearchState.get_empty(), 'min_search_word_length': min_search_word_length, 'current_language_code': current_language, 'settings': my_settings, 'moderation_items': api.get_info_on_moderation_items(request.user), 'need_scope_links': need_scope_links, 'noscript_url': const.DEPENDENCY_URLS['noscript'], } use_askbot_login = '******' in settings.INSTALLED_APPS my_settings['USE_ASKBOT_LOGIN_SYSTEM'] = use_askbot_login if use_askbot_login and request.user.is_anonymous: from askbot.deps.django_authopenid import context as login_context context.update(login_context.login_context(request)) context['group_list'] = json.dumps(make_group_list()) if askbot_settings.EDITOR_TYPE == 'tinymce': from tinymce.widgets import TinyMCE context['tinymce'] = TinyMCE() return context
def test_run_adv_search_1(self): ss = SearchState.get_empty() qs, meta_data = Thread.objects.run_advanced_search( request_user=self.user, search_state=ss) self.assertEqual(4, qs.count())
def test_cannot_add_already_added_tag(self): ss = SearchState.get_empty().add_tag('double').add_tag('double') self.assertListEqual(['double'], ss.tags)
def proto_test_non_user_urls(self, status_code): """test all reader views thoroughly on non-crashiness (no correcteness tests here) """ self.try_url("sitemap") self.try_url("get_groups_list", status_code=status_code) # self.try_url( # 'individual_question_feed', # kwargs={'pk':'one-tag'}, # status_code=status_code) self.try_url("latest_questions_feed", status_code=status_code) self.try_url("latest_questions_feed", data={"tags": "one-tag"}, status_code=status_code) self.try_url("about", status_code=status_code, template="static_page.html") self.try_url("privacy", status_code=status_code, template="static_page.html") self.try_url("logout", template="authopenid/logout.html") # todo: test different tabs self.try_url("tags", status_code=status_code, template="tags.html") self.try_url("tags", status_code=status_code, data={"sort": "name"}, template="tags.html") self.try_url("tags", status_code=status_code, data={"sort": "used"}, template="tags.html") self.try_url("badges", status_code=status_code, template="badges.html") self.try_url( "answer_revisions", status_code=status_code, template="revisions.html", kwargs={"id": models.Post.objects.get_answers().order_by("id")[0].id}, ) # todo: test different sort methods and scopes self.try_url("questions", status_code=status_code, template="main_page.html") self.try_url( url_name=reverse("questions") + SearchState.get_empty().change_scope("unanswered").query_string(), plain_url_passed=True, status_code=status_code, template="main_page.html", ) self.try_url( url_name=reverse("questions") + SearchState.get_empty().change_scope("followed").query_string(), plain_url_passed=True, status_code=status_code, template="main_page.html", ) self.try_url( url_name=reverse("questions") + SearchState.get_empty().change_scope("unanswered").change_sort("age-desc").query_string(), plain_url_passed=True, status_code=status_code, template="main_page.html", ) self.try_url( url_name=reverse("questions") + SearchState.get_empty().change_scope("unanswered").change_sort("age-asc").query_string(), plain_url_passed=True, status_code=status_code, template="main_page.html", ) self.try_url( url_name=reverse("questions") + SearchState.get_empty().change_scope("unanswered").change_sort("activity-desc").query_string(), plain_url_passed=True, status_code=status_code, template="main_page.html", ) self.try_url( url_name=reverse("questions") + SearchState.get_empty().change_scope("unanswered").change_sort("activity-asc").query_string(), plain_url_passed=True, status_code=status_code, template="main_page.html", ) self.try_url( url_name=reverse("questions") + SearchState.get_empty().change_sort("answers-desc").query_string(), plain_url_passed=True, status_code=status_code, template="main_page.html", ) self.try_url( url_name=reverse("questions") + SearchState.get_empty().change_sort("answers-asc").query_string(), plain_url_passed=True, status_code=status_code, template="main_page.html", ) self.try_url( url_name=reverse("questions") + SearchState.get_empty().change_sort("votes-desc").query_string(), plain_url_passed=True, status_code=status_code, template="main_page.html", ) self.try_url( url_name=reverse("questions") + SearchState.get_empty().change_sort("votes-asc").query_string(), plain_url_passed=True, status_code=status_code, template="main_page.html", ) self.try_url( "question", status_code=status_code, kwargs={"id": 1}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way follow=True, template="question.html", ) self.try_url( "question", status_code=status_code, kwargs={"id": 2}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way follow=True, template="question.html", ) self.try_url( "question", status_code=status_code, kwargs={"id": 3}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way follow=True, template="question.html", ) self.try_url( "question_revisions", status_code=status_code, kwargs={"id": 40}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way template="revisions.html", ) self.try_url("users", status_code=status_code, template="users.html") # self.try_url( # 'widget_questions', # status_code = status_code, # data={'tags': 'tag-1-0'}, # template='question_widget.html', # ) # todo: really odd naming conventions for sort methods self.try_url("users", status_code=status_code, template="users.html", data={"sort": "reputation"}) self.try_url("users", status_code=status_code, template="users.html", data={"sort": "newest"}) self.try_url("users", status_code=status_code, template="users.html", data={"sort": "last"}) self.try_url("users", status_code=status_code, template="users.html", data={"sort": "user"}) self.try_url("users", status_code=status_code, template="users.html", data={"sort": "reputation", "page": 2}) self.try_url("users", status_code=status_code, template="users.html", data={"sort": "newest", "page": 2}) self.try_url("users", status_code=status_code, template="users.html", data={"sort": "last", "page": 2}) self.try_url("users", status_code=status_code, template="users.html", data={"sort": "user", "page": 2}) self.try_url("users", status_code=status_code, template="users.html", data={"sort": "reputation", "page": 1}) self.try_url("users", status_code=status_code, template="users.html", data={"sort": "newest", "page": 1}) self.try_url("users", status_code=status_code, template="users.html", data={"sort": "last", "page": 1}) self.try_url("users", status_code=status_code, template="users.html", data={"sort": "user", "page": 1}) self.try_url( "edit_user", template="authopenid/signin.html", kwargs={"id": 4}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way status_code=status_code, follow=True, ) self.try_url("faq", template="faq_static.html", status_code=status_code)
def proto_test_non_user_urls(self, status_code): """test all reader views thoroughly on non-crashiness (no correcteness tests here) """ self.try_url('sitemap') self.try_url( 'feeds', status_code=status_code, kwargs={'url':'rss'}) self.try_url( 'feeds', kwargs={'url':'rss'}, data={'tags':'one-tag'}, status_code=status_code) #self.try_url( # 'feeds', # kwargs={'url':'question'}, # status_code=status_code) self.try_url( 'about', status_code=status_code, template='static_page.html') self.try_url( 'privacy', status_code=status_code, template='static_page.html') self.try_url('logout', template='authopenid/logout.html') #todo: test different tabs self.try_url( 'tags', status_code=status_code, template='tags.html') self.try_url( 'tags', status_code=status_code, data={'sort':'name'}, template='tags.html') self.try_url( 'tags', status_code=status_code, data={'sort':'used'}, template='tags.html') self.try_url( 'badges', status_code=status_code, template='badges.html') self.try_url( 'answer_revisions', status_code=status_code, template='revisions.html', kwargs={'id': models.Post.objects.get_answers().order_by('id')[0].id} ) #todo: test different sort methods and scopes self.try_url( 'questions', status_code=status_code, template='main_page.html' ) self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_scope('unanswered').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html', ) self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_scope('favorite').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html' ) self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_scope('unanswered').change_sort('age-desc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html' ) self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_scope('unanswered').change_sort('age-asc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html' ) self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_scope('unanswered').change_sort('activity-desc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html' ) self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_scope('unanswered').change_sort('activity-asc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html' ) self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_sort('answers-desc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html' ) self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_sort('answers-asc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html' ) self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_sort('votes-desc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html' ) self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_sort('votes-asc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html' ) self.try_url( 'question', status_code=status_code, kwargs={'id':1}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way follow=True, template='question.html' ) self.try_url( 'question', status_code=status_code, kwargs={'id':2}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way follow=True, template='question.html' ) self.try_url( 'question', status_code=status_code, kwargs={'id':3}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way follow=True, template='question.html' ) self.try_url( 'question_revisions', status_code=status_code, kwargs={'id':40}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way template='revisions.html' ) self.try_url('users', status_code=status_code, template='users.html' ) self.try_url( 'widget_questions', status_code = status_code, data={'tags': 'tag-1-0'}, template='question_widget.html', ) #todo: really odd naming conventions for sort methods self.try_url( 'users', status_code=status_code, template='users.html', data={'sort':'reputation'}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort':'newest'}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort':'last'}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort':'user'}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort':'reputation', 'page':2}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort':'newest', 'page':2}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort':'last', 'page':2}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort':'user', 'page':2}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort':'reputation', 'page':1}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort':'newest', 'page':1}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort':'last', 'page':1}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort':'user', 'page':1}, ) self.try_url( 'edit_user', template='authopenid/signin.html', kwargs={'id':4}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way status_code=status_code, follow=True, ) self.try_url( 'faq', template='faq_static.html', status_code=status_code, )
def get_empty_search_state(unused): from askbot.search.state_manager import SearchState return SearchState.get_empty()
def application_settings(request): """The context processor function""" # if not request.path.startswith('/' + settings.ASKBOT_URL): # #todo: this is a really ugly hack, will only work # #when askbot is installed not at the home page. # #this will not work for the # #heavy modders of askbot, because their custom pages # #will not receive the askbot settings in the context # #to solve this properly we should probably explicitly # #add settings to the context per page # return {} my_settings = askbot_settings.as_dict() my_settings["LANGUAGE_CODE"] = getattr(request, "LANGUAGE_CODE", settings.LANGUAGE_CODE) my_settings["MULTILINGUAL"] = getattr(settings, "ASKBOT_MULTILINGUAL", False) my_settings["LANGUAGES_DICT"] = dict(getattr(settings, "LANGUAGES", [])) my_settings["ALLOWED_UPLOAD_FILE_TYPES"] = settings.ASKBOT_ALLOWED_UPLOAD_FILE_TYPES my_settings["ASKBOT_URL"] = settings.ASKBOT_URL my_settings["STATIC_URL"] = settings.STATIC_URL my_settings["IP_MODERATION_ENABLED"] = getattr(settings, "ASKBOT_IP_MODERATION_ENABLED", False) my_settings["USE_LOCAL_FONTS"] = getattr(settings, "ASKBOT_USE_LOCAL_FONTS", False) my_settings["CSRF_COOKIE_NAME"] = settings.CSRF_COOKIE_NAME my_settings["DEBUG"] = settings.DEBUG my_settings["USING_RUNSERVER"] = "runserver" in sys.argv my_settings["ASKBOT_VERSION"] = askbot.get_version() my_settings["LOGIN_URL"] = url_utils.get_login_url() my_settings["LOGOUT_URL"] = url_utils.get_logout_url() if my_settings["EDITOR_TYPE"] == "tinymce": tinymce_plugins = settings.TINYMCE_DEFAULT_CONFIG.get("plugins", "").split(",") my_settings["TINYMCE_PLUGINS"] = map(lambda v: v.strip(), tinymce_plugins) else: my_settings["TINYMCE_PLUGINS"] = [] my_settings["LOGOUT_REDIRECT_URL"] = url_utils.get_logout_redirect_url() current_language = get_language() # for some languages we will start searching for shorter words if current_language == "ja": # we need to open the search box and show info message about # the japanese lang search min_search_word_length = 1 else: min_search_word_length = my_settings["MIN_SEARCH_WORD_LENGTH"] need_scope_links = ( askbot_settings.ALL_SCOPE_ENABLED or askbot_settings.UNANSWERED_SCOPE_ENABLED or (request.user.is_authenticated() and askbot_settings.FOLLOWED_SCOPE_ENABLED) ) context = { "base_url": site_url(""), "csrf_token": get_or_create_csrf_token(request), "empty_search_state": SearchState.get_empty(), "min_search_word_length": min_search_word_length, "current_language_code": current_language, "settings": my_settings, "moderation_items": api.get_info_on_moderation_items(request.user), "need_scope_links": need_scope_links, "noscript_url": const.DEPENDENCY_URLS["noscript"], } use_askbot_login = "******" in settings.INSTALLED_APPS my_settings["USE_ASKBOT_LOGIN_SYSTEM"] = use_askbot_login if use_askbot_login and request.user.is_anonymous(): from askbot.deps.django_authopenid import context as login_context context.update(login_context.login_context(request)) if askbot_settings.GROUPS_ENABLED: # calculate context needed to list all the groups def _get_group_url(group): """calculates url to the group based on its id and name""" group_slug = slugify(group["name"]) return reverse("users_by_group", kwargs={"group_id": group["id"], "group_slug": group_slug}) # load id's and names of all groups global_group = models.Group.objects.get_global_group() groups = models.Group.objects.exclude_personal() groups = groups.exclude(id=global_group.id) groups_data = list(groups.values("id", "name")) # sort groups_data alphanumerically, but case-insensitive groups_data = sorted(groups_data, lambda x, y: cmp(x["name"].lower(), y["name"].lower())) # insert data for the global group at the first position groups_data.insert(0, {"id": global_group.id, "name": global_group.name}) # build group_list for the context group_list = list() for group in groups_data: link = _get_group_url(group) group_list.append({"name": group["name"], "link": link}) context["group_list"] = simplejson.dumps(group_list) return context
def test_run_adv_search_1(self): ss = SearchState.get_empty() qs, meta_data = Thread.objects.run_advanced_search(request_user=self.user, search_state=ss) self.assertEqual(4, qs.count())
def application_settings(request): """The context processor function""" if not request.path.startswith('/' + settings.ASKBOT_URL): #todo: this is a really ugly hack, will only work #when askbot is installed not at the home page. #this will not work for the #heavy modders of askbot, because their custom pages #will not receive the askbot settings in the context #to solve this properly we should probably explicitly #add settings to the context per page return {} my_settings = askbot_settings.as_dict() my_settings['LANGUAGE_CODE'] = getattr(request, 'LANGUAGE_CODE', settings.LANGUAGE_CODE) my_settings['MULTILINGUAL'] = getattr(settings, 'ASKBOT_MULTILINGUAL', False) my_settings['LANGUAGES_DICT'] = dict(getattr(settings, 'LANGUAGES', [])) my_settings['ALLOWED_UPLOAD_FILE_TYPES'] = \ settings.ASKBOT_ALLOWED_UPLOAD_FILE_TYPES my_settings['ASKBOT_URL'] = settings.ASKBOT_URL my_settings['STATIC_URL'] = settings.STATIC_URL my_settings['IP_MODERATION_ENABLED'] = getattr(settings, 'ASKBOT_IP_MODERATION_ENABLED', False) my_settings['ASKBOT_CSS_DEVEL'] = getattr( settings, 'ASKBOT_CSS_DEVEL', False ) my_settings['USE_LOCAL_FONTS'] = getattr( settings, 'ASKBOT_USE_LOCAL_FONTS', False ) my_settings['CSRF_COOKIE_NAME'] = settings.CSRF_COOKIE_NAME my_settings['DEBUG'] = settings.DEBUG my_settings['USING_RUNSERVER'] = 'runserver' in sys.argv my_settings['ASKBOT_VERSION'] = askbot.get_version() my_settings['LOGIN_URL'] = url_utils.get_login_url() my_settings['LOGOUT_URL'] = url_utils.get_logout_url() if my_settings['EDITOR_TYPE'] == 'tinymce': tinymce_plugins = settings.TINYMCE_DEFAULT_CONFIG.get('plugins', '').split(',') my_settings['TINYMCE_PLUGINS'] = map(lambda v: v.strip(), tinymce_plugins) else: my_settings['TINYMCE_PLUGINS'] = []; my_settings['LOGOUT_REDIRECT_URL'] = url_utils.get_logout_redirect_url() my_settings['USE_ASKBOT_LOGIN_SYSTEM'] = 'askbot.deps.django_authopenid' \ in settings.INSTALLED_APPS current_language = get_language() #for some languages we will start searching for shorter words if current_language == 'ja': #we need to open the search box and show info message about #the japanese lang search min_search_word_length = 1 else: min_search_word_length = my_settings['MIN_SEARCH_WORD_LENGTH'] need_scope_links = askbot_settings.ALL_SCOPE_ENABLED or \ askbot_settings.UNANSWERED_SCOPE_ENABLED or \ (request.user.is_authenticated() and askbot_settings.FOLLOWED_SCOPE_ENABLED) context = { 'base_url': site_url(''), 'empty_search_state': SearchState.get_empty(), 'min_search_word_length': min_search_word_length, 'current_language_code': current_language, 'settings': my_settings, 'skin': get_skin(), 'moderation_items': api.get_info_on_moderation_items(request.user), 'need_scope_links': need_scope_links, 'noscript_url': const.DEPENDENCY_URLS['noscript'], } if askbot_settings.GROUPS_ENABLED: #calculate context needed to list all the groups def _get_group_url(group): """calculates url to the group based on its id and name""" group_slug = slugify(group['name']) return reverse( 'users_by_group', kwargs={'group_id': group['id'], 'group_slug': group_slug} ) #load id's and names of all groups global_group = models.Group.objects.get_global_group() groups = models.Group.objects.exclude_personal() groups = groups.exclude(id=global_group.id) groups_data = list(groups.values('id', 'name')) #sort groups_data alphanumerically, but case-insensitive groups_data = sorted( groups_data, lambda x, y: cmp(x['name'].lower(), y['name'].lower()) ) #insert data for the global group at the first position groups_data.insert(0, {'id': global_group.id, 'name': global_group.name}) #build group_list for the context group_list = list() for group in groups_data: link = _get_group_url(group) group_list.append({'name': group['name'], 'link': link}) context['group_list'] = simplejson.dumps(group_list) return context
def proto_test_non_user_urls(self, status_code): """test all reader views thoroughly on non-crashiness (no correcteness tests here) """ self.try_url('sitemap') self.try_url('get_groups_list', status_code=status_code) #self.try_url( # 'individual_question_feed', # kwargs={'pk':'one-tag'}, # status_code=status_code) self.try_url('latest_questions_feed', status_code=status_code) self.try_url('latest_questions_feed', data={'tags': 'one-tag'}, status_code=status_code) self.try_url('about', status_code=status_code, template='static_page.html') self.try_url('privacy', status_code=status_code, template='static_page.html') self.try_url('logout', template='authopenid/logout.html') #todo: test different tabs self.try_url('tags', status_code=status_code, template='tags.html') self.try_url('tags', status_code=status_code, data={'sort': 'name'}, template='tags.html') self.try_url('tags', status_code=status_code, data={'sort': 'used'}, template='tags.html') self.try_url('badges', status_code=status_code, template='badges.html') self.try_url('answer_revisions', status_code=status_code, template='revisions.html', kwargs={ 'id': models.Post.objects.get_answers().order_by('id')[0].id }) #todo: test different sort methods and scopes self.try_url('questions', status_code=status_code, template='main_page.html') self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_scope('unanswered').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html', ) self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_scope('favorite').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html') self.try_url(url_name=reverse('questions') + SearchState.get_empty().change_scope( 'unanswered').change_sort('age-desc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html') self.try_url(url_name=reverse('questions') + SearchState.get_empty().change_scope( 'unanswered').change_sort('age-asc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html') self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_scope('unanswered').change_sort( 'activity-desc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html') self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_scope('unanswered').change_sort( 'activity-asc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html') self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_sort('answers-desc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html') self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_sort('answers-asc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html') self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_sort('votes-desc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html') self.try_url( url_name=reverse('questions') + SearchState.get_empty().change_sort('votes-asc').query_string(), plain_url_passed=True, status_code=status_code, template='main_page.html') self.try_url( 'question', status_code=status_code, kwargs={ 'id': 1 }, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way follow=True, template='question.html') self.try_url( 'question', status_code=status_code, kwargs={ 'id': 2 }, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way follow=True, template='question.html') self.try_url( 'question', status_code=status_code, kwargs={ 'id': 3 }, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way follow=True, template='question.html') self.try_url( 'question_revisions', status_code=status_code, kwargs={ 'id': 40 }, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way template='revisions.html') self.try_url('users', status_code=status_code, template='users.html') #self.try_url( # 'widget_questions', # status_code = status_code, # data={'tags': 'tag-1-0'}, # template='question_widget.html', # ) #todo: really odd naming conventions for sort methods self.try_url( 'users', status_code=status_code, template='users.html', data={'sort': 'reputation'}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort': 'newest'}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort': 'last'}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={'sort': 'user'}, ) self.try_url( 'users', status_code=status_code, template='users.html', data={ 'sort': 'reputation', 'page': 2 }, ) self.try_url( 'users', status_code=status_code, template='users.html', data={ 'sort': 'newest', 'page': 2 }, ) self.try_url( 'users', status_code=status_code, template='users.html', data={ 'sort': 'last', 'page': 2 }, ) self.try_url( 'users', status_code=status_code, template='users.html', data={ 'sort': 'user', 'page': 2 }, ) self.try_url( 'users', status_code=status_code, template='users.html', data={ 'sort': 'reputation', 'page': 1 }, ) self.try_url( 'users', status_code=status_code, template='users.html', data={ 'sort': 'newest', 'page': 1 }, ) self.try_url( 'users', status_code=status_code, template='users.html', data={ 'sort': 'last', 'page': 1 }, ) self.try_url( 'users', status_code=status_code, template='users.html', data={ 'sort': 'user', 'page': 1 }, ) self.try_url( 'edit_user', template='authopenid/signin.html', kwargs={ 'id': 4 }, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way status_code=status_code, follow=True, ) self.try_url( 'faq', template='faq_static.html', status_code=status_code, )