-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from django.core.exceptions import ValidationError | ||
from django.test import TestCase | ||
from pytest import raises | ||
|
||
from variable_resolution_date import parse | ||
|
||
|
||
class VariableResolutionDateFieldTest(TestCase): | ||
def test_it_can_parse_vrd_with_year(self): | ||
y, m, d = parse('1996') | ||
assert y == 1996 | ||
assert m is None | ||
assert d is None | ||
|
||
def test_it_can_parse_vrd_with_year_and_month(self): | ||
y, m, d = parse('1996-02') | ||
assert y == 1996 | ||
assert m == 2 | ||
assert d is None | ||
|
||
def test_it_can_parse_vrd_with_full_date(self): | ||
y, m, d = parse('1996-02-29') | ||
assert y == 1996 | ||
assert m == 2 | ||
assert d is 29 | ||
|
||
def test_it_cannot_parse_vrd_with_invalid_full_date(self): | ||
with raises(ValidationError) as ex: | ||
parse('1997-02-29') | ||
assert ex.value.messages == ['Must be a valid year, year-month, or year-month-day.'] | ||
|
||
def test_it_cannot_parse_vrd_with_extra_characters(self): | ||
with raises(ValidationError) as ex: | ||
parse('20001') | ||
assert ex.value.messages == ['Must be a valid year, year-month, or year-month-day.'] | ||
|
||
def test_it_cannot_parse_vrd_with_month_day(self): | ||
with raises(ValidationError) as ex: | ||
parse('02-03') | ||
assert ex.value.messages == ['Must be a valid year, year-month, or year-month-day.'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters