Sfoglia il codice sorgente

Merging resolution with settings validator

m.orban 8 anni fa
parent
commit
7c99981ad1

+ 4
- 0
lodel/leapi/datahandlers/datas_base.py Vedi File

@@ -114,6 +114,10 @@ class Text(DataField):
114 114
     
115 115
     def _check_data_value(self, value):
116 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 121
         return value, error
118 122
 
119 123
 ##@brief Data field designed to handle Files

+ 2
- 2
tests/datahandlers/test_boolean.py Vedi File

@@ -10,12 +10,12 @@ class BooleanTestCase(unittest.TestCase):
10 10
 
11 11
         # correct values
12 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 14
             self.assertIsNone(error)
15 15
 
16 16
         # incorrect values
17 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 19
             self.assertIsNotNone(error)
20 20
 
21 21
     def test_can_override(self):

+ 2
- 2
tests/datahandlers/test_integer.py Vedi File

@@ -10,12 +10,12 @@ class IntegerTestCase(unittest.TestCase):
10 10
 
11 11
         # Incorrect values
12 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 14
             self.assertIsNotNone(error)
15 15
 
16 16
         # Correct values
17 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 19
             self.assertIsNone(error)
20 20
 
21 21
     def test_can_override(self):

+ 3
- 3
tests/datahandlers/test_regex.py Vedi File

@@ -9,7 +9,7 @@ class RegexTestCase(unittest.TestCase):
9 9
         test_value = '126.205.255.12'
10 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 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 13
         self.assertIsNone(error)
14 14
         self.assertEqual(value, test_value)
15 15
 
@@ -17,7 +17,7 @@ class RegexTestCase(unittest.TestCase):
17 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 18
                            max_length=15)
19 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 21
             self.assertEqual(value, '')
22 22
             self.assertIsNotNone(error)
23 23
 
@@ -25,7 +25,7 @@ class RegexTestCase(unittest.TestCase):
25 25
         test_max_length = 15
26 26
         test_regex = Regex('[a-z]+8?', max_length=15)
27 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 29
             if len(test_value)>test_max_length:
30 30
                 self.assertEqual(value, '')
31 31
                 self.assertIsNotNone(error)

+ 15
- 0
tests/datahandlers/test_text.py Vedi File

@@ -0,0 +1,15 @@
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 Vedi File

@@ -8,13 +8,13 @@ class VarcharTestCase(unittest.TestCase):
8 8
     def test_check_data_value(self):
9 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 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 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 18
         self.assertIsNotNone(error)
19 19
         self.assertIsInstance(error, ValueError)
20 20
 

Loading…
Annulla
Salva