def test_field_repr(self): self.assertRegex( odoo_repr(self.env["res.users"].login), r"""^char login on res.users \(required, store(, related_sudo)?\) Used to log into the system( On change: on_change_login)? base: /[^\n]*/res_users.py:\d+$""", ) self.assertRegex( odoo_repr(self.env["res.users"].company_id), r"""^many2one company_id on res.users to res.company""" r""" \(required, store(, related_sudo)?\) The [^\n]*\. Default value: (_get_company|lambda self: self\.env\.company\.id)( Constrained by _check_company)? base: /[^\n]*/res_users.py:\d+$""", ) self.assertRegex( odoo_repr(self.env["res.currency"].date), r"""^date date on res.currency \(readonly(, related_sudo)?\) Computed by _?compute_date base: /[^\n]*/res_currency.py:\d+$""", ) self.assertRegex( odoo_repr(self.env["res.partner"].type), r"""^selection type on res.partner \(store(, related_sudo)?\) Address Type: .* Default value: 'contact' \[(\('\w+', '[\w\s]+'\)[,\s]*)+\] base: /[^\n]*/res_partner.py:\d+$""", )
def displayhook(self, obj): # type: (object) -> None if obj is not None: if PY3: self.message(odoo_repl.odoo_repr(obj)) else: print(odoo_repl.odoo_repr(obj), file=self.stdout)
def test_create_write_info(self): demo = self.env["res.users"].search([("login", "=", "demo")]) self.assertRegex( odoo_repr(demo), "Created on 20..-..-.. ..:..:..", ) util.with_user(demo.partner_id, demo).write({"website": "blargh"}) self.assertRegex( odoo_repr(demo.partner_id), r"""Created on 20..-..-.. ..:..:.. Written on 20..-..-.. ..:..:.. by u.demo""", )
def test_repr_all_models(self): for model in self.ns["env"]: self.assertIsInstance(model, odoo_repl.models.ModelProxy) self.assertTrue(odoo_repl.odoo_repr(model)) for field in model.fields_: self.assertIsInstance(field, odoo_repl.fields.FieldProxy) self.assertTrue(odoo_repl.odoo_repr(field)) for attr_name in dir(model._real): if attr_name.startswith("__") or attr_name in {"_cache"}: continue thing = getattr(model, attr_name) try: self.assertTrue(odoo_repl.odoo_repr(thing)) except Exception: print("\n\nFailed on {}.{}\n".format( model._name, attr_name)) raise
def test_repr_all_addons(self): for addon in self.ns["addons"]: self.assertIsInstance(addon, odoo_repl.addons.Addon) if addon.record.state == "uninstallable": continue try: self.assertTrue(odoo_repl.odoo_repr(addon)) except Exception: print("\n\nFailed on addons.{}\n".format(addon._module)) raise
def test_addons(self): self.assertIn("auth_ldap", dir(self.addons)) self.assertIn("base", dir(self.addons)) self.assertEqual(self.addons.auth_ldap.manifest.installable, True) self.assertIsInstance(self.addons.auth_ldap.manifest.version, Text) self.assertTrue( self.addons.auth_ldap.path.endswith("addons/auth_ldap")) self.assertTrue(self.addons.auth_ldap.record.name, "auth_ldap") self.assertRegex( odoo_repr(self.addons.auth_ldap), r"""^auth_ldap [\d\.]* by O[^\n]* https?://.*/web\?debug=1#model=ir\.module\.module&id=\d+ [^\n]*/addons/auth_ldap (Uni|I)nstalled Authentication via LDAP Depends: base(, base_setup)?( Dependents: .*)?( Defines: .*)? Adds support for authentication by LDAP server. ===============================================""", ) self.assertRegex( odoo_repr(self.addons.base), r"""^base [\d\.]* by O[^\n]* https?://.*/web\?debug=1#model=ir\.module\.module&id=\d+ [^\n]*/addons/base Installed Base Dependents: [^\n]* Defines: [^\n]*, res.users, """, ) self.assertEqual(self.addons.base.ref.user_demo, self.u.demo)
def test_model_repr(self): rep = odoo_repl.odoo_repr(self.env["res.users"]) self.assertRegex(rep, r"^res.users\nUsers\n") self.assertRegex(rep, r"\nInherits from res.partner through partner_id\n") self.assertRegex(rep, r"\nrsd company_id:\s*many2one: res.company\n") self.assertRegex(rep, r"\nRs login:\s*char\n") self.assertRegex( rep, r"\nRs partner_id:\s*many2one: res.partner \(Related Partner\)\n" ) self.assertRegex(rep, r"\nDelegated to partner_id: \w+") self.assertRegex(rep, r"\nbase: /[^\n]*/res_users.py:\d+") self.assertRegex(rep, r"\nbase:\n")
def test_record_repr(self): if odoo_repl.xml_thread: odoo_repl.xml_thread.join() rep = odoo_repl.odoo_repr(self.u.demo) self.assertRegex(rep, r"^res.users\[\d*\] \(ref.base.user_demo\)\n") self.assertRegex( rep, r"\ncompany_id:\s*res.company\[\d*\] \(ref.base.main_company\)\n") self.assertNotRegex(rep, r"\ndate_create:") self.assertRegex(rep, r"\nlogin:\s*u?'demo'\n") self.assertRegex( rep, r"\npartner_id:\s*res.partner\[\d*\] \(ref.base.partner_demo\)\n") self.assertRegex(rep, r"\nbase: /[^\n]*demo\.xml:\d+")
def test_repr_all_data(self): if odoo_repl.xml_thread: odoo_repl.xml_thread.join() for xml_id in odoo_repl.sources.xml_records.copy(): try: record = self.real_env.ref(str(xml_id)) except ValueError: if xml_id.module == "base" and xml_id.name.startswith( "module_"): # These are not always present in Odoo 12+. # Maybe they're paid modules that are removed when the module # list is updated? continue print("\n\nHad trouble retrieving record {}. " "Maybe you need to run an update?\n".format(xml_id)) raise try: self.assertTrue(odoo_repl.odoo_repr(record)) except Exception: print("\n\nFailed on record {}\n".format(xml_id)) raise
def test_record_repr_works_if_unprivileged(self): user = cast("odoo.models.ResUsers", self.ref.base.public_user) odoo_repr(util.with_user(self.u.admin, user))