Skip to content

Commit

Permalink
Fixed issue with dates in the future being accepted.
Browse files Browse the repository at this point in the history
  • Loading branch information
victor73 committed Feb 13, 2016
1 parent 7c84381 commit 22fb139
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
cutlass 0.11

* Ensuring dates specified on the Visit class do not happen in the
future.

- Victor <[email protected]> Sun, 14 Feb 2016 12:00:00 -0400

cutlass 0.10

* Sample supports optional name property.
Expand Down
6 changes: 5 additions & 1 deletion cutlass/Visit.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def date(self, date):
except ValueError:
raise ValueError("Invalid date. Must be in YYYY-MM-DD format.")

now = datetime.now()
if parsed > now:
raise ValueError("Visit date must be in the past, not the future.")

self.logger.debug("Date is in the correct format.")
self._date = date

Expand Down Expand Up @@ -286,7 +290,7 @@ def is_valid(self):

if 'by' not in self._links.keys():
valid = False

self.logger.debug("Valid? %s" % str(valid))

return valid
Expand Down
15 changes: 15 additions & 0 deletions tests/test_visit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest
import json
import sys
from datetime import date

from cutlass import iHMPSession
from cutlass import Visit
Expand Down Expand Up @@ -144,6 +145,20 @@ def testIllegalDate(self):
with self.assertRaises(Exception):
visit.date = "random"

def testIllegalFutureDate(self):
visit = session.create_visit()
success = False
today = date.today()
next_year = str(date(today.year + 1, today.month, today.day))

try:
visit.date = next_year
success = True
except:
pass

self.assertFalse(success, "Visit class rejects future dates.")

def testLegalDate(self):
visit = session.create_visit()
success = False
Expand Down

0 comments on commit 22fb139

Please sign in to comment.