Пример #1
0
    def test_startup_info(self):
        worker = self.Worker(app=self.app)
        worker.on_start()
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.DEBUG
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.INFO
        self.assertTrue(worker.startup_info())
        worker.autoscale = 13, 10
        self.assertTrue(worker.startup_info())

        prev_loader = self.app.loader
        worker = self.Worker(app=self.app, queues='foo,bar,baz,xuzzy,do,re,mi')
        self.app.loader = Mock()
        self.app.loader.__module__ = 'acme.baked_beans'
        self.assertTrue(worker.startup_info())

        self.app.loader = Mock()
        self.app.loader.__module__ = 'celery.loaders.foo'
        self.assertTrue(worker.startup_info())

        from celery.loaders.app import AppLoader
        self.app.loader = AppLoader(app=self.app)
        self.assertTrue(worker.startup_info())

        self.app.loader = prev_loader
        worker.send_events = True
        self.assertTrue(worker.startup_info())

        # test when there are too few output lines
        # to draft the ascii art onto
        prev, cd.ARTLINES = cd.ARTLINES, ['the quick brown fox']
        self.assertTrue(worker.startup_info())
    def test_startup_info(self, stdout, stderr):
        worker = self.Worker(app=self.app)
        worker.on_start()
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.DEBUG
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.INFO
        self.assertTrue(worker.startup_info())

        prev_loader = self.app.loader
        worker = self.Worker(app=self.app, queues='foo,bar,baz,xuzzy,do,re,mi')
        with patch('celery.apps.worker.qualname') as qualname:
            qualname.return_value = 'acme.backed_beans.Loader'
            self.assertTrue(worker.startup_info())

        with patch('celery.apps.worker.qualname') as qualname:
            qualname.return_value = 'celery.loaders.Loader'
            self.assertTrue(worker.startup_info())

        from celery.loaders.app import AppLoader
        self.app.loader = AppLoader(app=self.app)
        self.assertTrue(worker.startup_info())

        self.app.loader = prev_loader
        worker.send_events = True
        self.assertTrue(worker.startup_info())

        # test when there are too few output lines
        # to draft the ascii art onto
        prev, cd.ARTLINES = cd.ARTLINES, ['the quick brown fox']
        try:
            self.assertTrue(worker.startup_info())
        finally:
            cd.ARTLINES = prev
 def test_on_start_custom_logging(self):
     with mock.stdouts():
         self.app.log.redirect_stdouts = Mock()
         worker = self.Worker(app=self.app, redirect_stoutds=True)
         worker._custom_logging = True
         worker.on_start()
         self.app.log.redirect_stdouts.assert_not_called()
Пример #4
0
    def test_startup_info(self):
        worker = self.Worker(app=self.app)
        worker.on_start()
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.DEBUG
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.INFO
        self.assertTrue(worker.startup_info())
        worker.autoscale = 13, 10
        self.assertTrue(worker.startup_info())

        prev_loader = self.app.loader
        worker = self.Worker(app=self.app, queues='foo,bar,baz,xuzzy,do,re,mi')
        self.app.loader = Mock()
        self.app.loader.__module__ = 'acme.baked_beans'
        self.assertTrue(worker.startup_info())

        self.app.loader = Mock()
        self.app.loader.__module__ = 'celery.loaders.foo'
        self.assertTrue(worker.startup_info())

        from celery.loaders.app import AppLoader
        self.app.loader = AppLoader(app=self.app)
        self.assertTrue(worker.startup_info())

        self.app.loader = prev_loader
        worker.send_events = True
        self.assertTrue(worker.startup_info())

        # test when there are too few output lines
        # to draft the ascii art onto
        prev, cd.ARTLINES = cd.ARTLINES, ['the quick brown fox']
        self.assertTrue(worker.startup_info())
