Exemplo n.º 1
0
 def test_valid(self):
     '''
     Tests the ``valid``-function.
     Note that mine functions defined as list are returned in dict format.
     Mine functions that do not exist in __salt__ are not returned.
     '''
     config_mine_functions = {
         'network.ip_addrs': [],
         'kernel': [{
             'mine_function': 'grains.get'
         }, 'kernel'],
         'fubar': [{
             'mine_function': 'does.not_exist'
         }],
     }
     with \
             patch.dict(mine.__salt__, {
                 'config.merge': MagicMock(return_value=config_mine_functions),
                 'network.ip_addrs': lambda: True,
                 'grains.get': lambda: True,
             }):
         self.assertEqual(mine.valid(), {
             'network.ip_addrs': [],
             'kernel': {
                 'grains.get': ['kernel']
             },
         })
Exemplo n.º 2
0
    def test_valid(self):
        """
        Tests the ``valid``-function.
        Note that mine functions defined as list are returned in dict format.
        Mine functions that do not exist in __salt__ are not returned.
        """
        config_mine_functions = {
            "network.ip_addrs": [],
            "kernel": [
                {"mine_function": "grains.get"},
                "kernel",
                {"os": "win32", "v": "2018"},
            ],
            "fubar": [{"mine_function": "does.not_exist"}],
        }
        with patch.dict(
            mine.__salt__,
            {
                "config.merge": MagicMock(return_value=config_mine_functions),
                "network.ip_addrs": lambda: True,
                "grains.get": lambda: True,
            },
        ):
            ret = mine.valid()
            # list cant be made to set "dict can't be hashed" and order changes
            self.assertIsInstance(ret["kernel"]["grains.get"], list)
            self.assertEqual(len(ret["kernel"]["grains.get"]), 3)
            for item in ("kernel", {"os": "win32"}, {"v": "2018"}):
                self.assertTrue(item in ret["kernel"]["grains.get"])
            ret["kernel"]["grains.get"] = None

            self.assertEqual(
                ret, {"network.ip_addrs": [], "kernel": {"grains.get": None}}
            )
Exemplo n.º 3
0
 def test_valid(self):
     """
     Tests the ``valid``-function.
     Note that mine functions defined as list are returned in dict format.
     Mine functions that do not exist in __salt__ are not returned.
     """
     config_mine_functions = {
         "network.ip_addrs": [],
         "kernel": [{"mine_function": "grains.get"}, "kernel"],
         "fubar": [{"mine_function": "does.not_exist"}],
     }
     with patch.dict(
         mine.__salt__,
         {
             "config.merge": MagicMock(return_value=config_mine_functions),
             "network.ip_addrs": lambda: True,
             "grains.get": lambda: True,
         },
     ):
         self.assertEqual(
             mine.valid(),
             {"network.ip_addrs": [], "kernel": {"grains.get": ["kernel"]}},
         )