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.

54 lines
1.8 KiB

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