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.

164 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.osv.orm import browse_record
  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(self.cr, self.uid, self.vals, context=None)
  49. def test_passport(self):
  50. """
  51. Checking the passport creation.
  52. """
  53. res_passport = self.registry('res.passport')
  54. passport_obj = res_passport.browse(self.cr, self.uid, self.passport_id, context=None)
  55. for field in self.vals:
  56. val = passport_obj[field]
  57. if type(val) == browse_record:
  58. self.assertEquals(self.vals[field], val.id,
  59. "IDs for %s don't match: (%i != %i)" %
  60. (field, self.vals[field], val.id))
  61. else:
  62. self.assertEquals(str(self.vals[field]), str(val),
  63. "Values for %s don't match: (%s != %s)" %
  64. (field, str(self.vals[field]), str(val)))
  65. class Test_passport_bad(Base_Test_passport):
  66. """
  67. Simple test creating a passport, test against bad values
  68. """
  69. def setUp(self):
  70. """
  71. Setting up passport, then changing the values to test against.
  72. """
  73. super(Test_passport_bad, self).setUp()
  74. # Change vals to something wrong
  75. self.vals = {
  76. 'name': 'This is the wrong passport name',
  77. 'number': 'A111111111',
  78. 'country_id': 0,
  79. 'expiration_date': date(1999, 11, 14),
  80. 'birth_date': date(1999, 11, 21),
  81. 'gender': '',
  82. }
  83. def test_passport(self):
  84. """
  85. Checking the passport creation, assertions should all be false.
  86. """
  87. res_passport = self.registry('res.passport')
  88. passport_obj = res_passport.browse(self.cr, self.uid, self.passport_id, context=None)
  89. for field in self.vals:
  90. val = passport_obj[field]
  91. if type(val) == browse_record:
  92. self.assertNotEqual(self.vals[field], val.id,
  93. "IDs for %s don't match: (%i != %i)" %
  94. (field, self.vals[field], val.id))
  95. else:
  96. self.assertNotEqual(str(self.vals[field]), str(val),
  97. "Values for %s don't match: (%s != %s)" %
  98. (field, str(self.vals[field]), str(val)))
  99. class Test_passport_name_get(TransactionCase):
  100. """
  101. Test name_get
  102. """
  103. def setUp(self):
  104. """
  105. Setting up passport with name, country, either and none.
  106. """
  107. super(Test_passport_name_get, self).setUp()
  108. res_passport = self.registry('res.passport')
  109. res_country = self.registry('res.country')
  110. country = res_country.browse(self.cr, self.uid, 1, context=None)
  111. self.name_on_passport = 'test name'
  112. self.country_name = country.name_get()[0][1]
  113. self.both = res_passport.create(
  114. self.cr, self.uid, {'name': self.name_on_passport,
  115. 'country_id': country.id, },
  116. context=None)
  117. self.name_only = res_passport.create(
  118. self.cr, self.uid, {'name': self.name_on_passport, },
  119. context=None)
  120. self.country_only = res_passport.create(
  121. self.cr, self.uid, {'country_id': country.id, },
  122. context=None)
  123. self.neither = res_passport.create(
  124. self.cr, self.uid, {},
  125. context=None)
  126. def test_passport(self):
  127. """
  128. Checking the passport creation, assertions should all be false.
  129. """
  130. res_passport = self.registry('res.passport')
  131. both_obj = res_passport.browse(self.cr, self.uid, self.both, context=None)
  132. name_only = res_passport.browse(self.cr, self.uid, self.name_only, context=None)
  133. country_only = res_passport.browse(self.cr, self.uid, self.country_only, context=None)
  134. neither = res_passport.browse(self.cr, self.uid, self.neither, context=None)
  135. self.assertEquals(
  136. both_obj.name_get()[0][1],
  137. ' | '.join((self.country_name, self.name_on_passport)),
  138. 'Error in passport name_get() with both country name and name on '
  139. 'passport.'
  140. )
  141. self.assertEquals(
  142. name_only.name_get()[0][1], self.name_on_passport,
  143. 'Error in passport name_get() with only name on passport.'
  144. )
  145. self.assertEquals(
  146. country_only.name_get()[0][1], self.country_name,
  147. 'Error in passport name_get() with only name of country.'
  148. )
  149. self.assertEquals(
  150. neither.name_get()[0][1], '',
  151. 'Error in passport name_get() with neither country name nor name '
  152. 'on passport.'
  153. )