瀏覽代碼

Merging resolution with settings validator

m.orban 8 年之前
父節點
當前提交
7c99981ad1

+ 4
- 0
lodel/leapi/datahandlers/datas_base.py 查看文件

114
     
114
     
115
     def _check_data_value(self, value):
115
     def _check_data_value(self, value):
116
         error = None
116
         error = None
117
+        try:
118
+            value = str(value)
119
+        except (ValueError, TypeError):
120
+            error = ValueError("The content passed to this Text field is not a convertible to a string")
117
         return value, error
121
         return value, error
118
 
122
 
119
 ##@brief Data field designed to handle Files
123
 ##@brief Data field designed to handle Files

+ 2
- 2
tests/datahandlers/test_boolean.py 查看文件

10
 
10
 
11
         # correct values
11
         # correct values
12
         for test_value in [True, False]:
12
         for test_value in [True, False]:
13
-            value, error = test_boolean._check_data_value(test_value)
13
+            value, error = test_boolean.check_data_value(test_value)
14
             self.assertIsNone(error)
14
             self.assertIsNone(error)
15
 
15
 
16
         # incorrect values
16
         # incorrect values
17
         for test_value in ['ok', 'True', 'False']:
17
         for test_value in ['ok', 'True', 'False']:
18
-            value, error = test_boolean._check_data_value(test_value)
18
+            value, error = test_boolean.check_data_value(test_value)
19
             self.assertIsNotNone(error)
19
             self.assertIsNotNone(error)
20
 
20
 
21
     def test_can_override(self):
21
     def test_can_override(self):

+ 2
- 2
tests/datahandlers/test_integer.py 查看文件

10
 
10
 
11
         # Incorrect values
11
         # Incorrect values
12
         for test_bad_value in ['ok','ceci est un test', '15.2', 15.2]:
12
         for test_bad_value in ['ok','ceci est un test', '15.2', 15.2]:
13
-            _, error = test_int._check_data_value(test_bad_value)
13
+            _, error = test_int.check_data_value(test_bad_value)
14
             self.assertIsNotNone(error)
14
             self.assertIsNotNone(error)
15
 
15
 
16
         # Correct values
16
         # Correct values
17
         for test_correct_value in [10, '15', '15.0']:
17
         for test_correct_value in [10, '15', '15.0']:
18
-            _, error = test_int._check_data_value(test_correct_value)
18
+            _, error = test_int.check_data_value(test_correct_value)
19
             self.assertIsNone(error)
19
             self.assertIsNone(error)
20
 
20
 
21
     def test_can_override(self):
21
     def test_can_override(self):

+ 3
- 3
tests/datahandlers/test_regex.py 查看文件

9
         test_value = '126.205.255.12'
9
         test_value = '126.205.255.12'
10
         test_regex = Regex('^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$',
10
         test_regex = Regex('^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$',
11
                            max_length=100)
11
                            max_length=100)
12
-        value, error = test_regex._check_data_value(test_value)
12
+        value, error = test_regex.check_data_value(test_value)
13
         self.assertIsNone(error)
13
         self.assertIsNone(error)
14
         self.assertEqual(value, test_value)
14
         self.assertEqual(value, test_value)
15
 
15
 
17
         test_regex = Regex('^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$',
17
         test_regex = Regex('^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$',
18
                            max_length=15)
18
                            max_length=15)
19
         for test_value in ['800.9.10.5', 'test_string_value', '999.999.999.999']:
19
         for test_value in ['800.9.10.5', 'test_string_value', '999.999.999.999']:
20
-            value, error = test_regex._check_data_value(test_value)
20
+            value, error = test_regex.check_data_value(test_value)
21
             self.assertEqual(value, '')
21
             self.assertEqual(value, '')
22
             self.assertIsNotNone(error)
22
             self.assertIsNotNone(error)
23
 
23
 
25
         test_max_length = 15
25
         test_max_length = 15
26
         test_regex = Regex('[a-z]+8?', max_length=15)
26
         test_regex = Regex('[a-z]+8?', max_length=15)
27
         for test_value in ['cccccc8', 'ccccccccccccccccccccccccccccccccc8']:
27
         for test_value in ['cccccc8', 'ccccccccccccccccccccccccccccccccc8']:
28
-            value, error = test_regex._check_data_value(test_value)
28
+            value, error = test_regex.check_data_value(test_value)
29
             if len(test_value)>test_max_length:
29
             if len(test_value)>test_max_length:
30
                 self.assertEqual(value, '')
30
                 self.assertEqual(value, '')
31
                 self.assertIsNotNone(error)
31
                 self.assertIsNotNone(error)

+ 15
- 0
tests/datahandlers/test_text.py 查看文件

1
+import unittest
2
+
3
+from lodel.leapi.datahandlers.datas import Text
4
+
5
+
6
+class TextTestCase(unittest.TestCase):
7
+
8
+    def test_check_data(self):
9
+        test_value = """ Ceci est un texte multiligne pour tester le check
10
+        sur le datahandler
11
+        Text
12
+        """
13
+        test_text = Text()
14
+        _, error = test_text.check_data_value(test_value)
15
+        self.assertIsNone(error)

+ 3
- 3
tests/datahandlers/test_varchar.py 查看文件

8
     def test_check_data_value(self):
8
     def test_check_data_value(self):
9
         test_varchar = Varchar(max_length=10)
9
         test_varchar = Varchar(max_length=10)
10
 
10
 
11
-        _, error = test_varchar._check_data_value("c" * 10)
11
+        _, error = test_varchar.check_data_value("c" * 10)
12
         self.assertIsNone(error)
12
         self.assertIsNone(error)
13
 
13
 
14
-        _, error = test_varchar._check_data_value("c" * 9)
14
+        _, error = test_varchar.check_data_value("c" * 9)
15
         self.assertIsNone(error)
15
         self.assertIsNone(error)
16
 
16
 
17
-        _, error = test_varchar._check_data_value("c" * 11)
17
+        _, error = test_varchar.check_data_value("c" * 11)
18
         self.assertIsNotNone(error)
18
         self.assertIsNotNone(error)
19
         self.assertIsInstance(error, ValueError)
19
         self.assertIsInstance(error, ValueError)
20
 
20
 

Loading…
取消
儲存