Пример #5
0
    def test_startup_info(self, stdout, stderr):
        worker = self.Worker(app=self.app)
        worker.on_start()
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.DEBUG
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.INFO
        self.assertTrue(worker.startup_info())

        prev_loader = self.app.loader
        worker = self.Worker(app=self.app, queues='foo,bar,baz,xuzzy,do,re,mi')
        with patch('celery.apps.worker.qualname') as qualname:
            qualname.return_value = 'acme.backed_beans.Loader'
            self.assertTrue(worker.startup_info())

        with patch('celery.apps.worker.qualname') as qualname:
            qualname.return_value = 'celery.loaders.Loader'
            self.assertTrue(worker.startup_info())

        from celery.loaders.app import AppLoader
        self.app.loader = AppLoader(app=self.app)
        self.assertTrue(worker.startup_info())

        self.app.loader = prev_loader
        worker.task_events = True
        self.assertTrue(worker.startup_info())

        # test when there are too few output lines
        # to draft the ascii art onto
        prev, cd.ARTLINES = cd.ARTLINES, ['the quick brown fox']
        try:
            self.assertTrue(worker.startup_info())
        finally:
            cd.ARTLINES = prev
Пример #6
0
 def test_on_start_custom_logging(self):
     prev, self.app.log.redirect_stdouts = (
         self.app.log.redirect_stdouts, Mock(),
     )
     try:
         worker = self.Worker(app=self.app, redirect_stoutds=True)
         worker._custom_logging = True
         worker.on_start()
         self.assertFalse(self.app.log.redirect_stdouts.called)
     finally:
         self.app.log.redirect_stdouts = prev
Пример #7
0
 def test_on_start_custom_logging(self):
     prev, self.app.log.redirect_stdouts = (
         self.app.log.redirect_stdouts, Mock(),
     )
     try:
         worker = self.Worker(redirect_stoutds=True)
         worker._custom_logging = True
         worker.on_start()
         self.assertFalse(self.app.log.redirect_stdouts.called)
     finally:
         self.app.log.redirect_stdouts = prev
Пример #8
0
    def test_warns_if_running_as_privileged_user(self):
        app = current_app
        if app.IS_WINDOWS:
            raise SkipTest('Not applicable on Windows')

        def getuid():
            return 0

        prev, os.getuid = os.getuid, getuid
        try:
            with self.assertWarnsRegex(RuntimeWarning,
                                       r'superuser privileges is discouraged'):
                worker = self.Worker()
                worker.on_start()
        finally:
            os.getuid = prev
Пример #9
0
    def test_warns_if_running_as_privileged_user(self):
        app = current_app
        if app.IS_WINDOWS:
            raise SkipTest('Not applicable on Windows')

        def getuid():
            return 0

        prev, os.getuid = os.getuid, getuid
        try:
            with self.assertWarnsRegex(RuntimeWarning,
                    r'superuser privileges is discouraged'):
                worker = self.Worker()
                worker.on_start()
        finally:
            os.getuid = prev
Пример #10
0
    def test_startup_info(self):
        worker = self.Worker()
        worker.on_start()
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.DEBUG
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.INFO
        self.assertTrue(worker.startup_info())
        worker.autoscale = 13, 10
        self.assertTrue(worker.startup_info())

        app = Celery(set_as_current=False)
        worker = self.Worker(app=app, queues='foo,bar,baz,xuzzy,do,re,mi')
        prev, app.loader = app.loader, Mock()
        try:
            app.loader.__module__ = 'acme.baked_beans'
            self.assertTrue(worker.startup_info())
        finally:
            app.loader = prev

        prev, app.loader = app.loader, Mock()
        try:
            app.loader.__module__ = 'celery.loaders.foo'
            self.assertTrue(worker.startup_info())
        finally:
            app.loader = prev

        from celery.loaders.app import AppLoader
        prev, app.loader = app.loader, AppLoader()
        try:
            self.assertTrue(worker.startup_info())
        finally:
            app.loader = prev

        worker.send_events = True
        self.assertTrue(worker.startup_info())

        # test when there are too few output lines
        # to draft the ascii art onto
        prev, cd.ARTLINES = (cd.ARTLINES,
            ['the quick brown fox'])
        self.assertTrue(worker.startup_info())
