Esempio n. 1
0
 def test_missing_command(self):
     with TemporaryDirectory() as tmpdirname:
         testargs = ["prog"]
         with self.assertRaises(SystemExit) as cm:
             with patch.object(sys, 'argv', testargs):
                 main()
         self.assertEqual(cm.exception.code, 1)
Esempio n. 2
0
 def test_validate_only_ok(self):
     with TemporaryDirectory() as tmpdirname:
         list_file = os.path.join(tmpdirname, 'resources.json')
         with open(list_file, 'w') as fp:
             fp.write(
                 '[{"id": "abc", "hostname": "localhost", "online": true}]')
         testargs = [
             "prog", "--validate-only", "--hostname", "localhost",
             "--resources", list_file, "echo", "$ID"
         ]
         with self.assertRaises(SystemExit) as cm:
             with patch.object(sys, 'argv', testargs):
                 main()
         self.assertEqual(cm.exception.code, 0)
Esempio n. 3
0
 def test_validate_only_fail(self):
     with TemporaryDirectory() as tmpdirname:
         list_file = os.path.join(tmpdirname, 'resources.json')
         with open(list_file, 'w') as fp:
             fp.write(
                 '[{"id": "abc", "hostname": "localhost", "online": true},'
                 ' {"id": "abc", "hostname": "localhost2", "online": true}]'
             )
         testargs = [
             "prog", "--validate-only", "--hostname", "localhost",
             "--resources", list_file, "echo", "$ID"
         ]
         with self.assertRaises(ValueError):
             with patch.object(sys, 'argv', testargs):
                 main()
Esempio n. 4
0
 def test_help(self):
     testargs = ["prog", "--help"]
     with self.assertRaises(SystemExit) as cm:
         with patch.object(sys, 'argv', testargs):
             main()
     self.assertEqual(cm.exception.code, 0)