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