Пример #11
0
    def test_startup_info(self):
        worker = self.Worker()
        worker.on_start()
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.DEBUG
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.INFO
        self.assertTrue(worker.startup_info())
        worker.autoscale = 13, 10
        self.assertTrue(worker.startup_info())

        app = Celery(set_as_current=False)
        worker = self.Worker(app=app, queues='foo,bar,baz,xuzzy,do,re,mi')
        prev, app.loader = app.loader, Mock()
        try:
            app.loader.__module__ = 'acme.baked_beans'
            self.assertTrue(worker.startup_info())
        finally:
            app.loader = prev

        prev, app.loader = app.loader, Mock()
        try:
            app.loader.__module__ = 'celery.loaders.foo'
            self.assertTrue(worker.startup_info())
        finally:
            app.loader = prev

        from celery.loaders.app import AppLoader
        prev, app.loader = app.loader, AppLoader()
        try:
            self.assertTrue(worker.startup_info())
        finally:
            app.loader = prev

        worker.send_events = True
        self.assertTrue(worker.startup_info())

        # test when there are too few output lines
        # to draft the ascii art onto
        prev, cd.ARTLINES = (cd.ARTLINES, ['the quick brown fox'])
        self.assertTrue(worker.startup_info())
    def test_startup_info(self):
        with mock.stdouts():
            worker = self.Worker(app=self.app)
            worker.on_start()
            assert worker.startup_info()
            worker.loglevel = logging.DEBUG
            assert worker.startup_info()
            worker.loglevel = logging.INFO
            assert worker.startup_info()
            worker.autoscale = 13, 10
            assert worker.startup_info()

            prev_loader = self.app.loader
            worker = self.Worker(
                app=self.app,
                queues='foo,bar,baz,xuzzy,do,re,mi',
            )
            with patch('celery.apps.worker.qualname') as qualname:
                qualname.return_value = 'acme.backed_beans.Loader'
                assert worker.startup_info()

            with patch('celery.apps.worker.qualname') as qualname:
                qualname.return_value = 'celery.loaders.Loader'
                assert worker.startup_info()

            from celery.loaders.app import AppLoader
            self.app.loader = AppLoader(app=self.app)
            assert worker.startup_info()

            self.app.loader = prev_loader
            worker.task_events = True
            assert worker.startup_info()

            # test when there are too few output lines
            # to draft the ascii art onto
            prev, cd.ARTLINES = cd.ARTLINES, ['the quick brown fox']
            try:
                assert worker.startup_info()
            finally:
                cd.ARTLINES = prev
Пример #13
0
    def test_warns_if_running_as_privileged_user(self):
        app = self.app
        if app.IS_WINDOWS:
            raise SkipTest('Not applicable on Windows')

        def getuid():
            return 0

        with patch('os.getuid') as getuid:
            getuid.return_value = 0
            self.app.conf.CELERY_ACCEPT_CONTENT = ['pickle']
            with self.assertRaises(RuntimeError):
                worker = self.Worker(app=self.app)
                worker.on_start()
            cd.C_FORCE_ROOT = True
            try:
                with self.assertWarnsRegex(
                        RuntimeWarning,
                        r'absolutely not recommended'):
                    worker = self.Worker(app=self.app)
                    worker.on_start()
            finally:
                cd.C_FORCE_ROOT = False
            self.app.conf.CELERY_ACCEPT_CONTENT = ['json']
            with self.assertWarnsRegex(
                    RuntimeWarning,
                    r'absolutely not recommended'):
                worker = self.Worker(app=self.app)
                worker.on_start()
Пример #14
0
    def test_warns_if_running_as_privileged_user(self, _exit):
        app = self.app
        if app.IS_WINDOWS:
            raise SkipTest('Not applicable on Windows')

        with patch('os.getuid') as getuid:
            getuid.return_value = 0
            self.app.conf.CELERY_ACCEPT_CONTENT = ['pickle']
            worker = self.Worker(app=self.app)
            worker.on_start()
            _exit.assert_called_with(1)
            from celery import platforms
            platforms.C_FORCE_ROOT = True
            try:
                with self.assertWarnsRegex(
                        RuntimeWarning,
                        r'absolutely not recommended'):
                    worker = self.Worker(app=self.app)
                    worker.on_start()
            finally:
                platforms.C_FORCE_ROOT = False
            self.app.conf.CELERY_ACCEPT_CONTENT = ['json']
            with self.assertWarnsRegex(
                    RuntimeWarning,
                    r'absolutely not recommended'):
                worker = self.Worker(app=self.app)
                worker.on_start()
