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