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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #
  2. # This file is part of Lodel 2 (https://github.com/OpenEdition)
  3. #
  4. # Copyright (C) 2015-2017 Cléo UMS-3287
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published
  8. # by the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import unittest
  20. from lodel.leapi.datahandlers.datas import VarcharList as Testee
  21. from lodel.leapi.datahandlers.exceptions import LodelDataHandlerException
  22. from lodel.exceptions import LodelException
  23. class VarcharListTestCase(unittest.TestCase):
  24. string = 'a simple string for testing purpose'
  25. expected_result = string.split(' ')
  26. def test_base_type_is_varchar(self):
  27. '''base_type property has to be equal to \'varchar\''''
  28. self.assertEqual(Testee.base_type, 'varchar')
  29. def test_help_property_str_is_set(self):
  30. '''Help property must be set and be a string'''
  31. self.assertEqual(type(Testee.help), str)
  32. def test_default_delimiter_is_set(self):
  33. '''The DataHandler has to provide a default delimiter if not provided'''
  34. testee = Testee()
  35. self.assertTrue(hasattr(testee, 'delimiter'))
  36. def test_set_custom_delimiter_success(self):
  37. '''The custom delimiter isn't set as expected'''
  38. delimiter = ';'
  39. testee = Testee(delimiter=delimiter)
  40. self.assertEqual(delimiter, testee.delimiter)
  41. def test_custom_delimiter_not_string_raises_error(self):
  42. '''DataHandler\'s init should raise an exception on trying to pass incorrect type delimiter'''
  43. self.assertRaises(LodelException, Testee, 123456789)
  44. def test_construct_datas_success(self):
  45. '''Basic usage of VarcharList doesn't behave as expected'''
  46. string = 'a b c'
  47. testee = Testee()
  48. actual_result = testee.construct_data(None, None, None, self.string)
  49. self.assertEqual(self.expected_result, actual_result)
  50. def test_constuct_datas_with_custom_delimiter_success(self):
  51. '''The use of custom delimiter doesn't work as supposed to !'''
  52. delimiter = ';'
  53. string = self.string.replace(' ', delimiter)
  54. testee = Testee(delimiter=delimiter)
  55. actual_result = testee.construct_data(None, None, None, string)
  56. self.assertEqual(self.expected_result, actual_result)