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.

94 lines
2.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # © <YEAR(S)> <AUTHOR(S)>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp.tests.common import TransactionCase
  5. class TestParser(TransactionCase):
  6. def test_getting_parser(self):
  7. expected_parser = [
  8. u'active',
  9. (u'category_id', [u'name']),
  10. (u'child_ids', [(
  11. u'child_ids', [u'name']),
  12. (u'country_id', [u'code', u'name']),
  13. u'email', u'id',
  14. u'name'
  15. ]),
  16. u'color',
  17. u'comment',
  18. (u'country_id', [u'code', u'name']),
  19. u'credit_limit',
  20. u'lang',
  21. u'name']
  22. exporter = self.env.ref('base_jsonify.ir_exp_partner')
  23. parser = exporter.get_json_parser()
  24. self.assertEqual(parser, expected_parser)
  25. # modify an ir.exports_line to put an alias for a field
  26. self.env.ref('base_jsonify.category_id_name').write({
  27. 'alias': 'category_id:category/name'
  28. })
  29. expected_parser[1] = (u'category_id:category', [u'name'])
  30. parser = exporter.get_json_parser()
  31. self.assertEqual(parser, expected_parser)
  32. def test_json_export(self):
  33. parser = [
  34. u'lang',
  35. u'comment',
  36. u'credit_limit',
  37. u'name',
  38. u'color',
  39. (u'child_ids:children', [
  40. (u'child_ids:children', [u'name']),
  41. u'email',
  42. (u'country_id:country', [u'code', u'name']),
  43. u'name',
  44. u'id',
  45. ]),
  46. (u'country_id:country', [u'code', u'name']),
  47. u'active',
  48. (u'category_id', [u'name'])
  49. ]
  50. partner = self.env['res.partner'].create({
  51. 'name': 'Akretion',
  52. 'country_id': self.env.ref('base.fr').id,
  53. 'category_id': [(0, 0, {'name': 'Inovator'})],
  54. 'child_ids': [
  55. (0, 0, {
  56. 'name': 'Sebatien Beau',
  57. 'country_id': self.env.ref('base.fr').id
  58. })
  59. ]
  60. })
  61. expected_json = [{
  62. u'lang': False,
  63. u'comment': False,
  64. u'credit_limit': 0.0,
  65. u'name': u'Akretion',
  66. u'color': 0,
  67. u'country': {
  68. u'code': u'FR',
  69. u'name': u'France'
  70. },
  71. u'active': True,
  72. u'category_id': [
  73. {u'name': u'Inovator'}
  74. ],
  75. u'children': [{
  76. u'id': partner.child_ids.id,
  77. u'country': {
  78. u'code': u'FR',
  79. u'name': u'France'
  80. },
  81. u'children': [],
  82. u'name': u'Sebatien Beau',
  83. u'email': False
  84. }]
  85. }]
  86. json_partner = partner.jsonify(parser)
  87. self.assertDictEqual(json_partner[0], expected_json[0])