예제 #1
0
    def test_drop_database(self, have_role_mock):
        have_role_mock.return_value = True

        db = model.mongo.db()
        db.test_collection.insert({"name": "test thingy"})

        response = self.app.get(url(controller='task', action='drop_database'))

        assert daemon.job_running('drop_database'), \
            "drop_database action didn't start the drop_database job!"

        while daemon.job_running('drop_database'):
            time.sleep(0.1)

        h.assert_equal(db.collection_names(), ['system.js', 'system.indexes'])
예제 #2
0
    def test_job_log_stderr(self):
        daemon.dispatch_job('test', config['__file__'], 'test_stderr')

        while daemon.job_running('test'):
            time.sleep(0.1)

        h.assert_equal(daemon.job_log('test'), 'Text to standard error\n')
예제 #3
0
    def test_dispatch_job_nonexistent_task(self):
        daemon.dispatch_job('test', config['__file__'], 'test_nonexistent')

        while daemon.job_running('test'):
            time.sleep(0.1)

        assert 'TaskNotFoundError' in daemon.job_log('test'), \
               "TaskNotFoundError not in job log for nonexistent task!"
예제 #4
0
    def test_args(self):
        args = ('one', '123', 'abc')
        daemon.dispatch_job('test', config['__file__'], 'test_args', args)

        while daemon.job_running('test'):
            time.sleep(0.1)

        h.assert_equal(daemon.job_log('test'), "('one', '123', 'abc')\n")
예제 #5
0
    def status(self, job_id):
        c.job_id = job_id
        c.job_running = daemon.job_running(job_id)
        c.job_log = daemon.job_log(job_id)

        if request.is_xhr:
            return render('job/_status.html')
        else:
            return render('job/status.html')
예제 #6
0
    def test_remove_dataset(self, have_role_mock):
        have_role_mock.return_value = True

        ds = model.Dataset(name='mydataset')
        ds.save()

        response = self.app.get(url(controller='task',
                                    action='remove_dataset',
                                    dataset='mydataset'))

        assert daemon.job_running('remove_mydataset'), \
            "remove_dataset action didn't start the remove_mydataset job!"

        while daemon.job_running('remove_mydataset'):
            time.sleep(0.1)

        res = model.Dataset.find_one({'name': 'mydataset'})
        h.assert_equal(res, None)
예제 #7
0
    def drop_database(self):
        c.job_id = 'drop_database'

        if daemon.job_running(c.job_id):
            return render('task/drop_database.html')

        daemon.dispatch_job(
            job_id=c.job_id,
            config=config['__file__'],
            task='drop_collections'
        )
        return redirect(url(controller='job', action='status', job_id=c.job_id))
예제 #8
0
    def test_start(self, have_role_mock):
        have_role_mock.return_value = True # Pretend to be admin user.

        response = self.app.get(url(controller='load',
                                    action='start',
                                    package='bar'))

        # Redirects to status page
        status_path = url(controller='job', action='status', job_id='import_bar')
        assert response.headers['Location'].endswith(status_path), \
            "LoadController start action didn't redirect to status page."

        assert daemon.job_running('import_bar'), \
            "LoadController start action didn't start the import_bar job!"
예제 #9
0
    def remove_dataset(self, dataset=None):
        if dataset is None:
            c.datasets = model.Dataset.find()
            return render('task/remove_dataset.html')

        c.job_id = 'remove_%s' % dataset
        c.job_running = daemon.job_running(c.job_id)

        if c.job_running:
            return render('task/remove_dataset.html')

        daemon.dispatch_job(
            job_id=c.job_id,
            config=config['__file__'],
            task='remove_dataset',
            args=(dataset,)
        )
        return redirect(url(controller='job', action='status', job_id=c.job_id))
예제 #10
0
    def start(self, package):
        job_id = _job_id_for_package(package)

        if daemon.job_running(job_id):
            c.pkg_name = package
            c.job_id = job_id
            return render('load/start.html')
        else:
            daemon.dispatch_job(
                job_id=job_id,
                config=config['__file__'],
                task='ckan_import',
                args=(package,)
            )
            return redirect(url(
                controller='job',
                action='status',
                job_id=job_id
            ))