You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.2 KiB

  1. # Copyright 2018 Simone Rubino - Agile Business Group
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo.exceptions import UserError
  4. from odoo.tests.common import TransactionCase
  5. class TestQuickCreate(TransactionCase):
  6. def setUp(self, *args, **kwargs):
  7. super(TestQuickCreate, self).setUp()
  8. model_model = self.env['ir.model']
  9. self.partner_model = model_model.search([
  10. ('model', '=', 'res.partner')])
  11. def test_quick_create(self):
  12. partner_id = self.env['res.partner'].name_create('TEST partner')
  13. self.assertEqual(bool(partner_id), True)
  14. # Setting the flag, patches the method
  15. self.partner_model.avoid_quick_create = True
  16. with self.assertRaises(UserError):
  17. self.env['res.partner'].name_create('TEST partner')
  18. # Unsetting the flag, unpatches the method
  19. self.partner_model.avoid_quick_create = False
  20. partner_id = self.env['res.partner'].name_create('TEST partner')
  21. self.assertEqual(bool(partner_id), True)
  22. def test_create_model(self):
  23. model_id = self.env['ir.model'].create({'name': 'Test',
  24. 'model': 'x_test_model'})
  25. self.assertEqual(bool(model_id), True)