def handle(self, *args, **options):
        if len(args) != 1:
            self.print_help(sys.argv[0], sys.argv[1])
            return
            
        if 'DJANGOTASKS_TESTING' in os.environ:
            # In tests, we make sure that we are using the right database connection
            # This code is heavily inspired by BaseDatabaseCreation._create_test_db in django/db/backends/creation.py
            # (why doesn't Django provides this as a public method ??)
            from django.db import connections
            for alias in connections:
                connection = connections[alias]
                connection.close()
                if connection.settings_dict['TEST_NAME']:
                    test_database_name = connection.settings_dict['TEST_NAME']
                else:
                    from django.db.backends.creation import TEST_DATABASE_PREFIX
                    test_database_name = TEST_DATABASE_PREFIX + connection.settings_dict['NAME']
                    
                connection.settings_dict["NAME"] = test_database_name
                if hasattr(connection.creation, '_rollback_works'):
                    # needed in Django 1.2, but not anymore in 1.3
                    can_rollback = connection.creation._rollback_works()
                    connection.settings_dict["SUPPORTS_TRANSACTIONS"] = can_rollback

            # Also register the test model
            from djangotasks import tests

        from djangotasks.models import Task, LOG
        # Ensure that task log messages will be sent to the standard output
        # thus caught in the task's log
        LOG.addHandler(logging.StreamHandler())
        LOG.setLevel(logging.INFO)

        return Task.objects.exec_task(*args)
Esempio n. 2
0
    def handle(self, *args, **options):
        if 'DJANGOTASKS_TESTING' in os.environ:
            # In tests, we make sure that we are using the right database connection
            # This code is heavily inspired by BaseDatabaseCreation._create_test_db in django/db/backends/creation.py
            # (why doesn't Django provides this as a public method ??)
            from django.db import connections
            for alias in connections:
                connection = connections[alias]
                connection.close()
                if connection.settings_dict[
                        'TEST'] and connection.settings_dict['TEST']['NAME']:
                    test_database_name = connection.settings_dict['TEST'][
                        'NAME']
                else:
                    from django.db.backends.creation import TEST_DATABASE_PREFIX
                    test_database_name = TEST_DATABASE_PREFIX + connection.settings_dict[
                        'NAME']

                connection.settings_dict["NAME"] = test_database_name
                if hasattr(connection.creation, '_rollback_works'):
                    # needed in Django 1.2, but not anymore in 1.3
                    can_rollback = connection.creation._rollback_works()
                    connection.settings_dict[
                        "SUPPORTS_TRANSACTIONS"] = can_rollback

            # Also register the test model
            from djangotasks import tests

        from djangotasks.models import Task, LOG
        # Ensure that task log messages will be sent to the standard output
        # thus caught in the task's log
        LOG.addHandler(logging.StreamHandler())
        LOG.setLevel(logging.INFO)

        return Task.objects.exec_task(options['task_id'])
Esempio n. 3
0
 def __enter__(self):
     from djangotasks.models import LOG
     self.loghandlers = LOG.handlers
     LOG.handlers = []
     self.log = StringIO.StringIO()
     test_handler = logging.StreamHandler(self.log)
     test_handler.setFormatter(
         logging.Formatter('%(levelname)s: %(message)s'))
     LOG.addHandler(test_handler)
Esempio n. 4
0
    def __enter__(self):
        from djangotasks.models import LOG

        self.loghandlers = LOG.handlers
        LOG.handlers = []
        self.log = StringIO.StringIO()
        test_handler = logging.StreamHandler(self.log)
        test_handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
        LOG.addHandler(test_handler)
Esempio n. 5
0
 def __enter__(self):
     from djangotasks.models import LOG
     self.loghandlers = LOG.handlers
     LOG.handlers = []
     self.log = StringIO()
     test_handler = logging.StreamHandler(self.log)
     test_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
     self.loglevel = LOG.getEffectiveLevel()
     LOG.setLevel(logging.INFO)
     LOG.addHandler(test_handler)
Esempio n. 6
0
    def __exit__(self, type, value, traceback):
        # Restore state
        from djangotasks.models import LOG
        LOG.handlers = self.loghandlers
        LOG.setLevel(self.loglevel)

        # Check the output only if no exception occured (to avoid "eating" test failures)
        if type:
            return

        if self.fail_if_different:
            self.test.assertEquals(self.expected_log, self.log.getvalue())
Esempio n. 7
0
    def __exit__(self, type, value, traceback):
        # Restore state
        from djangotasks.models import LOG
        LOG.handlers = self.loghandlers
        LOG.setLevel(self.loglevel)

        # Check the output only if no exception occured (to avoid "eating" test failures)
        if type:
            return
        
        if self.fail_if_different:
            self.test.assertEquals(self.expected_log, self.log.getvalue())
Esempio n. 8
0
    def handle(self, *args, **options):

        from djangotasks.models import Task, LOG

        LOG.addHandler(logging.StreamHandler())
        LOG.setLevel(logging.INFO)
        for t in Task.objects.filter(status__in=['scheduled', 'running'], archived=False):
            LOG.info('Task with id %s (%s) is %s' % (t.pk, t.method, t.status))
Esempio n. 9
0
    def handle(self, *args, **options):

        from djangotasks.models import Task, LOG

        LOG.addHandler(logging.StreamHandler())
        LOG.setLevel(logging.INFO)
        for t in Task.objects.filter(status__in=['scheduled', 'running'],
                                     archived=False):
            LOG.info('Task with id %s (%s) is %s' % (t.pk, t.method, t.status))