Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Commit

Permalink
Future date for date_start and nothing for date_end would should not …
Browse files Browse the repository at this point in the history
…result in assertionerror. Bug 639863.
  • Loading branch information
Fred Wenzel committed Mar 9, 2011
1 parent 23b36a4 commit c47ee5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/search/forms.py
Expand Up @@ -101,6 +101,10 @@ def __init__(self, *args, **kwargs):
def clean(self):
cleaned = self.cleaned_data

# default date_end to today
if not self.cleaned_data.get('date_end'):
self.cleaned_data['date_end'] = date.today() + timedelta(days=1)

# Flip start and end if necessary.
if (cleaned.get('date_start') and cleaned.get('date_end') and
cleaned['date_start'] > cleaned['date_end']):
Expand Down
11 changes: 11 additions & 0 deletions apps/search/tests/test_views.py
Expand Up @@ -344,3 +344,14 @@ def test_error(self, get_results):
get_results.side_effect = SearchError()
r = self.get_request()
eq_(r.status_code, 500)

def test_date_flip_future_start(self):
"""
With date_start in the future, and date_end empty, ensure we do something
useful (default to end=today and flip the dates).
"""
dates = dict(
date_start=datetime.date.today() + datetime.timedelta(days=10),
date_end='')
r = self.get_request(**dates)
eq_(r.status_code, 200)

0 comments on commit c47ee5e

Please sign in to comment.