summaryrefslogtreecommitdiffstats
path: root/askbot/tests/search_state_tests.py
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-07-01 04:22:35 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-07-01 04:22:35 -0400
commita18560e89a80f0c7a55aa00d2976023abc39870a (patch)
tree00a956f62e281be692c843da00a49ffdf2a66f2a /askbot/tests/search_state_tests.py
parent65f2791b29c8c9fe5eb2681c0d8ab97e34e87301 (diff)
downloadaskbot-a18560e89a80f0c7a55aa00d2976023abc39870a.tar.gz
askbot-a18560e89a80f0c7a55aa00d2976023abc39870a.tar.bz2
askbot-a18560e89a80f0c7a55aa00d2976023abc39870a.zip
allowed adding tag, user and title parameters in the search query
Diffstat (limited to 'askbot/tests/search_state_tests.py')
-rw-r--r--askbot/tests/search_state_tests.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/askbot/tests/search_state_tests.py b/askbot/tests/search_state_tests.py
index b4b66a65..b944a2e4 100644
--- a/askbot/tests/search_state_tests.py
+++ b/askbot/tests/search_state_tests.py
@@ -1,6 +1,8 @@
+import re
+import unittest
from django.test import TestCase
from django.contrib.auth.models import AnonymousUser
-from askbot.search.state_manager import SearchState, ViewLog
+from askbot.search.state_manager import SearchState, ViewLog, parse_query
from askbot import const
DEFAULT_SORT = const.DEFAULT_POST_SORT_METHOD
@@ -65,3 +67,41 @@ class SearchStateTests(TestCase):
self.assertEquals(self.state.sort, 'age-asc')
self.update({})
self.assertEquals(self.state.sort, DEFAULT_SORT)
+class ParseQueryTests(unittest.TestCase):
+ def test_extract_users(self):
+ text = '@anna haha @"maria fernanda" @\'diego maradona\' hehe [user:karl marx] hoho user:\' george bush \''
+ parse_results = parse_query(text)
+ self.assertEquals(
+ sorted(parse_results['query_users']),
+ sorted(['anna', 'maria fernanda', 'diego maradona', 'karl marx', 'george bush'])
+ )
+ self.assertEquals(parse_results['stripped_query'], 'haha hehe hoho')
+
+ def test_extract_tags(self):
+ text = '#tag1 [tag: tag2] some text [tag3] query'
+ parse_results = parse_query(text)
+ self.assertEquals(set(parse_results['query_tags']), set(['tag1', 'tag2', 'tag3']))
+ self.assertEquals(parse_results['stripped_query'], 'some text query')
+
+ def test_extract_title1(self):
+ text = 'some text query [title: what is this?]'
+ parse_results = parse_query(text)
+ self.assertEquals(parse_results['query_title'], 'what is this?')
+ self.assertEquals(parse_results['stripped_query'], 'some text query')
+
+ def test_extract_title2(self):
+ text = 'some text query title:"what is this?"'
+ parse_results = parse_query(text)
+ self.assertEquals(parse_results['query_title'], 'what is this?')
+ self.assertEquals(parse_results['stripped_query'], 'some text query')
+
+ def test_extract_title3(self):
+ text = 'some text query title:\'what is this?\''
+ parse_results = parse_query(text)
+ self.assertEquals(parse_results['query_title'], 'what is this?')
+ self.assertEquals(parse_results['stripped_query'], 'some text query')
+
+ def test_negative_match(self):
+ text = 'some query text'
+ parse_results = parse_query(text)
+ self.assertEquals(parse_results['stripped_query'], 'some query text')