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.

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