Пример #1
0
    def test_installed(self):
        '''
        Test to verify that the given package is installed
        and is at the correct version.
        '''
        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 [email protected]")
                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 [email protected]")
                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)
Пример #2
0
    def test_installed(self):
        """
        Test to verify that the given package is installed
        and is at the correct version.
        """
        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 [email protected]"
                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 [email protected]"
                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)
Пример #3
0
    def test_installed(self):
        '''
        Test to verify that the given package is installed
        and is at the correct version.
        '''
        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 [email protected]")
                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 [email protected]")
                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)
Пример #4
0
def test_when_install_does_not_error_installed_should_be_true(fake_install):
    ret = npm.installed("fnord")
    assert ret["result"] is True