Browse Source

Added the test_regex module under version control

Roland Haroutiounian 7 years ago
parent
commit
7850e6c2be
2 changed files with 42 additions and 0 deletions
  1. 2
    0
      tests/datahandlers/__init__.py
  2. 40
    0
      tests/datahandlers/test_regex.py

+ 2
- 0
tests/datahandlers/__init__.py View File

@@ -0,0 +1,2 @@
1
+# -*- coding: utf-8 -*-
2
+

+ 40
- 0
tests/datahandlers/test_regex.py View File

@@ -0,0 +1,40 @@
1
+import unittest
2
+
3
+from lodel.leapi.datahandlers.datas import Regex, Varchar
4
+
5
+
6
+class RegexTestCase(unittest.TestCase):
7
+
8
+    def test_check_correct_data_value(self):
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]?)$', max_length=100)
11
+        value, error = test_regex._check_data_value(test_value)
12
+        self.assertIsNone(error)
13
+        self.assertEqual(value, test_value)
14
+
15
+    def test_check_bad_data_value(self):
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]?)$', max_length=15)
17
+        for test_value in ['800.9.10.5', 'test_string_value', '999.999.999.999']:
18
+            value, error = test_regex._check_data_value(test_value)
19
+            self.assertEqual(value, '')
20
+            self.assertIsNotNone(error)
21
+
22
+    def test_check_max_length(self):
23
+        test_max_length = 15
24
+        test_regex = Regex('[a-z]+8?', max_length=15)
25
+        for test_value in ['cccccc8', 'ccccccccccccccccccccccccccccccccc8']:
26
+            value, error = test_regex._check_data_value(test_value)
27
+            if len(test_value)>test_max_length:
28
+                self.assertEqual(value, '')
29
+                self.assertIsNotNone(error)
30
+            else:
31
+                self.assertIsNone(error)
32
+                self.assertEqual(value, test_value)
33
+
34
+    def test_can_override(self):
35
+        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]?)$', max_length=15)
36
+        for test_varchar in [Varchar(max_length=64), Varchar(max_length=15), Varchar(max_length=9)]:
37
+            if test_regex.max_length == test_varchar.max_length:
38
+                self.assertTrue(test_regex.can_override(test_varchar))
39
+            else:
40
+                self.assertFalse(test_regex.can_override(test_varchar))

Loading…
Cancel
Save