diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2012-12-13 14:34:25 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2012-12-13 14:34:25 +0100 |
commit | a9d22e8e9cbe51ae353b4e2f68ff635e9cf6d844 (patch) | |
tree | 93b89c352c632360f4d056445c983615709f9b58 | |
parent | e8ff971ed0089e343c5653672707307b89ad6e63 (diff) | |
download | hyperkitty-a9d22e8e9cbe51ae353b4e2f68ff635e9cf6d844.tar.gz hyperkitty-a9d22e8e9cbe51ae353b4e2f68ff635e9cf6d844.tar.xz hyperkitty-a9d22e8e9cbe51ae353b4e2f68ff635e9cf6d844.zip |
Fix the archives view for december
-rw-r--r-- | hyperkitty/lib/__init__.py | 16 | ||||
-rw-r--r-- | hyperkitty/tests/__init__.py | 1 | ||||
-rw-r--r-- | hyperkitty/tests/test_lib.py | 47 | ||||
-rw-r--r-- | hyperkitty/tests/test_views.py | 37 | ||||
-rw-r--r-- | hyperkitty/tests_conf/settings_tests.py | 1 | ||||
-rw-r--r-- | hyperkitty/views/list.py | 51 |
6 files changed, 115 insertions, 38 deletions
diff --git a/hyperkitty/lib/__init__.py b/hyperkitty/lib/__init__.py index b260c3a..52b6bdc 100644 --- a/hyperkitty/lib/__init__.py +++ b/hyperkitty/lib/__init__.py @@ -70,3 +70,19 @@ def stripped_subject(mlist, subject): if subject.lower().startswith("[%s] " % list_name.lower()): subject = subject[len(list_name)+3 : ] return subject + + +def get_display_dates(year, month, day): + if day is None: + start_day = 1 + else: + start_day = int(day) + begin_date = datetime.datetime(int(year), int(month), start_day) + + if day is None: + end_date = begin_date + datetime.timedelta(days=32) + end_date = end_date.replace(day=1) + else: + end_date = begin_date + datetime.timedelta(days=1) + + return begin_date, end_date diff --git a/hyperkitty/tests/__init__.py b/hyperkitty/tests/__init__.py index f3ee25f..87e8c60 100644 --- a/hyperkitty/tests/__init__.py +++ b/hyperkitty/tests/__init__.py @@ -23,3 +23,4 @@ from hyperkitty.tests.test_views import * from hyperkitty.tests.test_models import * from hyperkitty.tests.test_forms import * from hyperkitty.tests.test_templatetags import * +from hyperkitty.tests.test_lib import * diff --git a/hyperkitty/tests/test_lib.py b/hyperkitty/tests/test_lib.py new file mode 100644 index 0000000..fb560ae --- /dev/null +++ b/hyperkitty/tests/test_lib.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 1998-2012 by the Free Software Foundation, Inc. +# +# This file is part of HyperKitty. +# +# HyperKitty is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# HyperKitty is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# HyperKitty. If not, see <http://www.gnu.org/licenses/>. +# +# Author: Aamir Khan <syst3m.w0rm@gmail.com> +# + +import datetime + +from django.test import TestCase + +from hyperkitty.lib import get_display_dates + + +class GetDisplayDatesTestCase(TestCase): + + def test_month(self): + begin_date, end_date = get_display_dates('2012', '6', None) + self.assertEqual(begin_date, datetime.datetime(2012, 6, 1)) + self.assertEqual(end_date, datetime.datetime(2012, 7, 1)) + + def test_month_december(self): + try: + begin_date, end_date = get_display_dates('2012', '12', None) + except ValueError, e: + self.fail(e) + self.assertEqual(begin_date, datetime.datetime(2012, 12, 1)) + self.assertEqual(end_date, datetime.datetime(2013, 1, 1)) + + def test_day(self): + begin_date, end_date = get_display_dates('2012', '4', '2') + self.assertEqual(begin_date, datetime.datetime(2012, 4, 2)) + self.assertEqual(end_date, datetime.datetime(2012, 4, 3)) diff --git a/hyperkitty/tests/test_views.py b/hyperkitty/tests/test_views.py index 13ad0d8..83e3e24 100644 --- a/hyperkitty/tests/test_views.py +++ b/hyperkitty/tests/test_views.py @@ -17,13 +17,21 @@ # HyperKitty. If not, see <http://www.gnu.org/licenses/>. # # Author: Aamir Khan <syst3m.w0rm@gmail.com> +# Author: Aurelien Bompard <abompard@fedoraproject.org> # +import datetime +import urllib + +from mock import Mock, patch + from django.test import TestCase -from django.test.client import Client +from django.test.client import Client, RequestFactory from django.contrib.auth.models import User from django.core.urlresolvers import reverse -import urllib + +#from hyperkitty.views.list import archives + class AccountViewsTestCase(TestCase): @@ -67,6 +75,7 @@ class AccountViewsTestCase(TestCase): class MessageViewsTestCase(TestCase): + def setUp(self): self.client = Client() @@ -80,3 +89,27 @@ class MessageViewsTestCase(TestCase): def test_unauth_vote(self): resp = self.client.post(reverse('message_vote', kwargs={'mlist_fqdn': 'list@list.com'}), {'vote': 1, 'hashid': 123, }) self.assertEqual(resp.status_code, 403) + + +from hyperkitty.views.list import archives + +class ListArchivesTestCase(TestCase): + + def setUp(self): +# self.store = Mock() +# self.store.get_threads.return_value = [] +# self.store.get_list.side_effect = lambda n: FakeList(n) +# defaults = {"kittystore.store": self.store} +# self.factory = RequestFactory(**defaults) + self.factory = RequestFactory() + + def test_no_date(self): + today = datetime.date.today() + request = self.factory.get("/archives") + response = archives(request, 'list@example.com') + final_url = reverse('archives_with_month', + kwargs={'mlist_fqdn': 'list@example.com', + 'year': today.year, + 'month': today.month, + }) + self.assertEqual(response["location"], final_url) diff --git a/hyperkitty/tests_conf/settings_tests.py b/hyperkitty/tests_conf/settings_tests.py index 8b6195e..efb0aed 100644 --- a/hyperkitty/tests_conf/settings_tests.py +++ b/hyperkitty/tests_conf/settings_tests.py @@ -39,6 +39,7 @@ INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', + 'django_gravatar', 'hyperkitty', ) diff --git a/hyperkitty/views/list.py b/hyperkitty/views/list.py index 8c3940c..fc029b0 100644 --- a/hyperkitty/views/list.py +++ b/hyperkitty/views/list.py @@ -25,8 +25,8 @@ import os import json import urllib import logging +import datetime from calendar import timegm -from datetime import datetime, timedelta from urlparse import urljoin from collections import namedtuple @@ -41,7 +41,7 @@ from django.contrib.auth.decorators import (login_required, user_passes_test) from hyperkitty.models import Rating, Tag -from hyperkitty.lib import get_months, get_store +from hyperkitty.lib import get_months, get_store, get_display_dates from forms import * @@ -53,39 +53,17 @@ if settings.USE_MOCKUPS: def archives(request, mlist_fqdn, year=None, month=None, day=None): - # No year/month: past 32 days - # year and month: find the 32 days for that month # @TODO : modify url.py to account for page number - end_date = None - if year or month or day: - try: - start_day = 1 - end_day = 1 - start_month = int(month) - end_month = int(month) + 1 - start_year = int(year) - end_year = int(year) - if day: - start_day = int(day) - end_day = start_day + 1 - end_month = start_month - if start_month == 12: - end_month = 1 - end_year = start_year + 1 - - begin_date = datetime(start_year, start_month, start_day) - end_date = datetime(end_year, end_month, end_day) - month_string = begin_date.strftime('%B %Y') - except ValueError, err: - print err - logger.error('Wrong format given for the date') - - if not end_date: - today = datetime.utcnow() - begin_date = datetime(today.year, today.month, 1) - end_date = datetime(today.year, today.month + 1, 1) - month_string = 'Past thirty days' + if year is None and month is None: + today = datetime.date.today() + return HttpResponseRedirect(reverse( + 'archives_with_month', kwargs={ + "mlist_fqdn": mlist_fqdn, + 'year': today.year, + 'month': today.month})) + + begin_date, end_date = get_display_dates(year, month, day) search_form = SearchForm(auto_id=False) t = loader.get_template('month_view.html') @@ -194,9 +172,10 @@ def list(request, mlist_fqdn=None): search_form = SearchForm(auto_id=False) # Get stats for last 30 days - today = datetime.utcnow() - end_date = datetime(today.year, today.month, today.day) - begin_date = end_date - timedelta(days=32) + today = datetime.datetime.utcnow() + # the upper boundary is excluded in the search, add one day + end_date = today + datetime.timedelta(days=1) + begin_date = end_date - datetime.timedelta(days=32) store = get_store(request) mlist = store.get_list(mlist_fqdn) |