diff --git a/tests.py b/tests.py index 17b1c27..bce20fa 100644 --- a/tests.py +++ b/tests.py @@ -1,6 +1,7 @@ import unittest -from wanikaniburned import app, db, User +from wanikaniburned import app, db, User, datetime_format, parse_range from flask.ext.testing import TestCase +from datetime import datetime class BaseTestCase(TestCase): @@ -65,5 +66,32 @@ class TestLogin(BaseTestCase): response = self.client.get('/user_items') self.assert200(response) + +class TestFormats(unittest.TestCase): + + def test_custom_datetime_format(self): + test_time = datetime.min + output = datetime_format(test_time) + self.assertEqual(output, "01 January 0001 12:00AM") + + def test_parse_range_empty(self): + self.assertIsNone(parse_range("")) + + def test_parse_range_letters(self): + self.assertIsNone(parse_range("ab-st,z")) + + def test_parse_range_single_number(self): + self.assertEqual(parse_range("1"), [1]) + + def test_parse_range_two_with_dash(self): + self.assertEqual(parse_range("1-4"), [1, 2, 3, 4]) + + def test_parse_range_two_with_comma(self): + self.assertEqual(parse_range("1,2"), [1, 2]) + + def test_parse_range_dash_and_comma(self): + self.assertEqual(parse_range("1,4-6"), [1, 4, 5, 6]) + + if __name__ == '__main__': unittest.main()