Пример #15
0
    def test_warns_if_running_as_privileged_user(self):
        app = self.app
        if app.IS_WINDOWS:
            raise SkipTest('Not applicable on Windows')

        def getuid():
            return 0

        with patch('os.getuid') as getuid:
            getuid.return_value = 0
            self.app.conf.CELERY_ACCEPT_CONTENT = ['pickle']
            with self.assertRaises(RuntimeError):
                worker = self.Worker(app=self.app)
                worker.on_start()
            cd.C_FORCE_ROOT = True
            try:
                with self.assertWarnsRegex(RuntimeWarning,
                                           r'absolutely not recommended'):
                    worker = self.Worker(app=self.app)
                    worker.on_start()
            finally:
                cd.C_FORCE_ROOT = False
            self.app.conf.CELERY_ACCEPT_CONTENT = ['json']
            with self.assertWarnsRegex(RuntimeWarning,
                                       r'absolutely not recommended'):
                worker = self.Worker(app=self.app)
                worker.on_start()
Пример #16
0
    def test_warns_if_running_as_privileged_user(self, _exit):
        app = self.app
        if app.IS_WINDOWS:
            raise SkipTest('Not applicable on Windows')

        with patch('os.getuid') as getuid:
            getuid.return_value = 0
            self.app.conf.CELERY_ACCEPT_CONTENT = ['pickle']
            worker = self.Worker(app=self.app)
            worker.on_start()
            _exit.assert_called_with(1)
            from celery import platforms
            platforms.C_FORCE_ROOT = True
            try:
                with self.assertWarnsRegex(
                        RuntimeWarning,
                        r'absolutely not recommended'):
                    worker = self.Worker(app=self.app)
                    worker.on_start()
            finally:
                platforms.C_FORCE_ROOT = False
            self.app.conf.CELERY_ACCEPT_CONTENT = ['json']
            with self.assertWarnsRegex(
                    RuntimeWarning,
                    r'absolutely not recommended'):
                worker = self.Worker(app=self.app)
                worker.on_start()
Пример #17
0
    def test_startup_info(self):
        worker = self.Worker(app=self.app)
        worker.on_start()
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.DEBUG
        self.assertTrue(worker.startup_info())
        worker.loglevel = logging.INFO
        self.assertTrue(worker.startup_info())
        worker.autoscale = 13, 10
        self.assertTrue(worker.startup_info())

        prev_loader = self.app.loader
        worker = self.Worker(app=self.app, queues="foo,bar,baz,xuzzy,do,re,mi")
        with patch("celery.apps.worker.qualname") as qualname:
            qualname.return_value = "acme.backed_beans.Loader"
            self.assertTrue(worker.startup_info())

        with patch("celery.apps.worker.qualname") as qualname:
            qualname.return_value = "celery.loaders.Loader"
            self.assertTrue(worker.startup_info())

        from celery.loaders.app import AppLoader

        self.app.loader = AppLoader(app=self.app)
        self.assertTrue(worker.startup_info())

        self.app.loader = prev_loader
        worker.send_events = True
        self.assertTrue(worker.startup_info())

        # test when there are too few output lines
        # to draft the ascii art onto
        prev, cd.ARTLINES = cd.ARTLINES, ["the quick brown fox"]
        try:
            self.assertTrue(worker.startup_info())
        finally:
            cd.ARTLINES = prev
    def test_warns_if_running_as_privileged_user(self, _exit, patching):
        getuid = patching('os.getuid')

        with mock.stdouts() as (_, stderr):
            getuid.return_value = 0
            self.app.conf.accept_content = ['pickle']
            worker = self.Worker(app=self.app)
            worker.on_start()
            _exit.assert_called_with(1)
            patching.setattr('celery.platforms.C_FORCE_ROOT', True)
            worker = self.Worker(app=self.app)
            worker.on_start()
            assert 'a very bad idea' in stderr.getvalue()
            patching.setattr('celery.platforms.C_FORCE_ROOT', False)
            self.app.conf.accept_content = ['json']
            worker = self.Worker(app=self.app)
            worker.on_start()
            assert 'superuser' in stderr.getvalue()
