Esempio n. 1
0
def _check_default_params(db1, db2, operator):
    params_by_db = defaultdict(dict)
    for db in (db1, db2):
        with click_odoo.OdooEnvironment(database=db) as env:
            IrConfigParameters = env["ir.config_parameter"]
            for key in _DEFAULT_IR_CONFIG_PARAMETERS:
                params_by_db[db][key] = IrConfigParameters.get_param(key)
    params1 = params_by_db[db1]
    params2 = params_by_db[db2]
    assert set(params1.keys()) == set(params2.keys())
    for k, v in params1.items():
        assert operator(v, params2[k])
Esempio n. 2
0
def test_create_cmd_nocache(dbcache):
    assert dbcache.size == 0
    try:
        result = CliRunner().invoke(
            main, ["--no-cache", "-n", TEST_DBNAME_NEW, "-m", "auth_signup"])
        assert result.exit_code == 0
        assert dbcache.size == 0
        with click_odoo.OdooEnvironment(database=TEST_DBNAME_NEW) 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)
Esempio n. 3
0
def test_create_cmd_nocache(dbcache):
    assert dbcache.size == 0
    try:
        result = CliRunner().invoke(main, [
            '--no-cache',
            '-n', TEST_DBNAME_NEW,
            '-m', 'auth_signup',
        ])
        assert result.exit_code == 0
        assert dbcache.size == 0
        with click_odoo.OdooEnvironment(database=TEST_DBNAME_NEW) 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)
Esempio n. 4
0
def refresh_module_list(dbname):
    with click_odoo.OdooEnvironment(database=dbname) as env:
        env["ir.module.module"].update_list()
Esempio n. 5
0
def test_create_cmd_cache(dbcache, tmpdir):
    assert dbcache.size == 0
    try:
        result = CliRunner().invoke(
            main,
            [
                "--cache-prefix", TEST_PREFIX, "-n", TEST_DBNAME_NEW, "-m",
                "auth_signup"
            ],
        )
        assert result.exit_code == 0
        assert dbcache.size == 1
        with click_odoo.OdooEnvironment(database=TEST_DBNAME_NEW) 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(initdb, "odoo_createdb") as m:
        try:
            result = CliRunner().invoke(
                main,
                [
                    "--cache-prefix",
                    TEST_PREFIX,
                    "--new-database",
                    TEST_DBNAME_NEW,
                    "--modules",
                    "auth_signup",
                ],
            )
            assert result.exit_code == 0
            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",
            "click_odoo_contrib.initdb",
            "-c",
            str(odoo_cfg),
            "--cache-prefix",
            TEST_PREFIX,
            "--new-database",
            TEST_DBNAME_NEW,
            "--modules",
            "auth_signup",
        ]
        try:
            subprocess.check_call(cmd)
            with click_odoo.OdooEnvironment(database=TEST_DBNAME_NEW) as env:
                assert env["ir.module.module"].search([
                    ("name", "=", "addon1")
                ]), "module addon1 not present in new database"
        finally:
            _dropdb(TEST_DBNAME_NEW)