Example #1
0
    def test_call_close_success(self, mock_device):
        """
        test_call_close_success - Test if the plugin junos plugin close a connection with the expected asserts
        """

        # Mocking
        mock_device.connected = False
        plugin = JUNOS(equipment_access=self.mock_equipment_access)
        plugin.remote_conn = mock_device

        # Close to a real test:
        close_response = plugin.close()

        # Asserts
        plugin.remote_conn.close.assert_called_once_with()
        self.assertTrue(close_response, True)
Example #2
0
    def test_call_ensure_privilege_level_success(self, mock_start_shell):
        """
        test_call_ensure_privilege_level_success

        Note: The shell run function expects an array as a return value,
        and ensure_privilege_level() parse it to ensure the privilege.
        """

        mock_start_shell.return_value.run.return_value = [
            False,
            u'cli -c "show cli authorization"\r\r\nCurrent user: \'root        \' class \'super-user\'\r'
        ]

        plugin = JUNOS(equipment_access=self.mock_equipment_access)

        # Mock connection
        plugin.remote_conn = MagicMock()
        plugin.remote_conn.connected.return_value = True

        result = plugin.ensure_privilege_level()
        self.assertTrue(result)