Пример #1
0
def test_copydb_target_exists(pgdb):
    _createdb(TEST_DBNAME_NEW)
    try:
        assert db_exists(TEST_DBNAME)
        assert db_exists(TEST_DBNAME_NEW)
        result = CliRunner().invoke(copy, [TEST_DBNAME, TEST_DBNAME_NEW])
        assert result.exit_code != 0
        assert "Destination database already exists" in result.output
    finally:
        _dropdb(TEST_DBNAME_NEW)
Пример #2
0
def tests_module_install_and_raw_sql(pgdb, filestore, mocker):
    filestore_dir_new = odoo.tools.config.filestore(TEST_DBNAME_NEW)
    try:
        assert not db_exists(TEST_DBNAME_NEW)
        assert not os.path.exists(filestore_dir_new)
        result = CliRunner().invoke(
            copy,
            [
                "--force-disconnect",
                "--modules",
                "auth_signup",
                TEST_DBNAME,
                TEST_DBNAME_NEW,
                """UPDATE res_company SET name='hello' WHERE id=1""",
            ],
        )
        assert result.exit_code == 0, result.output
        self = mocker.patch("dodoo.CommandWithOdooEnv")
        self.database = TEST_DBNAME_NEW
        with dodoo.OdooEnvironment(self) as env:
            m = env["ir.module.module"].search(
                [("name", "=", "auth_signup"), ("state", "=", "installed")]
            )
            assert m, "auth_signup module not installed"
            c = env["res.company"].browse([1])
            assert c.name == "hello", "company was not renamed from rawsql"
        assert os.path.isdir(filestore_dir_new)
    finally:
        _dropdb(TEST_DBNAME_NEW)
        if os.path.isdir(filestore_dir_new):
            shutil.rmtree(filestore_dir_new)
Пример #3
0
def tests_backupdb_folder_restore(odoodb, odoocfg, tmp_path):
    """Test the compatibility of the db dump file of a folder backup
    with native Odoo restore API
    """
    backup_path = tmp_path.joinpath("backup")
    assert not backup_path.exists()
    backup_dir = backup_path.as_posix()
    result = CliRunner().invoke(backuper.snapshot, [odoodb, backup_dir])
    assert result.exit_code == 0, result.output
    assert backup_path.exists()
    try:
        assert not db_exists(TEST_DBNAME)
        dumpfile = os.path.join(backuper._latest_snapshot(backup_dir), "db.dump")
        with odoo.api.Environment.manage():
            odoo.service.db.restore_db(TEST_DBNAME, dumpfile, copy=True)
            odoo.sql_db.close_db(TEST_DBNAME)
        assert db_exists(TEST_DBNAME)
    finally:
        _dropdb_odoo(TEST_DBNAME)
Пример #4
0
def tests_copydb(pgdb, filestore):
    filestore_dir_new = odoo.tools.config.filestore(TEST_DBNAME_NEW)
    try:
        assert not db_exists(TEST_DBNAME_NEW)
        assert not os.path.exists(filestore_dir_new)
        result = CliRunner().invoke(
            copy, ["--force-disconnect", TEST_DBNAME, TEST_DBNAME_NEW]
        )
        assert result.exit_code == 0, result.output
        # this dropdb will indirectly test that the new db exists
        subprocess.check_call(["dropdb", TEST_DBNAME_NEW])
        assert os.path.isdir(filestore_dir_new)
    finally:
        _dropdb(TEST_DBNAME_NEW)
        if os.path.isdir(filestore_dir_new):
            shutil.rmtree(filestore_dir_new)
Пример #5
0
def tests_copydb_template_absent():
    assert not db_exists(TEST_DBNAME)
    assert not db_exists(TEST_DBNAME_NEW)
    result = CliRunner().invoke(copy, [TEST_DBNAME, TEST_DBNAME_NEW])
    assert result.exit_code != 0
    assert "Source database does not exist" in result.output
Пример #6
0
def tests_backupdb_not_exists():
    assert not db_exists(TEST_DBNAME)
    result = CliRunner().invoke(backuper.snapshot, [TEST_DBNAME, "out"])
    assert result.exit_code != 0
    assert "Database does not exist" in result.output