Beispiel #1
0
def test_backup_restore(bkpdir, tmp_path, init_odoo, newdb2, caplog, mocker):
    caplog.set_level(logging.INFO)
    dbname = "notexists"
    backup(filestore_include=True, dbname=dbname, dest=bkpdir)
    assert f"Database {dbname} doesn't exists." in caplog.text
    caplog.clear()
    dt = mocker.patch("dodoo_backup.datetime")
    now = datetime.now()
    dt.now.return_value = now
    dt.isoformat.return_value = datetime.isoformat(now, timespec="seconds")
    archive = backup(filestore_include=True, dbname=init_odoo, dest=bkpdir)
    assert archive.parent == bkpdir
    assert datetime.isoformat(now, timespec="seconds") in str(archive)
    caplog.clear()

    dbname = newdb2
    # Restore normally
    restore(clear=False, dbname=dbname, src=archive)
    assert f"Database & filestore {dbname} restored." in caplog.text
    caplog.clear()

    from dodoo.interfaces import odoo

    # We are naively (not really) verifying shutil itself here
    # (basically, just check somehow if that call was made)
    fs_from = odoo.Config().filestore(init_odoo)
    fs_new = odoo.Config().filestore(dbname)
    for path in fs_from.iterdir():
        assert (fs_new / path).exists()

    # Restore already exists
    restore(clear=False, dbname=dbname, src=archive)
    assert f"Database {dbname} already exists." in caplog.text
    caplog.clear()

    # Restore already exists with clear
    restore(clear=True, dbname=dbname, src=archive)
    assert f"Dropping database & filestore of {dbname} before restoring." in caplog.text
    assert f"Database & filestore {dbname} pruned." in caplog.text
    assert f"Database & filestore {dbname} restored." in caplog.text
    caplog.clear()

    # Ensure corrupted archives fail before deleting target database.
    with _extracted(archive) as dir:
        db_bkp = dir / "db.dump"
        db_bkp.rename(db_bkp.parent / "wrongname.dump")
        newarchive = dir / "corrupted_archive"
        newarchive = Path(shutil.make_archive(newarchive, "gztar", dir))
        # Restore already exists with clear
        with pytest.raises(FolderStructureUnkown):
            restore(clear=True, dbname=dbname, src=newarchive)
    assert (f"Dropping database & filestore of {dbname} before restoring."
            not in caplog.text)
    assert f"Database & filestore {dbname} pruned." not in caplog.text
    assert f"Database & filestore {dbname} restored." not in caplog.text
    caplog.clear()
Beispiel #2
0
def fs(main_loaded):
    dbname = "testdb"
    from dodoo.interfaces import odoo

    fs = odoo.Config().filestore(dbname)
    fs.mkdir(parents=True)
    yield fs
    if fs.exists():
        fs.rmdir()
Beispiel #3
0
def _deduced_actions(path, module_name, relpath, info):

    path = Path(path)
    res = {}
    model_names_in_file = []
    # Python files
    if path.suffix == ".py" and not path.name.startswith(".~"):
        if path.name in odoo.Modules().MANIFEST_NAMES:
            res["update_module_list"] = True
        else:
            model_names_in_file += _get_odoo_models_from_file(path)
    # Something else, but referenced in the manifest -> upgrade module
    elif relpath and (relpath in info.get("data")
                      or relpath in info.get("demo")
                      and module_name in odoo.Config().config["demo"]
                      or odoo.Config().config["demo"] == "all"):
        if not relpath.startswith("view"):
            res["update"] = True
    res["model_names_in_file"] = model_names_in_file
    return res
Beispiel #4
0
 def test_config(self):
     odoo.Config().config
     odoo.Config().conf
     odoo.Config().defaults()
     # Repetitive call without error
     # Odoo's _parse_config() is not idempotent and only works on a freshly
     # initialized config object
     odoo.Config().defaults()
     odoo.Config().filestore("dbname")
     odoo.Config().session_dir()
Beispiel #5
0
 def apply(self):
     cfg = odoo.Config()
     for k, v in self.__dict__.items():
         cfg.config[k] = v
     cfg.config["list_db"] = self.list_db
     cfg.config["addons_path"] = ",".join(
         [str(self.scoped_addons_dir)] +
         [str(p) for p in self.resolve_addons_paths()] +
         cfg.config["addons_path"].split(","))
     # Fix frozenset config value
     cfg.config["server_wide_modules"] = ",".join(
         cfg.config["server_wide_modules"])
     # Fix Path objects
     cfg.config["data_dir"] = str(cfg.config["data_dir"])
     cfg.config["backup_dir"] = str(cfg.config["backup_dir"])
     cfg.config["geoip_database"] = str(cfg.config["geoip_database"])
     # Fix loaded defaults
     cfg.conf.addons_paths = cfg.config["addons_path"].split(",")
     server_wide_modules = cfg.config["server_wide_modules"].split(",")
     cfg.conf.server_wide_modules = [
         m.strip() for m in server_wide_modules if m.strip()
     ]
Beispiel #6
0
def install_modules(modules: List[str], dbname: str) -> None:
    odoo.Config().config["init"] = dict.fromkeys(modules, 1)
    odoo.Registry.update(dbname)
    odoo.Database().close_all()
    msg = f"Additional module(s) {','.join(modules)} installed."
    _log.info(msg)
Beispiel #7
0
def backup_filestore(dbname: str, folder: Path) -> None:
    fs = odoo.Config().filestore(dbname)
    shutil.copytree(fs, folder)
Beispiel #8
0
def drop_filestore(dbname: str) -> None:
    fs = odoo.Config().filestore(dbname)
    if fs.exists():
        shutil.rmtree(fs)
Beispiel #9
0
def copy_filestore(dbname: str, dbname_new: str) -> None:
    fs_src = odoo.Config().filestore(dbname)
    fs_dest = odoo.Config().filestore(dbname_new)
    _copy_if_not_exists(fs_src, fs_dest)
Beispiel #10
0
def restore_filestore(dbname: str, folder: Path) -> None:
    fs_dest = odoo.Config().filestore(dbname)
    _copy_if_not_exists(folder, fs_dest)
Beispiel #11
0
 def test_odoo_config_apply(self, confd, caplog):
     caplog.set_level(logging.WARNING)
     config = load_config(confd, RUNMODE.Production)
     config.Odoo.apply()
     odoo.Config().defaults()
     assert len(caplog.records) == 0