| 
									
										
										
										
											2020-12-05 00:16:07 +01:00
										 |  |  | #!/usr/bin/python3 | 
					
						
							|  |  |  | # -*- coding: utf-8 -*- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | iCalendar parser test (ical_parser) | 
					
						
							|  |  |  | Copyright by aceisace | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import arrow | 
					
						
							| 
									
										
										
										
											2020-05-15 22:40:30 +02:00
										 |  |  | import unittest | 
					
						
							| 
									
										
										
										
											2020-12-02 01:01:53 +01:00
										 |  |  | from urllib.request import urlopen | 
					
						
							| 
									
										
										
										
											2020-12-05 00:16:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | from inkycal.modules.ical_parser import iCalendar | 
					
						
							|  |  |  | from helper_functions import * | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-15 22:40:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-29 03:58:48 +02:00
										 |  |  | ical = iCalendar() | 
					
						
							| 
									
										
										
										
											2020-12-02 01:01:53 +01:00
										 |  |  | test_ical = 'https://calendar.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics' | 
					
						
							| 
									
										
										
										
											2020-05-15 22:40:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-16 08:15:17 +02:00
										 |  |  | class ical_parser_test(unittest.TestCase): | 
					
						
							| 
									
										
										
										
											2020-05-29 03:58:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_load_url(self): | 
					
						
							| 
									
										
										
										
											2020-12-02 01:01:53 +01:00
										 |  |  |     print('testing loading via URL...', end="") | 
					
						
							|  |  |  |     ical.load_url(test_ical) | 
					
						
							|  |  |  |     print('OK') | 
					
						
							| 
									
										
										
										
											2020-06-10 15:12:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-29 03:58:48 +02:00
										 |  |  |   def test_get_events(self): | 
					
						
							| 
									
										
										
										
											2020-12-02 01:01:53 +01:00
										 |  |  |     print('testing parsing of events...', end="") | 
					
						
							| 
									
										
										
										
											2020-05-29 03:58:48 +02:00
										 |  |  |     ical.get_events(arrow.now(), arrow.now().shift(weeks=30)) | 
					
						
							| 
									
										
										
										
											2020-12-02 01:01:53 +01:00
										 |  |  |     print('OK') | 
					
						
							| 
									
										
										
										
											2020-05-29 03:58:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_sorting(self): | 
					
						
							| 
									
										
										
										
											2020-12-02 01:01:53 +01:00
										 |  |  |     print('testing sorting of events...', end="") | 
					
						
							| 
									
										
										
										
											2020-05-29 03:58:48 +02:00
										 |  |  |     ical.sort() | 
					
						
							| 
									
										
										
										
											2020-12-02 01:01:53 +01:00
										 |  |  |     print('OK') | 
					
						
							| 
									
										
										
										
											2020-05-29 03:58:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_show_events(self): | 
					
						
							| 
									
										
										
										
											2020-12-02 01:01:53 +01:00
										 |  |  |     print('testing if events can be shown...', end="") | 
					
						
							| 
									
										
										
										
											2020-05-29 03:58:48 +02:00
										 |  |  |     ical.show_events() | 
					
						
							| 
									
										
										
										
											2020-12-02 01:01:53 +01:00
										 |  |  |     print('OK') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_laod_from_file(self): | 
					
						
							|  |  |  |     print('testing loading from file...', end="") | 
					
						
							|  |  |  |     dummy = str(urlopen(test_ical).read().decode()) | 
					
						
							|  |  |  |     with open('dummy.ical', mode="w") as file: | 
					
						
							|  |  |  |       file.write(dummy) | 
					
						
							|  |  |  |     ical.load_from_file('dummy.ical') | 
					
						
							|  |  |  |     print('OK') | 
					
						
							|  |  |  |     os.remove('dummy.ical') | 
					
						
							| 
									
										
										
										
											2020-05-15 22:40:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							| 
									
										
										
										
											2020-12-05 00:16:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   logger = logging.getLogger() | 
					
						
							|  |  |  |   logger.level = logging.DEBUG | 
					
						
							|  |  |  |   logger.addHandler(logging.StreamHandler(sys.stdout)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-29 03:58:48 +02:00
										 |  |  |   unittest.main() |