Exemple #1
0
    def test_run_program(self, mock_class, mock_load, mock_info, mock_mem,
                         mock_proc, mock_post):
        """Function:  test_run_program

        Description:  Test run_program function.

        Arguments:

        """

        mock_class.ProgramLock.return_value = self.proglock
        mock_class.System.return_value = System()
        mock_load.return_value = self.cfg
        mock_info.return_value = {
            "servername": "Server_Name",
            "datetime": "2018-10-17 12:00:01"
        }
        mock_mem.return_value = {
            "tot_mem": 100000000,
            "mem_used": 80000000,
            "mem_per": 80
        }
        mock_proc.return_value = [{
            "pid": 100,
            "ppid": 10,
            "proc": "proc_name",
            "uss_mem": 20000000,
            "per_used": "%.2f" % 25.15
        }]
        mock_post.return_value = True

        self.assertFalse(server_usage.run_program(self.args))
    def test_mongo(self):
        """Function:  test_mongo

        Description:  Test inserting data into Mongo database.

        Arguments:

        """

        self.args_array.update({"-n": True, "-m": True})

        server_usage.run_program(self.args_array)

        coll = mongo_libs.crt_coll_inst(self.cfg, self.cfg.db, self.cfg.coll)
        coll.connect()

        self.assertTrue(coll.coll_cnt() == 1)
    def test_print_raw(self):
        """Function:  test_print_raw

        Description:  Test printing unformatted data.

        Arguments:

        """

        with gen_libs.no_std_out():
            self.assertFalse(server_usage.run_program(self.args_array))
    def test_no_print(self):
        """Function:  test_no_print

        Description:  Test standard out suppression.

        Arguments:

        """

        self.args_array["-n"] = True

        self.assertFalse(server_usage.run_program(self.args_array))
Exemple #5
0
    def test_programlock_fail(self, mock_class, mock_load, mock_lock):
        """Function:  test_programlock_fail

        Description:  Test ProgramLock fails to lock.

        Arguments:

        """

        mock_lock.side_effect = server_usage.gen_class.SingleInstanceException
        mock_load.return_value = self.cfg
        mock_class.return_value = System()

        with gen_libs.no_std_out():
            self.assertFalse(server_usage.run_program(self.args))