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
5.1 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Authors: Nemry Jonathan
  5. # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
  6. # All Rights Reserved
  7. #
  8. # WARNING: This program as such is intended to be used by professional
  9. # programmers who take the whole responsibility of assessing all potential
  10. # consequences resulting from its eventual inadequacies and bugs.
  11. # End users who are looking for a ready-to-use solution with commercial
  12. # guarantees and support are strongly advised to contact a Free Software
  13. # Service Company.
  14. #
  15. # This program is Free Software; you can redistribute it and/or
  16. # modify it under the terms of the GNU General Public License
  17. # as published by the Free Software Foundation; either version 2
  18. # of the License, or (at your option) any later version.
  19. #
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program; if not, write to the Free Software
  27. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  28. #
  29. ##############################################################################
  30. import openerp.tests.common as common
  31. class test_partner_firstname(common.TransactionCase):
  32. def setUp(self):
  33. super(test_partner_firstname, self).setUp()
  34. self.registry('ir.model').clear_caches()
  35. self.registry('ir.model.data').clear_caches()
  36. self.user_model = self.registry("res.users")
  37. self.partner_model = self.registry("res.partner")
  38. self.fields_partner = {'lastname': 'lastname', 'firstname': 'firstname'}
  39. self.fields_user = {'name': 'lastname', 'login': 'v5Ue4Tql0Pm67KX05g25A'}
  40. def test_copy_partner(self):
  41. cr, uid = self.cr, self.uid
  42. res_id = self.partner_model.create(cr, uid, self.fields_partner, context={})
  43. res_id = self.partner_model.copy(cr, uid, res_id, default={}, context={})
  44. vals = self.partner_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context={})[0]
  45. self.assertEqual(vals['name'] == "lastname (copy) firstname" and
  46. vals['lastname'] == 'lastname (copy)' and
  47. vals['firstname'] == 'firstname', True, 'Copy of the partner failed with wrong values')
  48. def test_copy_user(self):
  49. cr, uid = self.cr, self.uid
  50. # create a user
  51. res_id = self.user_model.create(cr, uid, self.fields_user, context={})
  52. # get the related partner id and add it a firstname
  53. flds = self.user_model.read(cr, uid, [res_id], ['partner_id'], context={})[0]
  54. self.partner_model.write(cr, uid, flds['partner_id'][0], {'firstname':'firstname'}, context={})
  55. # copy the user and compare result
  56. res_id = self.user_model.copy(cr, uid, res_id, default={}, context={})
  57. vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context={})[0]
  58. self.assertEqual(vals['name'] == "lastname (copy) firstname" and
  59. vals['lastname'] == 'lastname (copy)' and
  60. vals['firstname'] == 'firstname', True, 'Copy of the user failed with wrong values')
  61. def test_update_user_lastname(self):
  62. cr, uid = self.cr, self.uid
  63. # create a user
  64. res_id = self.user_model.create(cr, uid, self.fields_user, context={})
  65. # get the related partner id and add it a firstname
  66. flds = self.user_model.read(cr, uid, [res_id], ['partner_id'], context={})[0]
  67. self.partner_model.write(cr, uid, flds['partner_id'][0], {'firstname':'firstname'}, context={})
  68. self.user_model.write(cr, uid, res_id, {'name': 'change firstname'}, context={})
  69. vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context={})[0]
  70. self.assertEqual(vals['name'] == "change firstname" and
  71. vals['lastname'] == 'change' and
  72. vals['firstname'] == 'firstname', True, 'Update of the user lastname failed with wrong values')
  73. def test_update_user_firstname(self):
  74. cr, uid = self.cr, self.uid
  75. # create a user
  76. res_id = self.user_model.create(cr, uid, self.fields_user, context={})
  77. # get the related partner id and add it a firstname
  78. flds = self.user_model.read(cr, uid, [res_id], ['partner_id'], context={})[0]
  79. self.partner_model.write(cr, uid, flds['partner_id'][0], {'firstname':'firstname'}, context={})
  80. self.user_model.write(cr, uid, res_id, {'name': 'lastname other'}, context={})
  81. vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context={})[0]
  82. self.assertEqual(vals['name'] == "lastname other" and
  83. vals['lastname'] == 'lastname other' and
  84. vals['firstname'] == False, True, 'Update of the user firstname failed with wrong values')
  85. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: