Example #1
0
    def test_list(self):
        '''
        Test if it list installed NPM packages.
        '''
        mock = MagicMock(return_value={'retcode': 1, 'stderr': 'error'})
        with patch.dict(npm.__salt__, {'cmd.run_all': mock}):
            self.assertRaises(CommandExecutionError, npm.list_, 'coffee-script')

        mock = MagicMock(return_value={'retcode': 0, 'stderr': 'error',
                                       'stdout': '{"salt": ["SALT"]}'})
        with patch.dict(npm.__salt__, {'cmd.run_all': mock}):
            mock_err = MagicMock(return_value={'dependencies': 'SALT'})
            with patch.object(json, 'loads', mock_err):
                self.assertEqual(npm.list_('coffee-script'), 'SALT')
Example #2
0
    def test_list(self):
        """
        Test if it list installed NPM packages.
        """
        mock = MagicMock(return_value={"retcode": 1, "stderr": "error"})
        with patch.dict(npm.__salt__, {"cmd.run_all": mock}):
            self.assertRaises(CommandExecutionError, npm.list_,
                              "coffee-script")

        mock = MagicMock(return_value={
            "retcode": 0,
            "stderr": "error",
            "stdout": '{"salt": ["SALT"]}',
        })
        with patch.dict(npm.__salt__, {"cmd.run_all": mock}):
            mock_err = MagicMock(return_value={"dependencies": "SALT"})
            with patch.object(salt.utils.json, "loads", mock_err):
                self.assertEqual(npm.list_("coffee-script"), "SALT")