def test_framework(self, confd, project_version_file, framework_dir): runner = CliRunner() args = [ "--confd", str(confd), "--framework", str(framework_dir), str(project_version_file), "dummy", ] @main.command() def dummy(): pass result = runner.invoke(main, args) # TODO: add database servie to tests # At this point we don't have a database yet assert isinstance(result.exception, psycopg2.OperationalError) import dodoo assert dodoo.framework().dodoo_run_mode == RUNMODE.Production assert ( dodoo.framework().dodoo_project_version == project_version_file.read_text() ) o = pathlib.Path(dodoo.framework().__file__) h = pathlib.Path(__file__) assert h.parents[2] == o.parents[2] # Cleanup for later tests during the same session dodoo._framework.dodoo_run_mode = None dodoo._framework.dodoo_project_version = None dodoo._framework.dodoo_config = None dodoo._framework = None
def environment(database: str, uid: int = None, dry_run: bool = False, interactive: bool = False) -> dict: global_vars = {"odoo": dodoo.framework()} if not database: msg = "No database set; load odoo namespace only." _log.info(msg) yield global_vars else: registry = odoo.Registry(database) with registry.cursor() as cr: orig_commit = cr.commit with odoo.Environment(cr, uid=uid) as env: ctx = env["res.users"].context_get() if dry_run: cr.commit = raise_on_commit try: with odoo.Environment(cr, uid=uid, context=ctx) as env: global_vars.update(env=env, self=env.user) yield global_vars except Exception as e: cr.rollback() raise e else: cr.rollback() if (dry_run or interactive) else cr.commit() cr.commit = orig_commit # Odoo commits (again) leaving context odoo.Database().close_all()
def graphql(*args, **kwargs): if dodoo.framework().dodoo_run_mode == dodoo.RUNMODE.Develop: import hupper reloader = hupper.get_reloader() reloader.watch_files([str(kwargs["schema"])]) _graphql(*args, **kwargs)
def run(): if dodoo.framework().dodoo_run_mode == dodoo.RUNMODE.Develop: import hupper from .servers.watcher import file_changed hupper.reloader.FileMonitorProxy.file_changed = file_changed hupper.start_reloader(f"dodoo.main")
def db_filter(self, dbs, httprequest=None): httprequest = httprequest or odoo.Request().httprequest host = re.escape(httprequest.environ.get("HTTP_HOST", "").split(":")[0]) project_version = re.escape(dodoo.framework().dodoo_project_version) pattern = rf"{host}-{project_version}" if self.OdooConfig.list_db: pattern = rf".*-{project_version}" dbs = [i for i in dbs if re.match(pattern, i)] return dbs
def server(app: ASGIApp, host: str, port: int, prod: bool = True) -> "server": global server kwargs = dict(host=host, port=port) if not prod: odooconfig = dodoo.framework().dodoo_config.Odoo assert odooconfig.ssl_keyfile and odooconfig.ssl_certfile kwargs.update( ssl_keyfile=str(odooconfig.ssl_keyfile), ssl_certfile=str(odooconfig.ssl_certfile), ) server = uvicorn.run(app, **kwargs) return server
def _is_dev(): return dodoo.framework().dodoo_run_mode == RUNMODE.Develop
def _dsn_resolver(dbname): return dodoo.framework().dodoo_config.Db.resolve_dsn(dbname)
def wrapper(*args, **kwds): framework = dodoo.framework() if not framework: _log.critical("dodoo must initialize the framework first.") raise FrameworkNotInitialized() return f(*args, **kwds)
def __str__(self) -> str: f = dodoo.framework() return f.dodoo_config.Odoo.Sec.session_encryption_key