def test_installed(self):
        name = 'coffee-script'

        ret = {'name': name,
               'result': False,
               'comment': '',
               'changes': {}}

        mock_err = MagicMock(side_effect=CommandExecutionError)
        mock_dict = MagicMock(return_value={name: {'version': '1.2'}})
        with patch.dict(npm.__salt__, {'npm.list': mock_err}):
            comt = ("Error looking up 'coffee-script': ")
            ret.update({'comment': comt})
            self.assertDictEqual(npm.installed(name), ret)

        with patch.dict(npm.__salt__, {'npm.list': mock_dict,
                                       'npm.install': mock_err}):
            with patch.dict(npm.__opts__, {'test': True}):
                comt = ("Package(s) 'coffee-script' "
                        "satisfied by coffee-script@1.2")
                ret.update({'comment': comt, 'result': True})
                self.assertDictEqual(npm.installed(name), ret)

            with patch.dict(npm.__opts__, {'test': False}):
                comt = ("Package(s) 'coffee-script' "
                        "satisfied by coffee-script@1.2")
                ret.update({'comment': comt, 'result': True})
                self.assertDictEqual(npm.installed(name), ret)

                comt = ("Error installing 'n, p, m': ")
                ret.update({'comment': comt, 'result': False})
                self.assertDictEqual(npm.installed(name, 'npm'), ret)

                with patch.dict(npm.__salt__, {'npm.install': mock_dict}):
                    comt = ("Package(s) 'n, p, m' successfully installed")
                    ret.update({'comment': comt, 'result': True,
                                'changes': {'new': ['n', 'p', 'm'], 'old': []}})
                    self.assertDictEqual(npm.installed(name, 'npm'), ret)

    # 'removed' function tests: 1
Test to verify that the given package is installed
dataset/ETHPy150Open saltstack/salt/tests/unit/states/npm_test.py/NpmTestCase.test_installed