| 
									
										
										
										
											2022-04-02 01:30:17 +02:00
										 |  |  | #!python3 | 
					
						
							| 
									
										
										
										
											2020-12-05 00:16:07 +01:00
										 |  |  | """
 | 
					
						
							|  |  |  | iCalendar parser test (ical_parser) | 
					
						
							|  |  |  | """
 | 
					
						
							| 
									
										
										
										
											2023-01-11 22:24:39 +01:00
										 |  |  | import logging | 
					
						
							| 
									
										
										
										
											2020-12-05 00:16:07 +01:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2023-01-11 22:24:39 +01:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-11 22:24:39 +01:00
										 |  |  | import arrow | 
					
						
							| 
									
										
										
										
											2020-12-05 00:16:07 +01:00
										 |  |  | from inkycal.modules.ical_parser import iCalendar | 
					
						
							| 
									
										
										
										
											2023-01-11 22:24:39 +01:00
										 |  |  | from inkycal.tests import Config | 
					
						
							| 
									
										
										
										
											2020-12-05 00:16:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-29 03:58:48 +02:00
										 |  |  | ical = iCalendar() | 
					
						
							| 
									
										
										
										
											2023-01-11 22:24:39 +01:00
										 |  |  | test_ical = Config.TEST_ICAL_URL | 
					
						
							| 
									
										
										
										
											2020-05-15 22:40:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-02 01:30:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-16 08:15:17 +02:00
										 |  |  | class ical_parser_test(unittest.TestCase): | 
					
						
							| 
									
										
										
										
											2020-05-29 03:58:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-02 01:30:17 +02:00
										 |  |  |     def test_load_url(self): | 
					
						
							|  |  |  |         print('testing loading via URL...', end="") | 
					
						
							|  |  |  |         ical.load_url(test_ical) | 
					
						
							|  |  |  |         print('OK') | 
					
						
							| 
									
										
										
										
											2020-05-15 22:40:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-02 01:30:17 +02:00
										 |  |  |     def test_get_events(self): | 
					
						
							|  |  |  |         print('testing parsing of events...', end="") | 
					
						
							|  |  |  |         ical.get_events(arrow.now(), arrow.now().shift(weeks=30)) | 
					
						
							|  |  |  |         print('OK') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_sorting(self): | 
					
						
							|  |  |  |         print('testing sorting of events...', end="") | 
					
						
							|  |  |  |         ical.sort() | 
					
						
							|  |  |  |         print('OK') | 
					
						
							| 
									
										
										
										
											2020-12-05 00:16:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-02 01:30:17 +02:00
										 |  |  |     def test_show_events(self): | 
					
						
							|  |  |  |         print('testing if events can be shown...', end="") | 
					
						
							|  |  |  |         ical.show_events() | 
					
						
							|  |  |  |         print('OK') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_laod_from_file(self): | 
					
						
							|  |  |  |         print('testing loading from file...', end="") | 
					
						
							| 
									
										
										
										
											2023-01-11 23:13:00 +01:00
										 |  |  |         dummy = str(urlopen(test_ical, timeout=10).read().decode()) | 
					
						
							| 
									
										
										
										
											2023-01-11 22:24:39 +01:00
										 |  |  |         with open('dummy.ical', mode="w", encoding="utf-8") as file: | 
					
						
							| 
									
										
										
										
											2022-04-02 01:30:17 +02:00
										 |  |  |             file.write(dummy) | 
					
						
							|  |  |  |         ical.load_from_file('dummy.ical') | 
					
						
							|  |  |  |         print('OK') | 
					
						
							|  |  |  |         os.remove('dummy.ical') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     logger = logging.getLogger() | 
					
						
							|  |  |  |     logger.level = logging.DEBUG | 
					
						
							|  |  |  |     logger.addHandler(logging.StreamHandler(sys.stdout)) | 
					
						
							| 
									
										
										
										
											2020-12-05 00:16:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-02 01:30:17 +02:00
										 |  |  |     unittest.main() |