Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #701 from akatsoulas/970749
Browse files Browse the repository at this point in the history
[fix bug 970749] Raise 404 error in month2number method if the input is ...
  • Loading branch information
akatsoulas committed Apr 14, 2014
2 parents 866a331 + 905b3d9 commit c1212d9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
25 changes: 25 additions & 0 deletions remo/base/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from datetime import datetime

import mock
from nose.tools import eq_

from remo.base.tests import RemoTestCase
from remo.base.utils import month2number
from remo.profiles.tests import UserFactory
from remo.reports.tests import NGReportFactory


class TestBaseUtils(RemoTestCase):
"""Tests for the utilities in base app."""

@mock.patch('remo.base.utils.month2number', wraps=month2number)
def test_month2number(self, mocked_month2number):
user = UserFactory.create(groups='Rep')
report_date = datetime(year=2014, month=4, day=1).date()
NGReportFactory.create(user=user, report_date=report_date)
reports_url = ('/reports/rep/' + user.userprofile.display_name +
'/?year=2014&month=Apri')
response = self.client.get(reports_url, follow=True)
mocked_month2number.assert_called_once_with(u'Apri')
eq_(response.status_code, 404)
self.assertTemplateUsed(response, '404.html')
6 changes: 5 additions & 1 deletion remo/base/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.contrib.auth.models import Group, Permission
from django.core.exceptions import ValidationError
from django.db.models import get_app, get_models
from django.http import Http404
from django.utils import timezone


Expand Down Expand Up @@ -71,7 +72,10 @@ def latest_object_or_none(model_class, field_name=None):

def month2number(month):
"""Convert to month name to number."""
return datetime.datetime.strptime(month, '%B').month
try:
return datetime.datetime.strptime(month, '%B').month
except ValueError:
raise Http404


def number2month(month, full_name=True):
Expand Down

0 comments on commit c1212d9

Please sign in to comment.