Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Fix search tests to include dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
davedash committed Mar 3, 2011
1 parent 126a25e commit 2d94191
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
38 changes: 23 additions & 15 deletions apps/search/tests/test_client.py
Expand Up @@ -36,26 +36,31 @@ def test_filter_date(self):
eq_(num_results(date_start=start, date_end=end), 5)

def test_filter_locale(self):
eq_(num_results(locale='en-US'), 29)
eq_(num_results(locale='de'), 1)
eq_(num_results(locale='unknown'), 1)
start = datetime.datetime(2010, 5, 27)
eq_(num_results(locale='en-US', date_start=start), 29)
eq_(num_results(locale='de', date_start=start), 1)
eq_(num_results(locale='unknown', date_start=start), 1)

def test_filter_platform(self):
eq_(num_results(platform='mac'), 31)
eq_(num_results(platform='palm'), 0)
start = datetime.datetime(2010, 5, 27)
eq_(num_results(platform='mac', date_start=start), 31)
eq_(num_results(platform='palm', date_start=start), 0)

def test_filter_product(self):
eq_(num_results(product=1), 31)
eq_(num_results(product=2), 0)
start = datetime.datetime(2010, 5, 27)
eq_(num_results(product=1, date_start=start), 31)
eq_(num_results(product=2, date_start=start), 0)

def test_filter_type(self):
eq_(num_results(type=input.OPINION_PRAISE.id), 17)
eq_(num_results(type=input.OPINION_ISSUE.id), 11)
eq_(num_results(type=input.OPINION_IDEA.id), 3)
start = datetime.datetime(2010, 5, 27)
eq_(num_results(type=input.OPINION_PRAISE.id, date_start=start), 17)
eq_(num_results(type=input.OPINION_ISSUE.id, date_start=start), 11)
eq_(num_results(type=input.OPINION_IDEA.id, date_start=start), 3)

def test_filter_version(self):
eq_(num_results(version='3.6.3'), 11)
eq_(num_results(version='3.6.4'), 16)
start = datetime.datetime(2010, 5, 27)
eq_(num_results(version='3.6.3', date_start=start), 11)
eq_(num_results(version='3.6.4', date_start=start), 16)

@patch('search.client.sphinx.SphinxClient.GetLastError')
def test_getlasterror(self, sphinx):
Expand All @@ -69,7 +74,8 @@ def test_meta_query(self):
assert 'day__avg__startup' in c.queries

def test_query(self):
eq_(num_results(), 31)
start = datetime.datetime(2010, 5, 27)
eq_(num_results(date_start=start), 31)

@patch('search.client.sphinx.SphinxClient.RunQueries')
def test_result_empty(self, rq):
Expand All @@ -91,11 +97,13 @@ def test_result_errors(self, rq):
self.assertRaises(SearchError, query)

def test_result_set(self):
rs = query()
start = datetime.datetime(2010, 5, 27)
rs = query(date_start=start)
assert isinstance(rs[0], Opinion)

def test_url_search(self):
eq_(num_results('url:*'), 7)
start = datetime.datetime(2010, 5, 27)
eq_(num_results('url:*', date_start=start), 7)


def test_date_filter_timezone():
Expand Down
5 changes: 3 additions & 2 deletions apps/search/tests/test_views.py
Expand Up @@ -284,15 +284,16 @@ def test_query(self):
url_base = 'http://%s/%s/%s/' % (s.domain, 'en-US',
settings.DEFAULT_CHANNEL)
eq_(doc('entry link').attr['href'],
'%s%s' % (url_base, 'opinion/32'))
'%s%s' % (url_base, 'opinion/29'))

def test_item_title(self):
"""
If we don't convert opinion type names to unicode, the world will end.
Bug 617204.
"""
r = self.client.get(reverse('search.feed', channel='beta'),
dict(product='firefox', version='--'))
dict(product='firefox', version='--',
date_start='2007-01-01'))
doc = self._pq(r)
# If we get a memory address, this is not a unicode string.
eq_(doc('entry title').text().find('object at 0x'), -1)
Expand Down

0 comments on commit 2d94191

Please sign in to comment.