Esempio n. 1
0
    def test_install(self):
        """
        Test for Install composer dependencies for a directory.
        """

        # Test _valid_composer=False throws exception
        mock = MagicMock(return_value=False)
        with patch.object(composer, "_valid_composer", mock):
            self.assertRaises(CommandNotFoundError, composer.install, "d")

        # Test no directory specified throws exception
        mock = MagicMock(return_value=True)
        with patch.object(composer, "_valid_composer", mock):
            self.assertRaises(SaltInvocationError, composer.install, None)

        # Test `composer install` exit status != 0 throws exception
        mock = MagicMock(return_value=True)
        with patch.object(composer, "_valid_composer", mock):
            mock = MagicMock(return_value={"retcode": 1, "stderr": "A"})
            with patch.dict(composer.__salt__, {"cmd.run_all": mock}):
                self.assertRaises(CommandExecutionError, composer.install, "d")

        # Test success with quiet=True returns True
        mock = MagicMock(return_value=True)
        with patch.object(composer, "_valid_composer", mock):
            mock = MagicMock(return_value={"retcode": 0, "stderr": "A"})
            with patch.dict(composer.__salt__, {"cmd.run_all": mock}):
                self.assertTrue(
                    composer.install(
                        "dir",
                        None,
                        None,
                        None,
                        None,
                        None,
                        None,
                        None,
                        None,
                        None,
                        True,
                    ))

        # Test success with quiet=False returns object
        mock = MagicMock(return_value=True)
        with patch.object(composer, "_valid_composer", mock):
            rval = {"retcode": 0, "stderr": "A", "stdout": "B"}
            mock = MagicMock(return_value=rval)
            with patch.dict(composer.__salt__, {"cmd.run_all": mock}):
                self.assertEqual(composer.install("dir"), rval)
Esempio n. 2
0
    def test_install(self):
        '''
        Test for Install composer dependencies for a directory.
        '''

        # Test _valid_composer=False throws exception
        mock = MagicMock(return_value=False)
        with patch.object(composer, '_valid_composer', mock):
            self.assertRaises(CommandNotFoundError, composer.install, 'd')

        # Test no directory specified throws exception
        mock = MagicMock(return_value=True)
        with patch.object(composer, '_valid_composer', mock):
            self.assertRaises(SaltInvocationError, composer.install, None)

        # Test `composer install` exit status != 0 throws exception
        mock = MagicMock(return_value=True)
        with patch.object(composer, '_valid_composer', mock):
            mock = MagicMock(return_value={'retcode': 1, 'stderr': 'A'})
            with patch.dict(composer.__salt__, {'cmd.run_all': mock}):
                self.assertRaises(CommandExecutionError, composer.install, 'd')

        # Test success with quiet=True returns True
        mock = MagicMock(return_value=True)
        with patch.object(composer, '_valid_composer', mock):
            mock = MagicMock(return_value={'retcode': 0, 'stderr': 'A'})
            with patch.dict(composer.__salt__, {'cmd.run_all': mock}):
                self.assertTrue(composer.install('dir', None, None, None, None,
                                                 None, None, None, None, None,
                                                 True))

        # Test success with quiet=False returns object
        mock = MagicMock(return_value=True)
        with patch.object(composer, '_valid_composer', mock):
            rval = {'retcode': 0, 'stderr': 'A', 'stdout': 'B'}
            mock = MagicMock(return_value=rval)
            with patch.dict(composer.__salt__, {'cmd.run_all': mock}):
                self.assertEqual(composer.install('dir'), rval)
Esempio n. 3
0
    def test_install(self):
        '''
        Test for Install composer dependencies for a directory.
        '''
        mock = MagicMock(return_value=False)
        msg = "'composer.install' is not available. Couldn't find 'composer'."
        with patch.object(composer, '_valid_composer', mock):
            self.assertEqual(composer.install('dir'), msg)

        mock = MagicMock(return_value=True)
        msg = "'dir' is required for 'composer.install'"
        with patch.object(composer, '_valid_composer', mock):
            self.assertEqual(composer.install(None), msg)

        mock = MagicMock(return_value=True)
        with patch.object(composer, '_valid_composer', mock):
            mock = MagicMock(return_value={'retcode': 1, 'stderr': 'A'})
            with patch.dict(composer.__salt__, {'cmd.run_all': mock}):
                self.assertRaises(CommandExecutionError, composer.install, 'd')

        mock = MagicMock(return_value=True)
        with patch.object(composer, '_valid_composer', mock):
            mock = MagicMock(return_value={'retcode': 0, 'stderr': 'A'})
            with patch.dict(composer.__salt__, {'cmd.run_all': mock}):
                self.assertTrue(
                    composer.install('dir', None, None, None, None, None, None,
                                     None, None, None, True))

        mock = MagicMock(return_value=True)
        with patch.object(composer, '_valid_composer', mock):
            mock = MagicMock(return_value={
                'retcode': 0,
                'stderr': 'A',
                'stdout': 'B'
            })
            with patch.dict(composer.__salt__, {'cmd.run_all': mock}):
                self.assertEqual(composer.install('dir'), 'B')
Esempio n. 4
0
    def test_install(self):
        """
        Test for Install composer dependencies for a directory.
        """

        # Test _valid_composer=False throws exception
        mock = MagicMock(return_value=False)
        with patch.object(composer, "_valid_composer", mock):
            self.assertRaises(CommandNotFoundError, composer.install, "d")

        # Test no directory specified throws exception
        mock = MagicMock(return_value=True)
        with patch.object(composer, "_valid_composer", mock):
            self.assertRaises(SaltInvocationError, composer.install, None)

        # Test `composer install` exit status != 0 throws exception
        mock = MagicMock(return_value=True)
        with patch.object(composer, "_valid_composer", mock):
            mock = MagicMock(return_value={"retcode": 1, "stderr": "A"})
            with patch.dict(composer.__salt__, {"cmd.run_all": mock}):
                self.assertRaises(CommandExecutionError, composer.install, "d")

        # Test success with quiet=True returns True
        mock = MagicMock(return_value=True)
        with patch.object(composer, "_valid_composer", mock):
            mock = MagicMock(return_value={"retcode": 0, "stderr": "A"})
            with patch.dict(composer.__salt__, {"cmd.run_all": mock}):
                self.assertTrue(composer.install("dir", None, None, None, None, None, None, None, None, None, True))

        # Test success with quiet=False returns object
        mock = MagicMock(return_value=True)
        with patch.object(composer, "_valid_composer", mock):
            rval = {"retcode": 0, "stderr": "A", "stdout": "B"}
            mock = MagicMock(return_value=rval)
            with patch.dict(composer.__salt__, {"cmd.run_all": mock}):
                self.assertEqual(composer.install("dir"), rval)