Beispiel #1
0
 def check_diff_as_arg(self):
     """
     If diff is called with both pre_snapfile and post_snap_file then just process the diff and exit
     """
     if self.args.diff is True:
         if (self.args.pre_snapfile is not None
                 and os.path.isfile(self.args.pre_snapfile)) and (
                     self.args.post_snapfile is not None
                     and os.path.isfile(self.args.post_snapfile)):
             comp = Comparator()
             comp.compare_diff(self.args.pre_snapfile,
                               self.args.post_snapfile, None)
             sys.exit(1)
Beispiel #2
0
    def check_arguments(self):
        """
        checks combination of arguments given from command line and display help if correct
        set of combination is not given.
        :return: print message in command line, regarding correct usage of JSNAPy
        """
        ## only four test operation is permitted, if given anything apart from this, then it should print error message
        if (self.args.snap is False and self.args.snapcheck is False
                and self.args.check is False and self.args.diff is False
                and self.args.version is False):
            self.logger.error(
                colorama.Fore.RED +
                "Arguments not given correctly, Please refer help message",
                extra=self.log_detail)
            self.parser.print_help()
            sys.exit(1)

        if (((self.args.snap is True and
              (self.args.pre_snapfile is None or self.args.file is None)) or
             (self.args.snapcheck is True and self.args.file is None) or
             (self.args.check is True and self.args.file is None)) and
            (self.args.testfiles is None or self.args.hostname is None)):
            self.logger.error(
                colorama.Fore.RED +
                "Arguments not given correctly, Please refer help message",
                extra=self.log_detail)
            self.parser.print_help()
            sys.exit(1)
        if self.args.diff is True:
            if (self.args.pre_snapfile is not None
                    and os.path.isfile(self.args.pre_snapfile)) and (
                        self.args.post_snapfile is not None
                        and os.path.isfile(self.args.post_snapfile)):
                comp = Comparator()
                comp.compare_diff(self.args.pre_snapfile,
                                  self.args.post_snapfile, None)
                sys.exit(1)
            else:
                if (self.args.file is None) and (self.args.testfiles is None or
                                                 self.args.hostname is None):
                    self.parser.print_help()
                    sys.exit(1)
Beispiel #3
0
    def check_arguments(self):
        """
        checks combination of arguments given from command line and display help if correct
        set of combination is not given.
        :return: print message in command line, regarding correct usage of JSNAPy
        """
        ## only four test operation is permitted, if given anything apart from this, then it should print error message
        if (self.args.snap is False and self.args.snapcheck is False and self.args.check is False and self.args.diff is False and self.args.version is False):
            self.logger.error(colorama.Fore.RED +
                              "Arguments not given correctly, Please refer help message", extra=self.log_detail)
            self.parser.print_help()
            sys.exit(1)

        if(((self.args.snap is True and (self.args.pre_snapfile is None or self.args.file is None)) or
            (self.args.snapcheck is True and self.args.file is None) or
            (self.args.check is True and self.args.file is None)) and 
            (self.args.testfiles is None or self.args.hostname is None)
           ):
            self.logger.error(colorama.Fore.RED +
                              "Arguments not given correctly, Please refer help message", extra=self.log_detail)
            self.parser.print_help()
            sys.exit(1)
        if self.args.diff is True:
            if (self.args.pre_snapfile is not None and os.path.isfile(self.args.pre_snapfile)) and (
                    self.args.post_snapfile is not None and os.path.isfile(self.args.post_snapfile)):
                comp = Comparator()
                comp.compare_diff(
                    self.args.pre_snapfile,
                    self.args.post_snapfile,
                    None)
                sys.exit(1)
            else:
                if (self.args.file is None) and (
                    self.args.testfiles is None or self.args.hostname is None):
                    self.parser.print_help()
                    sys.exit(1)
Beispiel #4
0
 def test_compare_diff_pre_post_file_not_present(self, mock_log):
     comp = Comparator()
     comp.compare_diff('pre_no_such_file', 'post_no_such_file', False)
     mock_log.assert_called()
Beispiel #5
0
 def test_compare_diff(self, mock_diff):
     comp = Comparator()
     comp.compare_diff('pre', 'pre', False)
     mock_diff.assert_called_with('pre', 'pre')