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.

176 lines
6.5 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={}):
  32. """
  33. Setting up passport.
  34. """
  35. # Default test values
  36. self.vals = {'name': 'This is a test passport name',
  37. 'number': 'A200124789',
  38. 'country_id': 1,
  39. 'expiration_date': date(2013, 11, 14),
  40. 'birth_date': date(1980, 11, 21),
  41. 'gender': 'male',
  42. }
  43. super(Base_Test_passport, self).setUp()
  44. # Overwrite vals if needed
  45. self.vals = dict(self.vals.items() + vals.items())
  46. # Create the passport object; we will be testing this, so store in self
  47. res_passport = self.registry('res.passport')
  48. self.passport_id = res_passport.create(
  49. self.cr, self.uid, self.vals, context=None)
  50. def test_passport(self):
  51. """
  52. Checking the passport creation.
  53. """
  54. res_passport = self.registry('res.passport')
  55. passport_obj = res_passport.browse(
  56. self.cr, self.uid, self.passport_id, context=None)
  57. for field in self.vals:
  58. val = passport_obj[field]
  59. if isinstance(val, BaseModel):
  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(str(self.vals[field]), str(val),
  65. "Values for %s don't match: (%s != %s)" %
  66. (field, str(self.vals[field]), str(val)))
  67. class Test_passport_bad(Base_Test_passport):
  68. """
  69. Simple test creating a passport, test against bad values
  70. """
  71. def setUp(self):
  72. """
  73. Setting up passport, then changing the values to test against.
  74. """
  75. super(Test_passport_bad, self).setUp()
  76. # Change vals to something wrong
  77. self.vals = {
  78. 'name': 'This is the wrong passport name',
  79. 'number': 'A111111111',
  80. 'country_id': 0,
  81. 'expiration_date': date(1999, 11, 14),
  82. 'birth_date': date(1999, 11, 21),
  83. 'gender': '',
  84. }
  85. def test_passport(self):
  86. """
  87. Checking the passport creation, assertions should all be false.
  88. """
  89. res_passport = self.registry('res.passport')
  90. passport_obj = res_passport.browse(
  91. self.cr, self.uid, self.passport_id, context=None)
  92. for field in self.vals:
  93. val = passport_obj[field]
  94. if isinstance(val, BaseModel):
  95. self.assertNotEqual(self.vals[field], val.id,
  96. "IDs for %s don't match: (%i != %i)" %
  97. (field, self.vals[field], val.id))
  98. else:
  99. self.assertNotEqual(str(self.vals[field]), str(val),
  100. "Values for %s don't match: (%s != %s)" %
  101. (field, str(self.vals[field]), str(val)))
  102. class Test_passport_name_get(TransactionCase):
  103. """
  104. Test name_get
  105. """
  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. name_only = res_passport.browse(
  137. self.cr, self.uid, self.name_only, context=None)
  138. country_only = res_passport.browse(
  139. self.cr, self.uid, self.country_only, context=None)
  140. neither = res_passport.browse(
  141. self.cr, self.uid, self.neither, context=None)
  142. self.assertEquals(
  143. both_obj.name_get()[0][1],
  144. ' | '.join((self.country_name, self.name_on_passport)),
  145. 'Error in passport name_get() with both country name and name on '
  146. 'passport.'
  147. )
  148. self.assertEquals(
  149. name_only.name_get()[0][1], self.name_on_passport,
  150. 'Error in passport name_get() with only name on passport.'
  151. )
  152. self.assertEquals(
  153. country_only.name_get()[0][1], self.country_name,
  154. 'Error in passport name_get() with only name of country.'
  155. )
  156. self.assertEquals(
  157. neither.name_get()[0][1], '',
  158. 'Error in passport name_get() with neither country name nor name '
  159. 'on passport.'
  160. )