commit 4fa157d798f7bbc1ede6217e1ac5e4a55946510f
parent de08ce096e91aba22b1817e322b24106077a6401
Author: Matthias Balk <mbalk@mbalk.de>
Date: Fri, 5 Feb 2021 17:50:45 +0100
some tests added
Diffstat:
2 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,7 +1,12 @@
-setup: src/config.py
- virtualenv -p python3 env
+setup: env src/config.py
. env/bin/activate && pip install -r requirements-freeze.txt
src/config.py: src/config.tpl
if [ -f src/config.py ]; then cp src/config.py src/config.py~; fi
cp src/config.tpl src/config.py
+
+env:
+ virtualenv -p python3 env
+
+tests: setup
+ . env/bin/activate && src/tests.py
diff --git a/src/tests.py b/src/tests.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+
+# Copyright 2021 Matthias Balk
+#
+# This file is part of ya3 (yet another appointment application).
+#
+# ya3 is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
+#
+# ya3 is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with ya3. If not, see <http://www.gnu.org/licenses/>.
+
+import unittest
+from datetime import date, datetime
+
+import vobject
+
+import utils
+
+
+class TestEvent2String(unittest.TestCase):
+
+ def test_datetime(self):
+ cal = vobject.iCalendar()
+ evt = cal.add('vevent')
+ evt.add('dtstart').value = datetime(2021, 2, 6, 13, 30, 0)
+ evt.add('dtend').value = datetime(2021, 2, 6, 14, 30, 0)
+ evt.add('summary').value = 'we need to talk'
+ evt.add('location').value = 'room 1'
+
+ self.assertEqual('2021-02-06 13:30 - 14:30 we need to talk (room 1)',
+ utils.event2string(evt))
+
+ def test_date(self):
+ cal = vobject.iCalendar()
+ evt = cal.add('vevent')
+ evt.add('dtstart').value = date(2021, 2, 6)
+ evt.add('dtend').value = date(2021, 2, 7)
+ evt.add('summary').value = 'we need to talk all day'
+ evt.add('location').value = 'room 1'
+
+ self.assertEqual(
+ '2021-02-06 we need to talk all day (room 1)',
+ utils.event2string(evt))
+
+
+if __name__ == '__main__':
+ unittest.main()