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_varcharlist.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import unittest
  2. from lodel.leapi.datahandlers.datas import VarcharList as Testee
  3. from lodel.leapi.datahandlers.exceptions import LodelDataHandlerException
  4. from lodel.exceptions import LodelException
  5. class VarcharListTestCase(unittest.TestCase):
  6. string = 'a simple string for testing purpose'
  7. expected_result = string.split(' ')
  8. def test_base_type_is_varchar(self):
  9. '''base_type property has to be equal to \'varchar\''''
  10. self.assertEqual(Testee.base_type, 'varchar')
  11. def test_help_property_str_is_set(self):
  12. '''Help property must be set and be a string'''
  13. self.assertEqual(type(Testee.help), str)
  14. def test_default_delimiter_is_set(self):
  15. '''The DataHandler has to provide a default delimiter if not provided'''
  16. testee = Testee()
  17. self.assertTrue(hasattr(testee, 'delimiter'))
  18. def test_set_custom_delimiter_success(self):
  19. '''The custom delimiter isn't set as expected'''
  20. delimiter = ';'
  21. testee = Testee(delimiter=delimiter)
  22. self.assertEqual(delimiter, testee.delimiter)
  23. def test_custom_delimiter_not_string_raises_error(self):
  24. '''DataHandler\'s init should raise an exception on trying to pass incorrect type delimiter'''
  25. self.assertRaises(LodelException, Testee, 123456789)
  26. def test_construct_datas_success(self):
  27. '''Basic usage of VarcharList doesn't behave as expected'''
  28. string = 'a b c'
  29. testee = Testee()
  30. actual_result = testee.construct_data(None, None, None, self.string)
  31. self.assertEqual(self.expected_result, actual_result)
  32. def test_constuct_datas_with_custom_delimiter_success(self):
  33. '''The use of custom delimiter doesn't work as supposed to !'''
  34. delimiter = ';'
  35. string = self.string.replace(' ', delimiter)
  36. testee = Testee(delimiter=delimiter)
  37. actual_result = testee.construct_data(None, None, None, string)
  38. self.assertEqual(self.expected_result, actual_result)