def test_valid_command_unreadable_script_file(self, mock__file_access_ok):
        mock__file_access_ok.side_effect = validation.ValidationError("O_o")

        validator = vmtasks.ValidCommandValidator(param_name="p",
                                                  required=True)

        command = {"script_file": "foobar", "interpreter": "foo"}
        e = self.assertRaises(validation.ValidationError, validator.validate,
                              self.context, {"args": {
                                  "p": command
                              }}, None, None)
        self.assertEqual("O_o", e.message)
    def test_valid_command_fail_check_command_dict(self,
                                                   mock_check_command_dict):
        validator = vmtasks.ValidCommandValidator(param_name="p",
                                                  required=True)

        mock_check_command_dict.side_effect = validation.ValidationError(
            "foobar")
        e = self.assertRaises(validation.ValidationError, validator.validate,
                              {"args": {
                                  "p": {
                                      "foo": "bar"
                                  }
                              }}, self.context, None, None)
        self.assertEqual("foobar", e.message)
    def test_valid_command_local_path(self, mock__file_access_ok):
        mock__file_access_ok.side_effect = validation.ValidationError("")

        validator = vmtasks.ValidCommandValidator(param_name="p",
                                                  required=True)

        command = {"remote_path": "bar", "local_path": "foobar"}
        self.assertRaises(validation.ValidationError, validator.validate,
                          self.context, {"args": {
                              "p": command
                          }}, None, None)
        mock__file_access_ok.assert_called_once_with(filename="foobar",
                                                     mode=os.R_OK,
                                                     param_name="p",
                                                     required=True)