# -*- coding: utf-8 -*-

# Import Python libs
from __future__ import absolute_import

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import skipIf, TestCase
from tests.support.mock import (
    NO_MOCK,
    NO_MOCK_REASON,
    MagicMock,
    patch)

# Import Salt Libs
import salt.modules.pkgng as pkgng


@skipIf(NO_MOCK, NO_MOCK_REASON)
class PkgNgTestCase(TestCase, LoaderModuleMockMixin):
    '''
    Test cases for salt.modules.pkgng
    '''

    @classmethod
    def setup_loader_modules(cls):
        return {
            pkgng: {
                '__salt__': {}
            }
        }

    def test_lock(self):
        '''
        Test pkgng.lock
        '''
        lock_cmd = MagicMock(return_value={
            'stdout': 'pkga-1.0\npkgb-2.0\n',
            'retcode': 0
        })
        with patch.dict(pkgng.__salt__, {'cmd.run_all': lock_cmd}):

            result = pkgng.lock('pkga')
            self.assertTrue(result)
            lock_cmd.assert_called_with(
                ['pkg', 'lock', '-y', '--quiet', '--show-locked', 'pkga'],
                output_loglevel='trace', python_shell=False
            )

            result = pkgng.lock('dummy')
            self.assertFalse(result)
            lock_cmd.assert_called_with(
                ['pkg', 'lock', '-y', '--quiet', '--show-locked', 'dummy'],
                output_loglevel='trace', python_shell=False
            )

    def test_unlock(self):
        '''
        Test pkgng.unlock
        '''
        unlock_cmd = MagicMock(return_value={
            'stdout': 'pkga-1.0\npkgb-2.0\n',
            'retcode': 0
        })
        with patch.dict(pkgng.__salt__, {'cmd.run_all': unlock_cmd}):

            result = pkgng.unlock('pkga')
            self.assertFalse(result)
            unlock_cmd.assert_called_with(
                ['pkg', 'unlock', '-y', '--quiet', '--show-locked', 'pkga'],
                output_loglevel='trace', python_shell=False
            )

            result = pkgng.unlock('dummy')
            self.assertTrue(result)
            unlock_cmd.assert_called_with(
                ['pkg', 'unlock', '-y', '--quiet', '--show-locked', 'dummy'],
                output_loglevel='trace', python_shell=False
            )

    def test_locked(self):
        '''
        Test pkgng.unlock
        '''
        lock_cmd = MagicMock(return_value={
            'stdout': 'pkga-1.0\npkgb-2.0\n',
            'retcode': 0
        })
        with patch.dict(pkgng.__salt__, {'cmd.run_all': lock_cmd}):

            result = pkgng.locked('pkga')
            self.assertTrue(result)
            lock_cmd.assert_called_with(
                ['pkg', 'lock', '-y', '--quiet', '--show-locked'],
                output_loglevel='trace', python_shell=False
            )

            result = pkgng.locked('dummy')
            self.assertFalse(result)
            lock_cmd.assert_called_with(
                ['pkg', 'lock', '-y', '--quiet', '--show-locked'],
                output_loglevel='trace', python_shell=False
            )
@@ -3050,28 +3050,659 @@
 on_shell=False%0A            )
+%0A%0A    def test_list_upgrades(self):%0A        '''%0A        Test pkgng.list_upgrades%0A        '''%0A        pkg_cmd = MagicMock(return_value=%7B%0A            'stdout': 'pkga-1.0 %3C (port has 1.1)%5Cnpkgb-2.0 %3C (port has 2.1)%5Cn',%0A            'retcode': 0%0A        %7D)%0A        with patch.dict(pkgng.__salt__, %7B'cmd.run_all': pkg_cmd%7D):%0A%0A            result = pkgng.list_upgrades()%0A            self.assertDictEqual(result, %7B'pkga': '1.1', 'pkgb': '2.1'%7D)%0A            pkg_cmd.assert_called_with(%0A                %5B'pkg', 'version', '--like', '%3C', '--verbose', '--quiet', '-R'%5D,%0A                output_loglevel='trace', python_shell=False%0A            )%0A

Add unit tests for pkgng.list_upgrades