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.

65 lines
2.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 Creu Blanca <https://creublanca.es/>
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. from openerp.tests import common
  5. import logging
  6. from openerp.exceptions import ValidationError
  7. try:
  8. from stdnum.iso7064 import mod_97_10
  9. from stdnum.iso7064 import mod_37_2, mod_37_36
  10. from stdnum.iso7064 import mod_11_2, mod_11_10
  11. from stdnum import luhn, damm, verhoeff
  12. except(ImportError, IOError) as err:
  13. logging.info(err)
  14. class TestSequenceCheckDigit(common.TransactionCase):
  15. def get_sequence(self, method):
  16. return self.env['ir.sequence'].create({
  17. 'name': 'Test sequence',
  18. 'implementation': 'standard',
  19. 'check_digit_formula': method,
  20. 'padding': '5'
  21. })
  22. def test_luhn(self):
  23. sequence = self.get_sequence('luhn')
  24. self.assertTrue(luhn.validate(sequence.next_by_id()))
  25. def test_damm(self):
  26. sequence = self.get_sequence('damm')
  27. self.assertTrue(damm.validate(sequence.next_by_id()))
  28. def test_verhoeff(self):
  29. sequence = self.get_sequence('verhoeff')
  30. self.assertTrue(verhoeff.validate(sequence.next_by_id()))
  31. def test_mod_11_2(self):
  32. sequence = self.get_sequence('ISO7064_11_2')
  33. self.assertTrue(mod_11_2.validate(sequence.next_by_id()))
  34. def test_mod11_10(self):
  35. sequence = self.get_sequence('ISO7064_11_10')
  36. self.assertTrue(mod_11_10.validate(sequence.next_by_id()))
  37. def test_validation(self):
  38. sequence = self.get_sequence('ISO7064_11_10')
  39. with self.assertRaises(ValidationError):
  40. sequence.prefix = 'A'
  41. sequence.prefix = ''
  42. def test_mod37_2(self):
  43. sequence = self.get_sequence('ISO7064_37_2')
  44. sequence.prefix = 'A'
  45. self.assertTrue(mod_37_2.validate(sequence.next_by_id()))
  46. def test_mod37_36(self):
  47. sequence = self.get_sequence('ISO7064_37_36')
  48. self.assertTrue(mod_37_36.validate(sequence.next_by_id()))
  49. def test_mod97_10(self):
  50. sequence = self.get_sequence('ISO7064_97_10')
  51. self.assertTrue(mod_97_10.validate(sequence.next_by_id()))