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.

53 lines
1.8 KiB

  1. # Copyright 2015-2018 Tecnativa - Jairo Llopis
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.exceptions import ValidationError
  4. from odoo.tests.common import TransactionCase
  5. class TestIrExportsCase(TransactionCase):
  6. def test_create_with_basic_data(self):
  7. """Emulate creation from original form.
  8. This form is handled entirely client-side, and lacks some required
  9. field values.
  10. """
  11. # Emulate creation from JsonRpc, without model_id and field#_id
  12. data = {
  13. "name": u"Test éxport",
  14. "resource": "ir.exports",
  15. "export_fields": [
  16. [0, 0, {"name": "export_fields"}],
  17. [0, 0, {"name": "export_fields/create_uid"}],
  18. [0, 0, {"name": "export_fields/create_date"}],
  19. [0, 0, {"name": "export_fields/field1_id"}],
  20. ],
  21. }
  22. record = self.env["ir.exports"].create(data)
  23. self.assertEqual(record.model_id.model, data["resource"])
  24. def test_create_without_model(self):
  25. """Creating a record without ``model_id`` and ``resource`` fails."""
  26. IrExports = self.env["ir.exports"]
  27. model = IrExports._get_model_id("res.partner")
  28. # Creating with resource
  29. record = IrExports.create({
  30. "name": "some",
  31. "resource": model.model,
  32. })
  33. self.assertEqual(record.model_id, model)
  34. # Creating with model_id
  35. record = IrExports.create({
  36. "name": "some",
  37. "model_id": model.id,
  38. })
  39. self.assertEqual(record.resource, model.model)
  40. # Creating without anyone
  41. with self.assertRaises(ValidationError):
  42. IrExports.create({
  43. "name": "some",
  44. })