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.

105 lines
4.1 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2013 Savoir-faire Linux
  6. # (<http://www.savoirfairelinux.com>).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp.tests.common import TransactionCase
  23. from openerp.osv.orm import browse_record
  24. from openerp.tools import ustr
  25. class Base_Test_function(TransactionCase):
  26. """
  27. Simple test creating a function
  28. This is a base class for function test cases.
  29. Inherit from this and setup values.
  30. """
  31. def setUp(self, vals=None):
  32. """
  33. Setting up function.
  34. """
  35. if not vals:
  36. vals = {}
  37. # Default test values
  38. self.vals = {
  39. 'name': u'This is a test function name with uniödé',
  40. 'acronym': u'This is a test function acronym with uniödé',
  41. }
  42. super(Base_Test_function, self).setUp()
  43. self.vals = dict(self.vals.items() + vals.items())
  44. # Create the function object; we will be testing this, so store in self
  45. function_pool = self.registry('res.partner.function')
  46. self.function_id = function_pool.create(
  47. self.cr, self.uid, self.vals, context=None
  48. )
  49. def test_function(self):
  50. """
  51. Checking the function creation.
  52. """
  53. function_function = self.registry('res.partner.function')
  54. function_obj = function_function.browse(
  55. self.cr, self.uid, self.function_id, context=None
  56. )
  57. for field in self.vals:
  58. val = function_obj[field]
  59. if type(val) == browse_record:
  60. self.assertEquals(self.vals[field], val.id,
  61. "IDs for %s don't match: (%i != %i)" %
  62. (field, self.vals[field], val.id))
  63. else:
  64. self.assertEquals(ustr(self.vals[field]), ustr(val),
  65. "Values for %s don't match: (%s != %s)" %
  66. (field, ustr(self.vals[field]), ustr(val)))
  67. class Test_function_bad(Base_Test_function):
  68. """
  69. Simple test creating a function, test against bad values
  70. """
  71. def setUp(self):
  72. """
  73. Setting up function, then changing the values to test against.
  74. """
  75. super(Test_function_bad, self).setUp()
  76. # Change vals to something wrong
  77. self.vals = {'name': 'This is the wrong function name',
  78. 'acronym': 'This is the wrong function acronym',
  79. }
  80. def test_function(self):
  81. """
  82. Checking the function creation, assertions should all be false.
  83. """
  84. function_function = self.registry('res.partner.function')
  85. function_obj = function_function.browse(
  86. self.cr, self.uid, self.function_id, context=None
  87. )
  88. for field in self.vals:
  89. val = function_obj[field]
  90. if type(val) == browse_record:
  91. self.assertNotEqual(self.vals[field], val.id,
  92. "IDs for %s don't match: (%i != %i)" %
  93. (field, self.vals[field], val.id))
  94. else:
  95. self.assertNotEqual(ustr(self.vals[field]), ustr(val),
  96. "Values for %s don't match: (%s != %s)" %
  97. (field, ustr(self.vals[field]), ustr(val)))