Exemplo n.º 1
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)
Exemplo n.º 2
0
def test_rawsql(dbcache, mocker):
    assert dbcache.size == 0
    try:
        result = CliRunner().invoke(
            initializer.init,
            [
                "--no-cache",
                "-n",
                TEST_DBNAME_NEW,
                """UPDATE res_company SET name='hello' WHERE id=1""",
            ],
        )
        assert result.exit_code == 0, result.output
        assert dbcache.size == 0
        self = mocker.patch("dodoo.CommandWithOdooEnv")
        self.database = TEST_DBNAME_NEW
        with dodoo.OdooEnvironment(self) as env:
            c = env["res.company"].browse([1])
            assert c.name == "hello", "company was not renamed from rawsql"
    finally:
        _dropdb(TEST_DBNAME_NEW)
Exemplo n.º 3
0
def test_create_cmd_nocache(dbcache, mocker):
    assert dbcache.size == 0
    try:
        result = CliRunner().invoke(
            initializer.init,
            ["--no-cache", "-n", TEST_DBNAME_NEW, "-m", "auth_signup"])
        assert result.exit_code == 0, result.output
        assert dbcache.size == 0
        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"
            env.cr.execute("""
                SELECT COUNT(*) FROM ir_attachment
                WHERE store_fname IS NULL
            """)
            assert (env.cr.fetchone()[0] == 0
                    ), "some attachments are not stored in filestore"
    finally:
        _dropdb(TEST_DBNAME_NEW)
Exemplo n.º 4
0
def refresh_module_list(dbname):
    self = click.get_current_context().command
    self.database = dbname
    with dodoo.OdooEnvironment(self) as env:
        env["ir.module.module"].update_list()
Exemplo n.º 5
0
def test_create_cmd_cache(dbcache, tmpdir, mocker):
    assert dbcache.size == 0
    try:
        result = CliRunner().invoke(
            initializer.init,
            [
                "--cache-prefix", TEST_PREFIX, "-n", TEST_DBNAME_NEW, "-m",
                "auth_signup"
            ],
        )
        assert result.exit_code == 0, result.output
        assert dbcache.size == 1
        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"
            env.cr.execute("""
                SELECT COUNT(*) FROM ir_attachment
                WHERE store_fname IS NOT NULL
            """)
            assert env.cr.fetchone(
            )[0] == 0, "some attachments are not stored in db"
    finally:
        _dropdb(TEST_DBNAME_NEW)
    # try again, from cache this time
    with mock.patch.object(initializer, "odoo_createdb") as m:
        try:
            result = CliRunner().invoke(
                initializer.init,
                [
                    "--cache-prefix",
                    TEST_PREFIX,
                    "--new-database",
                    TEST_DBNAME_NEW,
                    "--modules",
                    "auth_signup",
                ],
            )
            assert result.exit_code == 0, result.output
            assert m.call_count == 0
            assert dbcache.size == 1
        finally:
            _dropdb(TEST_DBNAME_NEW)
        # now run again, with a new addon in path
        # and make sure the list of modules has been updated
        # after creating the database from cache
        odoo_cfg = tmpdir / "odoo.cfg"
        odoo_cfg.write(
            textwrap.dedent("""\
            [options]
            addons_path = {}
        """.format(ADDONS_PATH)))
        cmd = [
            sys.executable,
            "-m",
            "src.initializer",
            "-c",
            str(odoo_cfg),
            "--cache-prefix",
            TEST_PREFIX,
            "--new-database",
            TEST_DBNAME_NEW,
            "--modules",
            "auth_signup",
        ]
        try:
            subprocess.check_call(cmd)
            self = mocker.patch("dodoo.CommandWithOdooEnv")
            self.database = TEST_DBNAME_NEW
            with dodoo.OdooEnvironment(self) as env:
                assert env["ir.module.module"].search([
                    ("name", "=", "addon1")
                ]), "module addon1 not present in new database"
        finally:
            _dropdb(TEST_DBNAME_NEW)

    # Reset side-effects
    initializer.init.database = False