ungana

Client application that creates customized .ics files for ticket booking and event reservations
Info | Log | Files | Refs | README

test_args_parser.py (3310B)


      1 import unittest
      2 from unittest.mock import patch
      3 import argparse
      4 
      5 from ungana.cmd.args_parser import ArgsParser
      6 
      7 class TestArgsParser(unittest.TestCase):
      8 
      9     def setUp(self):
     10         self.args_parser = ArgsParser(cfg={"OBJ_STORES": []})
     11 
     12     def test_ensure_no_multiline_input_valid(self):
     13         result = self.args_parser._ensure_no_multiline_input("foo bar")
     14         self.assertEqual(result, "foo bar")
     15 
     16     def test_ensure_no_multiline_input_invalid(self):
     17         with self.assertRaises(argparse.ArgumentTypeError):
     18             self.args_parser._ensure_no_multiline_input("bad\nline")
     19 
     20     def test_process_contact_arg_with_params(self):
     21         value, params = self.args_parser._process_contact_arg("Go pher|ALTREP=mailto:gophers@go.org")
     22         self.assertEqual(value, "Go pher")
     23         self.assertEqual(params, {"ALTREP": "mailto:gophers@go.org"})
     24 
     25     def test_process_contact_arg_simple(self):
     26         value, params = self.args_parser._process_contact_arg("gophers@go.org")
     27         self.assertEqual(value, "gophers@go.org")
     28         self.assertEqual(params, {})
     29 
     30 
     31     @patch("sys.argv", ["prog", "create", "-s", "Gophers Meetup", "--start", "2025-09-06 10:00", "-d", "Gophers yearly meetup", "-l", "Gopher Confrence Hall", "-o", "events@gophers.com"])
     32     def test_parse_args_create_command(self):
     33         args = self.args_parser.parse_args()
     34         self.assertEqual(args.command, "create")
     35         self.assertEqual(args.summary, "Gophers Meetup")
     36         self.assertEqual(args.location, "Gopher Confrence Hall")
     37 
     38 
     39 
     40     @patch("sys.argv", ["prog", "edit","calendar.ics","-s", "Updated Gophers Meetup","-l", "Updated Conference Hall","-o", "neworganizer@gophers.com","--description", "Updated description"])
     41     def test_parse_args_edit_command(self):
     42         args = self.args_parser.parse_args()
     43         self.assertEqual(args.command, "edit")
     44         self.assertEqual(args.ics_file, "calendar.ics")
     45         self.assertEqual(args.summary, "Updated Gophers Meetup")
     46         self.assertEqual(args.location, "Updated Conference Hall")
     47         self.assertEqual(args.organizer, "neworganizer@gophers.com")
     48         self.assertEqual(args.description, "Updated description")
     49 
     50 
     51     @patch("sys.argv", ["prog", "edit", "calendar.ics","--host", "http://host.com","--venue", "http://venue.com","--presenter", "http://presenter.com"])
     52     def test_parse_args_edit_with_presenter_host_venue(self):
     53         args = self.args_parser.parse_args()
     54         self.assertEqual(args.host, "http://host.com")
     55         self.assertEqual(args.venue, "http://venue.com")
     56         self.assertEqual(args.presenter, "http://presenter.com")
     57 
     58 
     59     @patch("sys.argv", ["prog", "merge", "--input-dir", "./events", "--output", "merged.ics"])
     60     def test_parse_args_merge_command(self):
     61         args = self.args_parser.parse_args()
     62         self.assertEqual(args.command, "merge")
     63         self.assertEqual(args.input_dir, "./events")
     64         self.assertEqual(args.output, "merged.ics")
     65 
     66     @patch("sys.argv", ["prog", "merge"])
     67     def test_parse_args_merge_command_defaults(self):
     68         args = self.args_parser.parse_args()
     69         self.assertEqual(args.command, "merge")
     70         self.assertEqual(args.input_dir, "./events")
     71         self.assertEqual(args.output, "merged_events.ics")
     72 
     73 
     74 
     75 
     76 if __name__ == "__main__":
     77     unittest.main()