No Description
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.

test_regex.py 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import unittest
  2. from lodel.leapi.datahandlers.datas import Regex, Varchar, Integer
  3. class RegexTestCase(unittest.TestCase):
  4. def test_check_correct_data_value(self):
  5. test_value = '126.205.255.12'
  6. test_regex = Regex('^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$',
  7. max_length=100)
  8. value, error = test_regex.check_data_value(test_value)
  9. self.assertIsNone(error)
  10. self.assertEqual(value, test_value)
  11. def test_check_bad_data_value(self):
  12. test_regex = Regex('^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$',
  13. max_length=15)
  14. for test_value in ['800.9.10.5', 'test_string_value', '999.999.999.999']:
  15. value, error = test_regex.check_data_value(test_value)
  16. self.assertEqual(value, '')
  17. self.assertIsNotNone(error)
  18. def test_check_max_length(self):
  19. test_max_length = 15
  20. test_regex = Regex('[a-z]+8?', max_length=15)
  21. for test_value in ['cccccc8', 'ccccccccccccccccccccccccccccccccc8']:
  22. value, error = test_regex.check_data_value(test_value)
  23. if len(test_value)>test_max_length:
  24. self.assertEqual(value, '')
  25. self.assertIsNotNone(error)
  26. else:
  27. self.assertIsNone(error)
  28. self.assertEqual(value, test_value)
  29. def test_can_override(self):
  30. test_regex = Regex('^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$',
  31. max_length=15)
  32. for test_varchar in [Varchar(), Varchar(max_length=15), Varchar(max_length=9)]:
  33. if test_regex.max_length == test_varchar.max_length:
  34. self.assertTrue(test_regex.can_override(test_varchar))
  35. else:
  36. self.assertFalse(test_regex.can_override(test_varchar))
  37. def test_cant_override(self):
  38. test_regex = Regex('^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$',
  39. max_length=15)
  40. test_int = Integer()
  41. self.assertFalse(test_regex.can_override(test_int))