def test_command_invoke_2(self): # Invoke the init command passing a path where the user cannot write. try: self.args.DIR = "/root/a_temp_dir" init_command = init(self.parser, self.args) self.assertRaises(CommandError, init_command.invoke) finally: if os.path.exists(self.args.DIR): os.removedirs(self.args.DIR)
def test_register_arguments(self): self.args.DIR = os.path.join(tempfile.gettempdir(), "a_fake_dir") init_command = init(self.parser, self.args) init_command.register_arguments(self.parser) # Make sure we do not forget about this test. self.assertEqual(2, len(self.parser.method_calls)) _, args, _ = self.parser.method_calls[0] self.assertIn("--non-interactive", args) _, args, _ = self.parser.method_calls[1] self.assertIn("DIR", args)
def test_update_data(self): # Make sure the template is updated accordingly with the provided data. self.args.DIR = self.temp_file.name init_command = init(self.parser, self.args) init_command.config.get = MagicMock() init_command.config.save = MagicMock() init_command.config.get.side_effect = ["a_job.json"] expected = { "jobfile": "a_job.json", } obtained = init_command._update_data() self.assertEqual(expected, obtained)
def test_command_invoke_0(self, mocked_edit_file): # Invoke the init command passing a path to a file. Should raise an # exception. self.args.DIR = self.temp_file.name init_command = init(self.parser, self.args) self.assertRaises(CommandError, init_command.invoke)