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.

177 lines
6.8 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 datetime import date
  25. class Base_Test_passport(TransactionCase):
  26. """Simple test creating a passport
  27. This is a base class for passport test cases.
  28. Inherit from this and setup values.
  29. """
  30. def setUp(self, vals=None):
  31. """
  32. Setting up passport.
  33. """
  34. if vals is None:
  35. vals = {}
  36. # Default test values
  37. self.vals = {'name': 'This is a test passport name',
  38. 'number': 'A200124789',
  39. 'country_id': 1,
  40. 'expiration_date': date(2013, 11, 14),
  41. 'birth_date': date(1980, 11, 21),
  42. 'gender': 'male',
  43. }
  44. super(Base_Test_passport, self).setUp()
  45. # Overwrite vals if needed
  46. self.vals = dict(self.vals.items() + vals.items())
  47. # Create the passport object; we will be testing this, so store in self
  48. res_passport = self.registry('res.passport')
  49. self.passport_id = res_passport.create(
  50. self.cr, self.uid, self.vals, context=None
  51. )
  52. def test_passport(self):
  53. """
  54. Checking the passport creation.
  55. """
  56. res_passport = self.registry('res.passport')
  57. passport_obj = res_passport.browse(
  58. self.cr, self.uid, self.passport_id, context=None
  59. )
  60. for field in self.vals:
  61. val = passport_obj[field]
  62. if type(val) == browse_record:
  63. self.assertEquals(self.vals[field], val.id,
  64. "IDs for %s don't match: (%i != %i)" %
  65. (field, self.vals[field], val.id))
  66. else:
  67. self.assertEquals(str(self.vals[field]), str(val),
  68. "Values for %s don't match: (%s != %s)" %
  69. (field, str(self.vals[field]), str(val)))
  70. class Test_passport_bad(Base_Test_passport):
  71. """Simple test creating a passport, test against bad values"""
  72. def setUp(self):
  73. """
  74. Setting up passport, then changing the values to test against.
  75. """
  76. super(Test_passport_bad, self).setUp()
  77. # Change vals to something wrong
  78. self.vals = {
  79. 'name': 'This is the wrong passport name',
  80. 'number': 'A111111111',
  81. 'country_id': 0,
  82. 'expiration_date': date(1999, 11, 14),
  83. 'birth_date': date(1999, 11, 21),
  84. 'gender': '',
  85. }
  86. def test_passport(self):
  87. """
  88. Checking the passport creation, assertions should all be false.
  89. """
  90. res_passport = self.registry('res.passport')
  91. passport_obj = res_passport.browse(
  92. self.cr, self.uid, self.passport_id, context=None
  93. )
  94. for field in self.vals:
  95. val = passport_obj[field]
  96. if type(val) == browse_record:
  97. self.assertNotEqual(self.vals[field], val.id,
  98. "IDs for %s don't match: (%i != %i)" %
  99. (field, self.vals[field], val.id))
  100. else:
  101. self.assertNotEqual(str(self.vals[field]), str(val),
  102. "Values for %s don't match: (%s != %s)" %
  103. (field, str(self.vals[field]), str(val)))
  104. class Test_passport_name_get(TransactionCase):
  105. """Test name_get"""
  106. def setUp(self):
  107. """
  108. Setting up passport with name, country, either and none.
  109. """
  110. super(Test_passport_name_get, self).setUp()
  111. res_passport = self.registry('res.passport')
  112. res_country = self.registry('res.country')
  113. country = res_country.browse(self.cr, self.uid, 1, context=None)
  114. self.name_on_passport = 'test name'
  115. self.country_name = country.name_get()[0][1]
  116. self.both = res_passport.create(
  117. self.cr, self.uid, {'name': self.name_on_passport,
  118. 'country_id': country.id, },
  119. context=None)
  120. self.name_only = res_passport.create(
  121. self.cr, self.uid, {'name': self.name_on_passport, },
  122. context=None)
  123. self.country_only = res_passport.create(
  124. self.cr, self.uid, {'country_id': country.id, },
  125. context=None)
  126. self.neither = res_passport.create(
  127. self.cr, self.uid, {},
  128. context=None)
  129. def test_passport(self):
  130. """
  131. Checking the passport creation, assertions should all be false.
  132. """
  133. res_passport = self.registry('res.passport')
  134. both_obj = res_passport.browse(
  135. self.cr, self.uid, self.both, context=None
  136. )
  137. name_only = res_passport.browse(
  138. self.cr, self.uid, self.name_only, context=None
  139. )
  140. country_only = res_passport.browse(
  141. self.cr, self.uid, self.country_only, context=None
  142. )
  143. neither = res_passport.browse(
  144. self.cr, self.uid, self.neither, context=None
  145. )
  146. self.assertEquals(
  147. both_obj.name_get()[0][1],
  148. ' | '.join((self.country_name, self.name_on_passport)),
  149. 'Error in passport name_get() with both country name and name on '
  150. 'passport.'
  151. )
  152. self.assertEquals(
  153. name_only.name_get()[0][1], self.name_on_passport,
  154. 'Error in passport name_get() with only name on passport.'
  155. )
  156. self.assertEquals(
  157. country_only.name_get()[0][1], self.country_name,
  158. 'Error in passport name_get() with only name of country.'
  159. )
  160. self.assertEquals(
  161. neither.name_get()[0][1], '',
  162. 'Error in passport name_get() with neither country name nor name '
  163. 'on passport.'
  164. )