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.

109 lines
4.3 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. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: