def test_status(self): ''' Test to display puppet agent status ''' mock_lst = MagicMock(return_value=[]) with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}): mock = MagicMock(return_value=True) with patch.object(puppet, '_check_puppet', mock): mock = MagicMock(side_effect=[True]) with patch.object(os.path, 'isfile', mock): self.assertEqual(puppet.status(), "Administratively disabled") mock = MagicMock(side_effect=[False, True]) with patch.object(os.path, 'isfile', mock): with patch('salt.utils.fopen', mock_open(read_data="1")): mock = MagicMock(return_value=True) with patch.object(os, 'kill', mock): self.assertEqual(puppet.status(), "Applying a catalog") mock = MagicMock(side_effect=[False, True]) with patch.object(os.path, 'isfile', mock): with patch('salt.utils.fopen', mock_open()): mock = MagicMock(return_value=True) with patch.object(os, 'kill', mock): self.assertEqual(puppet.status(), "Stale lockfile") mock = MagicMock(side_effect=[False, False, True]) with patch.object(os.path, 'isfile', mock): with patch('salt.utils.fopen', mock_open(read_data="1")): mock = MagicMock(return_value=True) with patch.object(os, 'kill', mock): self.assertEqual(puppet.status(), "Idle daemon") mock = MagicMock(side_effect=[False, False, True]) with patch.object(os.path, 'isfile', mock): with patch('salt.utils.fopen', mock_open()): mock = MagicMock(return_value=True) with patch.object(os, 'kill', mock): self.assertEqual(puppet.status(), "Stale pidfile") mock = MagicMock(side_effect=[False, False, False]) with patch.object(os.path, 'isfile', mock): self.assertEqual(puppet.status(), "Stopped")
def test_status(): """ Test to display puppet agent status """ mock_lst = MagicMock(return_value=[]) with patch.dict(puppet.__salt__, {"cmd.run": mock_lst}): mock = MagicMock(side_effect=[True]) with patch.object(os.path, "isfile", mock): assert puppet.status() == "Administratively disabled" mock = MagicMock(side_effect=[False, True]) with patch.object(os.path, "isfile", mock): with patch("salt.utils.files.fopen", mock_open(read_data="1")): mock = MagicMock(return_value=True) with patch.object(os, "kill", mock): assert puppet.status() == "Applying a catalog" mock = MagicMock(side_effect=[False, True]) with patch.object(os.path, "isfile", mock): with patch("salt.utils.files.fopen", mock_open()): mock = MagicMock(return_value=True) with patch.object(os, "kill", mock): assert puppet.status() == "Stale lockfile" mock = MagicMock(side_effect=[False, False, True]) with patch.object(os.path, "isfile", mock): with patch("salt.utils.files.fopen", mock_open(read_data="1")): mock = MagicMock(return_value=True) with patch.object(os, "kill", mock): assert puppet.status() == "Idle daemon" mock = MagicMock(side_effect=[False, False, True]) with patch.object(os.path, "isfile", mock): with patch("salt.utils.files.fopen", mock_open()): mock = MagicMock(return_value=True) with patch.object(os, "kill", mock): assert puppet.status() == "Stale pidfile" mock = MagicMock(side_effect=[False, False, False]) with patch.object(os.path, "isfile", mock): assert puppet.status() == "Stopped"