def test_db_url_from_request(self):
        req = DummyRequest()
        odb_url = 'postgresql://localhost/db1?ssl=true'
        req.registry.settings = {}
        req.registry.settings['sqlalchemy.url'] = odb_url
        req.environ['HTTP_AUTHORIZATION'] = 'Basic bWU6cGFzc3dvcmQ=\n'

        db_url = models.db_url_from_request(req)

        edb_url = 'postgresql://*****:*****@localhost/db1?ssl=true'
        self.assertEqual(db_url, edb_url)
    def test_db_url_from_request_overwritehostfromenv(self):
        req = DummyRequest()
        odb_url = 'postgresql://localhost/db1?ssl=true'
        req.registry.settings = {}
        req.registry.settings['sqlalchemy.url'] = odb_url
        req.environ['HTTP_AUTHORIZATION'] = 'Basic bWU6cGFzc3dvcmQ=\n'

        env = {'DB_HOST': 'somemachine'}
        with patch.dict('script_wrapper.models.environ', env):
            db_url = models.db_url_from_request(req)
            edb_url = 'postgresql://*****:*****@somemachine/db1?ssl=true'
            self.assertEqual(db_url, edb_url)
Example #3
0
    def submit(self):
        """Process task submission

        The submission will be validated and submitted to the task queue.
        """
        task = self.task()
        db_url = db_url_from_request(self.request)
        try:
            kwargs = task.formfields2taskargs(self.request.json_body, db_url)
            taskresp = task.apply_async(kwargs=kwargs)
            result_url = self.request.route_path("result", script=self.scriptid, taskid=taskresp.id)
            return {"success": True, "result": result_url}
        except Invalid as e:
            return {"success": False, "msg": e.message}
        except ColanderInvalid as e:
            return {"success": False, "errors": e.asdict()}