def test_show_low_sls(): """ Test to display the low data from a specific sls """ mock = MagicMock(side_effect=["A", None, None]) with patch.object(state, "_check_queue", mock): assert state.show_low_sls("foo") == "A" with patch.dict(state.__opts__, {"test": "A"}): mock = MagicMock(return_value={"test": True, "saltenv": None}) with patch.object(salt.utils.state, "get_sls_opts", mock): MockState.State.flag = True MockState.HighState.flag = True assert state.show_low_sls("foo") == 2 MockState.State.flag = False assert state.show_low_sls("foo") == [{"__id__": "ABC"}]
def test_show_low_sls(self): ''' Test to display the low data from a specific sls ''' mock = MagicMock(side_effect=["A", None, None]) with patch.object(state, '_check_queue', mock): self.assertEqual(state.show_low_sls("foo"), "A") with patch.dict(state.__opts__, {"test": "A"}): mock = MagicMock(return_value={'test': True}) with patch.object(state, '_get_opts', mock): MockState.State.flag = True MockState.HighState.flag = True self.assertEqual(state.show_low_sls("foo"), 2) MockState.State.flag = False self.assertListEqual(state.show_low_sls("foo"), [{'__id__': 'ABC'}])
def test_show_states(): """ Test to display the low data from a specific sls """ mock = MagicMock(side_effect=["A", None]) with patch.object(state, "_check_queue", mock): assert state.show_low_sls("foo") == "A" assert state.show_states("foo") == ["abc"]
def test_show_states_missing_sls(): """ Test state.show_states when a sls file defined in a top.sls file is missing """ msg = ["No matching sls found for 'cloud' in evn 'base'"] chunks_mock = MagicMock(side_effect=[msg]) mock = MagicMock(side_effect=["A", None]) with patch.object(state, "_check_queue", mock), patch( "salt.state.HighState.compile_low_chunks", chunks_mock ): assert state.show_low_sls("foo") == "A" assert state.show_states("foo") == [msg[0]]
def test_lock_saltenv(): """ Tests lock_saltenv in each function which accepts saltenv on the CLI """ lock_msg = "lock_saltenv is enabled, saltenv cannot be changed" empty_list_mock = MagicMock(return_value=[]) with patch.dict(state.__opts__, {"lock_saltenv": True}), patch.dict( state.__salt__, {"grains.get": empty_list_mock} ), patch.object(state, "running", empty_list_mock): # Test high with pytest.raises(CommandExecutionError, match=lock_msg): state.high([{"vim": {"pkg": ["installed"]}}], saltenv="base") # Test template with pytest.raises(CommandExecutionError, match=lock_msg): state.template("foo", saltenv="base") # Test template_str with pytest.raises(CommandExecutionError, match=lock_msg): state.template_str("foo", saltenv="base") # Test apply_ with SLS with pytest.raises(CommandExecutionError, match=lock_msg): state.apply_("foo", saltenv="base") # Test apply_ with Highstate with pytest.raises(CommandExecutionError, match=lock_msg): state.apply_(saltenv="base") # Test "test" with SLS with pytest.raises(CommandExecutionError, match=lock_msg): state.test("foo", saltenv="base") # Test "test" with Highstate with pytest.raises(CommandExecutionError, match=lock_msg): state.test(saltenv="base") # Test highstate with pytest.raises(CommandExecutionError, match=lock_msg): state.highstate(saltenv="base") # Test sls with pytest.raises(CommandExecutionError, match=lock_msg): state.sls("foo", saltenv="base") # Test top with pytest.raises(CommandExecutionError, match=lock_msg): state.top("foo.sls", saltenv="base") # Test show_highstate with pytest.raises(CommandExecutionError, match=lock_msg): state.show_highstate(saltenv="base") # Test show_lowstate with pytest.raises(CommandExecutionError, match=lock_msg): state.show_lowstate(saltenv="base") # Test sls_id with pytest.raises(CommandExecutionError, match=lock_msg): state.sls_id("foo", "bar", saltenv="base") # Test show_low_sls with pytest.raises(CommandExecutionError, match=lock_msg): state.show_low_sls("foo", saltenv="base") # Test show_sls with pytest.raises(CommandExecutionError, match=lock_msg): state.show_sls("foo", saltenv="base") # Test show_top with pytest.raises(CommandExecutionError, match=lock_msg): state.show_top(saltenv="base") # Test single with pytest.raises(CommandExecutionError, match=lock_msg): state.single("foo.bar", name="baz", saltenv="base") # Test pkg with pytest.raises(CommandExecutionError, match=lock_msg): state.pkg( "/tmp/salt_state.tgz", "760a9353810e36f6d81416366fc426dc", "md5", saltenv="base", )
def test_lock_saltenv(self): ''' Tests lock_saltenv in each function which accepts saltenv on the CLI ''' lock_msg = 'lock_saltenv is enabled, saltenv cannot be changed' empty_list_mock = MagicMock(return_value=[]) with patch.dict(state.__opts__, {'lock_saltenv': True}), \ patch.dict(state.__salt__, {'grains.get': empty_list_mock}), \ patch.object(state, 'running', empty_list_mock): # Test high with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.high( [{"vim": {"pkg": ["installed"]}}], saltenv='base') # Test template with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.template('foo', saltenv='base') # Test template_str with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.template_str('foo', saltenv='base') # Test apply_ with SLS with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.apply_('foo', saltenv='base') # Test apply_ with Highstate with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.apply_(saltenv='base') # Test highstate with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.highstate(saltenv='base') # Test sls with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.sls('foo', saltenv='base') # Test top with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.top('foo.sls', saltenv='base') # Test show_highstate with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.show_highstate(saltenv='base') # Test show_lowstate with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.show_lowstate(saltenv='base') # Test sls_id with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.sls_id('foo', 'bar', saltenv='base') # Test show_low_sls with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.show_low_sls('foo', saltenv='base') # Test show_sls with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.show_sls('foo', saltenv='base') # Test show_top with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.show_top(saltenv='base') # Test single with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.single('foo.bar', name='baz', saltenv='base') # Test pkg with self.assertRaisesRegex(CommandExecutionError, lock_msg): state.pkg( '/tmp/salt_state.tgz', '760a9353810e36f6d81416366fc426dc', 'md5', saltenv='base')