Add unittest for function first_of_month.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 26 Feb 2019 22:25:44 +0000 (23:25 +0100)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 26 Feb 2019 22:25:44 +0000 (23:25 +0100)
web/README
web/seepark_web_tests.py [new file with mode: 0644]

index 6a6ee1f..0dd0ca6 100644 (file)
@@ -40,3 +40,8 @@ https://gr33ndata.blogspot.com/2012/01/waitress-flask.html
 Generate documentation:
 cd doc
 SEEPARKINI=~/seewasser.ini make web
+
+---
+
+Execute unittests
+SEEPARKINI=~/seewasser.ini python3 -m unittest seepark_web_tests.py
diff --git a/web/seepark_web_tests.py b/web/seepark_web_tests.py
new file mode 100644 (file)
index 0000000..aedc7c7
--- /dev/null
@@ -0,0 +1,17 @@
+import datetime
+import unittest
+import seepark_web
+
+
+class SeeparkWebTestCase(unittest.TestCase):
+    def test_first_of_month(self):
+        for d in [1, 8, 25, 28]:
+            date_a = datetime.date(2019, 2, d)
+            date_b = seepark_web.first_of_month(date_a, 1)
+            self.assertEqual(date_b, datetime.date(2019, 3, 1))
+
+            date_b = seepark_web.first_of_month(date_a, -1)
+            self.assertEqual(date_b, datetime.date(2019, 1, 1))
+
+            date_b = seepark_web.first_of_month(date_a, 0)
+            self.assertEqual(date_b, datetime.date(2019, 2, 1))