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_formatstring.py 1.4KB

12345678910111213141516171819202122232425262728
  1. import unittest
  2. from lodel.leapi.datahandlers.datas import FormatString
  3. from lodel.editorial_model.components import EmClass
  4. class FormatStringTestCase(unittest.TestCase):
  5. def test_construct_data(self):
  6. test_class = EmClass('testing',display_name='testing class')
  7. test_class.new_field('field1', 'varchar')
  8. test_class.new_field('field2', 'varchar')
  9. test_formatstring = FormatString('%s_%s',['field1', 'field2'], max_length=10)
  10. formatted_string_value = test_formatstring.construct_data(test_class, 'field', {'field1': 'o'*5, 'field2': 'k'*4}, '')
  11. self.assertEqual('%s_%s' % ('o'*5, 'k'*4), formatted_string_value)
  12. def test_construct_too_long_data(self):
  13. test_class = EmClass('testing', display_name='testing class')
  14. test_class.new_field('field1', 'varchar')
  15. test_class.new_field('field2', 'varchar')
  16. test_formatstring = FormatString('%s-%s', ['field2', 'field1'], max_length=10)
  17. formatted_string_value = test_formatstring.construct_data(test_class, 'field', {'field1': 'o'*300, 'field2': 'k'*500},'')
  18. test_value = '%s-%s' % ('k'*500, 'o'*300)
  19. self.assertNotEqual(test_value, formatted_string_value)
  20. self.assertTrue(formatted_string_value in test_value)
  21. self.assertTrue(len(formatted_string_value) == test_formatstring.max_length)
  22. self.assertEqual(formatted_string_value, test_value[:test_formatstring.max_length])