Example #1
0
class TestCCExpirationDateField(unittest.TestCase):
    def setUp(self):
        self.field = CCExpirationDateField()

    def test_not_a_date(self):
        with self.assertRaises(ValidationError):
            self.field.clean('asdfasdf')

        with self.assertRaises(ValidationError):
            self.field.clean('12')

    def test_looks_like_a_date_but_isnt(self):
        with self.assertRaises(ValidationError):
            self.field.clean('50 / 2012')

    def test_expired_date(self):
        with patch.object(timezone, 'now') as mocked_timezone:
            mocked_timezone.return_value = datetime.datetime(day=1,
                                                             month=5,
                                                             year=2005)

            with self.assertRaises(ValidationError):
                self.field.clean('04 / 05')

            self.field.clean('05 / 05')

            with self.assertRaises(ValidationError):
                self.field.clean('10 / 04')

    def test_month_year(self):
        with patch.object(timezone, 'now') as mocked_timezone:
            mocked_timezone.return_value = datetime.datetime(day=1,
                                                             month=5,
                                                             year=2005)

            value = self.field.clean('03 / 2006')
            self.assertEqual(value.month, 3)
            self.assertEqual(value.year, 2006)
class TestCCExpirationDateField(unittest.TestCase):
    def setUp(self):
        self.field = CCExpirationDateField()

    def test_not_a_date(self):
        with self.assertRaises(ValidationError):
            self.field.clean("asdfasdf")

        with self.assertRaises(ValidationError):
            self.field.clean("12")

    def test_looks_like_a_date_but_isnt(self):
        with self.assertRaises(ValidationError):
            self.field.clean("50 / 2012")

    def test_expired_date(self):
        with patch.object(timezone, "now") as mocked_timezone:
            mocked_timezone.return_value = datetime.datetime(day=1, month=5, year=2005)

            with self.assertRaises(ValidationError):
                self.field.clean("04 / 05")

            self.field.clean("05 / 05")

            with self.assertRaises(ValidationError):
                self.field.clean("10 / 04")

    def test_month_year(self):
        with patch.object(timezone, "now") as mocked_timezone:
            mocked_timezone.return_value = datetime.datetime(day=1, month=5, year=2005)

            value = self.field.clean("03 / 2006")
            self.assertEqual(value.month, 3)
            self.assertEqual(value.year, 2006)
Example #3
0
 def setUp(self):
     self.field = CCExpirationDateField()
 def setUp(self):
     self.field = CCExpirationDateField()