Example #1
0
def test_installed():
    """
    Test to verify that the correct versions of composer
    dependencies are present.
    """
    name = "CURL"

    ret = {"name": name, "result": True, "comment": "", "changes": {}}

    mock = MagicMock(return_value=True)
    with patch.dict(composer.__salt__,
                    {"composer.did_composer_install": mock}):
        comt = "Composer already installed this directory"
        ret.update({"comment": comt})
        assert composer.installed(name, always_check=False) == ret

        with patch.dict(composer.__opts__, {"test": True}):
            comt = 'The state of "CURL" will be changed.'
            changes = {
                "new": "composer install will be run in CURL",
                "old": "composer install has been run in CURL",
            }
            ret.update({"comment": comt, "result": None, "changes": changes})
            assert composer.installed(name) == ret

        with patch.dict(composer.__opts__, {"test": False}):
            mock = MagicMock(side_effect=[SaltException, {}])
            with patch.dict(composer.__salt__, {"composer.install": mock}):
                comt = "Error executing composer in 'CURL': "
                ret.update({"comment": comt, "result": False, "changes": {}})
                assert composer.installed(name) == ret

                comt = "Composer install completed successfully, output silenced by quiet flag"
                ret.update({"comment": comt, "result": True})
                assert composer.installed(name, quiet=True) == ret
Example #2
0
    def test_installed(self):
        '''
        Test to verify that the correct versions of composer
        dependencies are present.
        '''
        name = 'CURL'

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

        mock = MagicMock(return_value=True)
        with patch.dict(composer.__salt__,
                        {'composer.did_composer_install': mock}):
            comt = ('Composer already installed this directory')
            ret.update({'comment': comt})
            self.assertDictEqual(composer.installed(name, always_check=False),
                                 ret)

            with patch.dict(composer.__opts__, {'test': True}):
                comt = ('The state of "CURL" will be changed.')
                changes = {
                    'new': 'composer install will be run in CURL',
                    'old': 'composer install has been run in CURL'
                }
                ret.update({
                    'comment': comt,
                    'result': None,
                    'changes': changes
                })
                self.assertDictEqual(composer.installed(name), ret)

            with patch.dict(composer.__opts__, {'test': False}):
                mock = MagicMock(side_effect=[SaltException, {}])
                with patch.dict(composer.__salt__, {'composer.install': mock}):
                    comt = ("Error executing composer in " "'CURL': ")
                    ret.update({
                        'comment': comt,
                        'result': False,
                        'changes': {}
                    })
                    self.assertDictEqual(composer.installed(name), ret)

                    comt = ('Composer install completed successfully,'
                            ' output silenced by quiet flag')
                    ret.update({'comment': comt, 'result': True})
                    self.assertDictEqual(composer.installed(name, quiet=True),
                                         ret)
Example #3
0
    def test_installed(self):
        '''
        Test to verify that the correct versions of composer
        dependencies are present.
        '''
        name = 'CURL'

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

        mock = MagicMock(return_value=True)
        with patch.dict(composer.__salt__,
                        {'composer.did_composer_install': mock}):
            comt = ('Composer already installed this directory')
            ret.update({'comment': comt})
            self.assertDictEqual(composer.installed(name, always_check=False),
                                 ret)

            with patch.dict(composer.__opts__, {'test': True}):
                comt = ('The state of "CURL" will be changed.')
                changes = {'new': 'composer install will be run in CURL',
                           'old': 'composer install has been run in CURL'}
                ret.update({'comment': comt, 'result': None,
                            'changes': changes})
                self.assertDictEqual(composer.installed(name), ret)

            with patch.dict(composer.__opts__, {'test': False}):
                mock = MagicMock(side_effect=[SaltException, {}])
                with patch.dict(composer.__salt__, {'composer.install': mock}):
                    comt = ("Error executing composer in "
                            "'CURL': ")
                    ret.update({'comment': comt, 'result': False,
                                'changes': {}})
                    self.assertDictEqual(composer.installed(name), ret)

                    comt = ('Composer install completed successfully,'
                            ' output silenced by quiet flag')
                    ret.update({'comment': comt, 'result': True})
                    self.assertDictEqual(composer.installed(name, quiet=True),
                                         ret)