Added tests for some formatting mechanisms.
This commit is contained in:
parent
7dad8ab54d
commit
32bae249db
30
tests.py
30
tests.py
@ -1,6 +1,7 @@
|
|||||||
import unittest
|
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 flask.ext.testing import TestCase
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class BaseTestCase(TestCase):
|
class BaseTestCase(TestCase):
|
||||||
@ -65,5 +66,32 @@ class TestLogin(BaseTestCase):
|
|||||||
response = self.client.get('/user_items')
|
response = self.client.get('/user_items')
|
||||||
self.assert200(response)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user