From db0d10f45354f313755189fae8f22c6f0289708b Mon Sep 17 00:00:00 2001 From: Rupesh Tare Date: Tue, 27 Jan 2015 18:46:07 +0530 Subject: [PATCH] implemented unit test cases for junos module --- tests/unit/modules/junos_test.py | 87 ++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tests/unit/modules/junos_test.py diff --git a/tests/unit/modules/junos_test.py b/tests/unit/modules/junos_test.py new file mode 100644 index 0000000000..4c5e488d34 --- /dev/null +++ b/tests/unit/modules/junos_test.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- +''' + :codeauthor: :email:`Rupesh Tare ` +''' + +# Import Salt Testing Libs +from salttesting import TestCase, skipIf +from salttesting.mock import ( + MagicMock, + patch, + NO_MOCK, + NO_MOCK_REASON +) + +# Import Salt Libs +from salt.modules import junos + +# Globals +junos.__opts__ = {} + + +@skipIf(NO_MOCK, NO_MOCK_REASON) +class JunosTestCase(TestCase): + ''' + Test cases for salt.modules.junos + ''' + def test_facts_refresh(self): + ''' + Test for Reload the facts dictionary from the device + ''' + mock = MagicMock(return_value='A') + with patch.dict(junos.__opts__, {'proxyobject': mock}): + self.assertTrue(junos.facts_refresh()) + + def test_set_hostname(self): + ''' + Test for set hostname + ''' + mock = MagicMock(return_value='A') + with patch.dict(junos.__opts__, {'proxyobject': mock}): + self.assertEqual(junos.set_hostname(), {'out': False}) + + with patch.object(junos, 'commit', return_value=None): + self.assertIsNone(junos.set_hostname('host', True)) + + self.assertDictEqual(junos.set_hostname('host', False), + {'msg': 'set system host-name host is queued', + 'out': True}) + + def test_commit(self): + ''' + Test for commit + ''' + mock = MagicMock(return_value='A') + with patch.dict(junos.__opts__, {'proxyobject': mock}): + self.assertDictEqual(junos.commit(), + {'message': 'Commit Successful.', + 'out': True}) + + def test_rollback(self): + ''' + Test for rollback + ''' + mock = MagicMock(return_value='A') + with patch.dict(junos.__opts__, {'proxyobject': mock}): + self.assertEqual(junos.rollback()['message'], + 'Rollback successful') + + def test_diff(self): + ''' + Test for diff + ''' + mock = MagicMock(return_value='A') + with patch.dict(junos.__opts__, {'proxyobject': mock}): + self.assertTrue(junos.diff()['out']) + + def test_ping(self): + ''' + Test for ping + ''' + mock = MagicMock(return_value='A') + with patch.dict(junos.__opts__, {'proxyobject': mock}): + self.assertIsNone(junos.ping()) + +if __name__ == '__main__': + from integration import run_tests + run_tests(JunosTestCase, needs_daemon=False)