tests.py (2625B)
1 #!/usr/bin/env python3 2 3 # Copyright 2021 Matthias Balk 4 # 5 # This file is part of ya3 (yet another appointment application). 6 # 7 # ya3 is free software: you can redistribute it and/or modify it under the 8 # terms of the GNU Affero General Public License as published by the Free 9 # Software Foundation, either version 3 of the License, or (at your option) any 10 # later version. 11 # 12 # ya3 is distributed in the hope that it will be useful, but WITHOUT ANY 13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 14 # A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 15 # details. 16 # 17 # You should have received a copy of the GNU Affero General Public License 18 # along with ya3. If not, see <http://www.gnu.org/licenses/>. 19 20 import unittest 21 from datetime import date, datetime, timedelta 22 23 import vobject 24 25 import utils 26 27 28 class TestEvent2String(unittest.TestCase): 29 30 def test_datetime(self): 31 cal = vobject.iCalendar() 32 evt = cal.add('vevent') 33 evt.add('dtstart').value = datetime(2021, 2, 6, 13, 30, 0) 34 evt.add('dtend').value = datetime(2021, 2, 6, 14, 30, 0) 35 evt.add('summary').value = 'we need to talk' 36 evt.add('location').value = 'room 1' 37 38 self.assertEqual('2021-02-06 13:30 - 14:30 we need to talk (room 1)', 39 utils.event2string(evt)) 40 41 def test_date(self): 42 cal = vobject.iCalendar() 43 evt = cal.add('vevent') 44 evt.add('dtstart').value = date(2021, 2, 6) 45 evt.add('dtend').value = date(2021, 2, 7) 46 evt.add('summary').value = 'we need to talk all day' 47 evt.add('location').value = 'room 1' 48 49 self.assertEqual( 50 '2021-02-06 we need to talk all day (room 1)', 51 utils.event2string(evt)) 52 53 54 class TestNormalize(unittest.TestCase): 55 56 def setUp(self): 57 cal = vobject.iCalendar() 58 self.evt = cal.add('vevent') 59 self.evt.add('dtstart').value = datetime(2021, 2, 6, 13, 30, 0) 60 61 def test_with_dtend(self): 62 self.evt.add('dtend').value = datetime(2021, 2, 6, 14, 30, 0) 63 norm = utils.normalize(self.evt) 64 self.assertEqual(datetime(2021, 2, 6, 14, 30, 0), norm.dtend.value) 65 66 def test_with_duration(self): 67 self.evt.add('duration').value = timedelta(hours=7) 68 norm = utils.normalize(self.evt) 69 self.assertEqual(datetime(2021, 2, 6, 20, 30, 0), norm.dtend.value) 70 71 def test_no_dtend_no_duration(self): 72 norm = utils.normalize(self.evt) 73 self.assertTrue(norm.dtstart.value < norm.dtend.value) 74 75 76 if __name__ == '__main__': 77 unittest.main()