Пример #19
0
 def test_warns_if_running_as_privileged_user(self, _exit, stdout, stderr):
     with patch('os.getuid') as getuid:
         getuid.return_value = 0
         self.app.conf.accept_content = ['pickle']
         worker = self.Worker(app=self.app)
         worker.on_start()
         _exit.assert_called_with(1)
         from celery import platforms
         platforms.C_FORCE_ROOT = True
         try:
             with self.assertWarnsRegex(RuntimeWarning,
                                        r'absolutely not recommended'):
                 worker = self.Worker(app=self.app)
                 worker.on_start()
         finally:
             platforms.C_FORCE_ROOT = False
         self.app.conf.accept_content = ['json']
         with self.assertWarnsRegex(RuntimeWarning,
                                    r'absolutely not recommended'):
             worker = self.Worker(app=self.app)
             worker.on_start()
Пример #20
0
 def test_warns_if_running_as_privileged_user(self, _exit, stdout, stderr):
     with patch('os.getuid') as getuid:
         getuid.return_value = 0
         self.app.conf.accept_content = ['pickle']
         worker = self.Worker(app=self.app)
         worker.on_start()
         _exit.assert_called_with(1)
         from celery import platforms
         platforms.C_FORCE_ROOT = True
         try:
             with self.assertWarnsRegex(
                     RuntimeWarning,
                     r'absolutely not recommended'):
                 worker = self.Worker(app=self.app)
                 worker.on_start()
         finally:
             platforms.C_FORCE_ROOT = False
         self.app.conf.accept_content = ['json']
         with self.assertWarnsRegex(
                 RuntimeWarning,
                 r'absolutely not recommended'):
             worker = self.Worker(app=self.app)
             worker.on_start()
Пример #21
0
    def test_warns_if_running_as_privileged_user(self, _exit):
        app = self.app
        if app.IS_WINDOWS:
            raise SkipTest("Not applicable on Windows")

        with patch("os.getuid") as getuid:
            getuid.return_value = 0
            self.app.conf.accept_content = ["pickle"]
            worker = self.Worker(app=self.app)
            worker.on_start()
            _exit.assert_called_with(1)
            from celery import platforms

            platforms.C_FORCE_ROOT = True
            try:
                with self.assertWarnsRegex(RuntimeWarning, r"absolutely not recommended"):
                    worker = self.Worker(app=self.app)
                    worker.on_start()
            finally:
                platforms.C_FORCE_ROOT = False
            self.app.conf.accept_content = ["json"]
            with self.assertWarnsRegex(RuntimeWarning, r"absolutely not recommended"):
                worker = self.Worker(app=self.app)
                worker.on_start()
Пример #22
0
 def test_on_start_custom_logging(self):
     self.app.log.redirect_stdouts = Mock()
     worker = self.Worker(app=self.app, redirect_stoutds=True)
     worker._custom_logging = True
     worker.on_start()
     self.assertFalse(self.app.log.redirect_stdouts.called)
Пример #23
0
 def test_run(self):
     self.Worker().on_start()
     self.Worker(purge=True).on_start()
     worker = self.Worker()
     worker.on_start()
Пример #24
0
 def test_run(self):
     self.Worker(app=self.app).on_start()
     self.Worker(app=self.app, purge=True).on_start()
     worker = self.Worker(app=self.app)
     worker.on_start()
Пример #25
0
 def test_run(self):
     self.Worker().on_start()
     self.Worker(purge=True).on_start()
     worker = self.Worker()
     worker.on_start()
 def test_run(self):
     with mock.stdouts():
         self.Worker(app=self.app).on_start()
         self.Worker(app=self.app, purge=True).on_start()
         worker = self.Worker(app=self.app)
         worker.on_start()
Пример #27
0
 def test_run(self):
     self.Worker(app=self.app).on_start()
     self.Worker(app=self.app, purge=True).on_start()
     worker = self.Worker(app=self.app)
     worker.on_start()
Пример #28
0
 def test_on_start_custom_logging(self):
     self.app.log.redirect_stdouts = Mock()
     worker = self.Worker(app=self.app, redirect_stoutds=True)
     worker._custom_logging = True
     worker.on_start()
     self.assertFalse(self.app.log.redirect_stdouts.called)