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.

175 lines
6.7 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={}):
  31. """
  32. Setting up passport.
  33. """
  34. # Default test values
  35. self.vals = {'name': 'This is a test passport name',
  36. 'number': 'A200124789',
  37. 'country_id': 1,
  38. 'expiration_date': date(2013, 11, 14),
  39. 'birth_date': date(1980, 11, 21),
  40. 'gender': 'male',
  41. }
  42. super(Base_Test_passport, self).setUp()
  43. # Overwrite vals if needed
  44. self.vals = dict(self.vals.items() + vals.items())
  45. # Create the passport object; we will be testing this, so store in self
  46. res_passport = self.registry('res.passport')
  47. self.passport_id = res_passport.create(
  48. self.cr, self.uid, self.vals, context=None
  49. )
  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. )
  58. for field in self.vals:
  59. val = passport_obj[field]
  60. if type(val) == browse_record:
  61. self.assertEquals(self.vals[field], val.id,
  62. "IDs for %s don't match: (%i != %i)" %
  63. (field, self.vals[field], val.id))
  64. else:
  65. self.assertEquals(str(self.vals[field]), str(val),
  66. "Values for %s don't match: (%s != %s)" %
  67. (field, str(self.vals[field]), str(val)))
  68. class Test_passport_bad(Base_Test_passport):
  69. """Simple test creating a passport, test against bad values"""
  70. def setUp(self):
  71. """
  72. Setting up passport, then changing the values to test against.
  73. """
  74. super(Test_passport_bad, self).setUp()
  75. # Change vals to something wrong
  76. self.vals = {
  77. 'name': 'This is the wrong passport name',
  78. 'number': 'A111111111',
  79. 'country_id': 0,
  80. 'expiration_date': date(1999, 11, 14),
  81. 'birth_date': date(1999, 11, 21),
  82. 'gender': '',
  83. }
  84. def test_passport(self):
  85. """
  86. Checking the passport creation, assertions should all be false.
  87. """
  88. res_passport = self.registry('res.passport')
  89. passport_obj = res_passport.browse(
  90. self.cr, self.uid, self.passport_id, context=None
  91. )
  92. for field in self.vals:
  93. val = passport_obj[field]
  94. if type(val) == browse_record:
  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. """Test name_get"""
  104. def setUp(self):
  105. """
  106. Setting up passport with name, country, either and none.
  107. """
  108. super(Test_passport_name_get, self).setUp()
  109. res_passport = self.registry('res.passport')
  110. res_country = self.registry('res.country')
  111. country = res_country.browse(self.cr, self.uid, 1, context=None)
  112. self.name_on_passport = 'test name'
  113. self.country_name = country.name_get()[0][1]
  114. self.both = res_passport.create(
  115. self.cr, self.uid, {'name': self.name_on_passport,
  116. 'country_id': country.id, },
  117. context=None)
  118. self.name_only = res_passport.create(
  119. self.cr, self.uid, {'name': self.name_on_passport, },
  120. context=None)
  121. self.country_only = res_passport.create(
  122. self.cr, self.uid, {'country_id': country.id, },
  123. context=None)
  124. self.neither = res_passport.create(
  125. self.cr, self.uid, {},
  126. context=None)
  127. def test_passport(self):
  128. """
  129. Checking the passport creation, assertions should all be false.
  130. """
  131. res_passport = self.registry('res.passport')
  132. both_obj = res_passport.browse(
  133. self.cr, self.uid, self.both, context=None
  134. )
  135. name_only = res_passport.browse(
  136. self.cr, self.uid, self.name_only, context=None
  137. )
  138. country_only = res_passport.browse(
  139. self.cr, self.uid, self.country_only, context=None
  140. )
  141. neither = res_passport.browse(
  142. self.cr, self.uid, self.neither, context=None
  143. )
  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. )