Browse Source

Modified and added test for regex datahandler

m.orban 8 years ago
parent
commit
437c41fd49
1 changed files with 22 additions and 15 deletions
  1. 22
    15
      tests/datahandlers/test_regex.py

+ 22
- 15
tests/datahandlers/test_regex.py View File

@@ -1,5 +1,5 @@
1 1
 import unittest
2
-
2
+from lodel.exceptions import *
3 3
 from lodel.leapi.datahandlers.datas import Regex, Varchar, Integer
4 4
 
5 5
 
@@ -9,29 +9,36 @@ 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)
13
-        self.assertIsNone(error)
12
+        value = test_regex._check_data_value(test_value)
14 13
         self.assertEqual(value, test_value)
15 14
 
16 15
     def test_check_bad_data_value(self):
17 16
         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 17
                            max_length=15)
19 18
         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)
21
-            self.assertEqual(value, None)
22
-            self.assertIsNotNone(error)
19
+            with self.assertRaises(FieldValidationError):
20
+                test_regex._check_data_value(test_value)
21
+
22
+    def test_check_bad_compile_regex(self):
23
+        test_max_length = 15
24
+        test_regex = Regex('^\d[a-z]+8?', max_length=15)
25
+        for test_value in ['cccc8']:
26
+            with self.assertRaises(FieldValidationError):
27
+                test_regex._check_data_value(test_value)
23 28
 
24
-    def test_check_max_length(self):
29
+    def test_check_bad_max_length(self):
25 30
         test_max_length = 15
26 31
         test_regex = Regex('[a-z]+8?', max_length=15)
27
-        for test_value in ['cccccc8', 'ccccccccccccccccccccccccccccccccc8']:
28
-            value, error = test_regex.check_data_value(test_value)
29
-            if len(test_value)>test_max_length:
30
-                self.assertEqual(value, None)
31
-                self.assertIsNotNone(error)
32
-            else:
33
-                self.assertIsNone(error)
34
-                self.assertEqual(value, test_value)
32
+        for test_value in ['ccccccccccccccccccccccccccccccccc8']:
33
+            with self.assertRaises(FieldValidationError):
34
+                test_regex._check_data_value(test_value)
35
+            
36
+    def test_check_good_max_length(self):
37
+        test_max_length = 15
38
+        test_regex = Regex('^\d[a-z]+8?', max_length=15)
39
+        for test_value in ['3ccccccccc8']:
40
+            value = test_regex._check_data_value(test_value)
41
+            self.assertEqual(value, test_value)
35 42
 
36 43
     def test_can_override(self):
37 44
         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]?)$',

Loading…
Cancel
Save