Browse Source

Cleaned tests

Quentin Bonaventure 8 years ago
parent
commit
bf4540c1b1

+ 1
- 9
tests/datahandlers/test_concat.py View File

@@ -6,23 +6,15 @@ from lodel.leapi.datahandlers.datas import Concat as Testee
6 6
 class ConcatTestCase(unittest.TestCase):
7 7
     
8 8
     
9
-    def test_has_base_type_property(self):
10
-        self.assertTrue(hasattr(Testee, 'base_type'))
11
-        
12
-        
13 9
     def test_base_type_is_char(self):
14 10
         self.assertEqual(Testee.base_type, 'char')
15 11
         
16 12
         
17
-    def test_has_help_property(self):
18
-        self.assertTrue(hasattr(Testee, 'help'))
19
-        
20
-        
21 13
     def test_help_property_str_is_set(self):
22 14
         self.assertEqual(type(Testee.help), str)
23 15
         
24 16
     
25
-    def test_sets_correct_format_string(self):
17
+    def test_correctly_sets_format_string(self):
26 18
         separator = '-'
27 19
         field_list  = ['', '', '']
28 20
         testee = Testee(field_list, separator)

+ 37
- 34
tests/datahandlers/test_formatstring.py View File

@@ -1,66 +1,69 @@
1 1
 import unittest
2 2
 
3
-from lodel.leapi.datahandlers.datas import FormatString as Testee
3
+from lodel.leapi.datahandlers.datas import FormatString
4 4
 from lodel.editorial_model.components import EmClass
5 5
 
6
-class TesteeTestCase(unittest.TestCase):
7
-    regex = '%s-%s'
8
-    dummyEmClass = EmClass('testing')
9
-    fone_name = 'field1'
10
-    ftwo_name = 'field2'
11
-    dummyEmClass.new_field(fone_name, 'varchar')
12
-    dummyEmClass.new_field(ftwo_name, 'varchar')
13
-    field_one_value = 'field one value'
14
-    field_two_value = 'field two value'
15
-    field_value_dict = {fone_name: field_one_value, ftwo_name: field_two_value}
16
-    field_list = [fone_name, ftwo_name]
17
-    
18
-    test_Testee = Testee(regex,[fone_name, ftwo_name])
19
-    
20
-    max_length = round(len(regex % (field_one_value, field_two_value)) / 2)
21
-
6
+class FormatStringTestCase(unittest.TestCase):
22 7
 
23
-    def test_has_base_type_property(self):
24
-        self.assertTrue(hasattr(Testee, 'base_type'))
25
-        
26 8
         
27 9
     def test_base_type_is_char(self):
28
-        self.assertEqual(Testee.base_type, 'char')
29
-        
30
-        
31
-    def test_has_help_property(self):
32
-        self.assertTrue(hasattr(Testee, 'help'))
10
+        self.assertEqual(FormatString.base_type, 'char')
33 11
         
34 12
         
35 13
     def test_help_property_str_is_set(self):
36
-        self.assertEqual(type(Testee.help), str)
14
+        self.assertEqual(type(FormatString.help), str)
37 15
 
38 16
 
39 17
     def test_string_formatting_output(self):
18
+        testee = FormatString(self.regex,[self.fone_name, self.ftwo_name])
19
+        
40 20
         expected_result = self.regex % (self.field_one_value, self.field_two_value)
41
-        actual_result = self.test_Testee.construct_data(self.dummyEmClass, None, self.field_value_dict, None)
21
+        actual_result = testee.construct_data(self.dummyEmClass, None, self.field_value_dict, None)
42 22
 
43 23
         self.assertEqual(actual_result, expected_result)
44 24
         
45 25
         
46 26
     def test_throws_user_warning_on_exceeding_string(self):
47 27
         max_length = len(self.regex % (self.field_one_value, self.field_two_value)) / 2
48
-        testee = Testee(self.regex, self.field_list, max_length=self.max_length)
28
+        testee = FormatString(self.regex, self.field_list, max_length=self.max_length)
49 29
         
50
-        with self.assertWarns(UserWarning):
51
-            testee.construct_data(self.dummyEmClass, None, self.field_value_dict, None)
30
+        self.assertWarns(
31
+            UserWarning,
32
+            testee.construct_data,
33
+            self.dummyEmClass, None, self.field_value_dict, None
34
+        )
52 35
             
53 36
             
54 37
     def test_exceeding_string_length_is_truncated(self):
55 38
         max_length = 2
56
-        testee = Testee(self.regex, self.field_list, max_length=self.max_length)
39
+        testee = FormatString(self.regex, self.field_list, max_length=self.max_length)
57 40
         result_string = testee._construct_data(self.dummyEmClass, None, self.field_value_dict, None)
58 41
         
59 42
         self.assertEqual(self.max_length, len(result_string))
60 43
         
61 44
             
62 45
     def test_thrown_exceeding_str_warning_message_composition(self):
63
-        testee = Testee(self.regex, self.field_list, max_length=self.max_length)
46
+        testee = FormatString(self.regex, self.field_list, max_length=self.max_length)
47
+        
48
+        self.assertWarnsRegex(
49
+            UserWarning,
50
+            '[T|t]runcat[a-z]+',
51
+            testee.construct_data,
52
+            self.dummyEmClass, None, self.field_value_dict, None
53
+        )
54
+            
55
+    
56
+    def setUp(self):
57
+        self.regex = '%s-%s'
58
+        self.dummyEmClass = EmClass('testing')
59
+        self.fone_name = 'field1'
60
+        self.ftwo_name = 'field2'
61
+        self.dummyEmClass.new_field(self.fone_name, 'varchar')
62
+        self.dummyEmClass.new_field(self.ftwo_name, 'varchar')
63
+        self.field_one_value = 'field one value'
64
+        self.field_two_value = 'field two value'
65
+        self.field_value_dict = {self.fone_name: self.field_one_value, self.ftwo_name: self.field_two_value}
66
+        self.field_list = [self.fone_name, self.ftwo_name]
64 67
         
65
-        with self.assertWarnsRegex(UserWarning, '[T|t]runcat[a-z]+'):
66
-            testee.construct_data(self.dummyEmClass, None, self.field_value_dict, None)
68
+        self.max_length = round(len(self.regex % (self.field_one_value, self.field_two_value)) / 2)
69
+        

+ 3
- 15
tests/datahandlers/test_leobjectidentifier.py View File

@@ -1,29 +1,17 @@
1 1
 import unittest
2 2
 import inspect
3
-from unittest import mock 
4
-from unittest.mock import patch
5
-
6
-import leapi_dyncode as dyncode
7
-
8
-from types import *
9 3
 
4
+from unittest import mock
10 5
 from lodel.leapi.datahandlers.datas import LeobjectSubclassIdentifier as Testee
11 6
 
12 7
 
13 8
 class LeresultectSubclassIdentifierTestCase(unittest.TestCase):        
14 9
         
15
-    def test_has_base_type_property(self):
16
-        self.assertTrue(hasattr(Testee, 'base_type'))
17
-        
18 10
         
19 11
     def test_base_type_is_varchar(self):
20 12
         self.assertEqual(Testee.base_type, 'varchar')
21 13
         
22 14
         
23
-    def test_has_help_property(self):
24
-        self.assertTrue(hasattr(Testee, 'help'))
25
-        
26
-        
27 15
     def test_help_property_str_is_set(self):
28 16
         self.assertEqual(type(Testee.help), str)
29 17
         
@@ -39,7 +27,7 @@ class LeresultectSubclassIdentifierTestCase(unittest.TestCase):
39 27
     def test_passing_class_returns_class_name(self):
40 28
         result = Testee.construct_data(None, object, None, None, None)
41 29
         
42
-        self.assertEqual(result, object .__name__)
30
+        self.assertEqual(result, object.__name__)
43 31
         
44 32
         
45 33
     def test_passing_instance_returns_class_name(self):
@@ -49,7 +37,7 @@ class LeresultectSubclassIdentifierTestCase(unittest.TestCase):
49 37
         
50 38
         
51 39
     def test_passing_instance_and_class_same_result(self):
52
-        objResult = Testee.construct_data(None,  Testee(), None, None, None)
40
+        objResult = Testee.construct_data(None, Testee(), None, None, None)
53 41
         clsResult = Testee.construct_data(None, Testee, None, None, None)
54 42
         
55 43
         self.assertEqual(objResult, clsResult)

+ 2
- 15
tests/datahandlers/test_password.py View File

@@ -1,26 +1,13 @@
1 1
 import unittest
2
-from unittest import mock 
3
-from unittest.mock import patch
4
-
5
-import leapi_dyncode as dyncode
6
-
7 2
 from lodel.leapi.datahandlers.datas import Password as Testee
8 3
 
9 4
 
10 5
 class PasswordTestCase(unittest.TestCase):
11 6
         
12 7
         
13
-    def test_has_base_type_property(self):
14
-        self.assertTrue(hasattr(Testee, 'base_type'))
15
-        
16
-        
17
-    def test_base_type_is_password(self):
8
+    def test_base_type_property_value_equals_password(self):
18 9
         self.assertEqual(Testee.base_type, 'password')
19 10
         
20 11
         
21
-    def test_has_help_property(self):
22
-        self.assertTrue(hasattr(Testee, 'help'))
23
-        
24
-        
25
-    def test_help_property_str_is_set(self):
12
+    def test_help_property_string_is_set(self):
26 13
         self.assertEqual(type(Testee.help), str)

+ 15
- 14
tests/datahandlers/test_uniqid.py View File

@@ -11,18 +11,10 @@ from lodel.plugins.dummy_datasource.datasource import DummyDatasource
11 11
 class UniqIDTestCase(unittest.TestCase):
12 12
         
13 13
         
14
-    def test_has_base_type_property(self):
15
-        self.assertTrue(hasattr(Testee, 'base_type'))
16
-        
17
-        
18
-    def test_base_type_is_int(self):
14
+    def test_base_type_is_set_to_int(self):
19 15
         self.assertEqual(Testee.base_type, 'int')
20 16
         
21 17
         
22
-    def test_has_help_property(self):
23
-        self.assertTrue(hasattr(Testee, 'help'))
24
-        
25
-        
26 18
     def test_help_property_str_is_set(self):
27 19
         self.assertEqual(type(Testee.help), str)
28 20
         
@@ -32,22 +24,31 @@ class UniqIDTestCase(unittest.TestCase):
32 24
         
33 25
     
34 26
     def test_construct_data_sets_new_uid_if_none(self):
35
-        sent_uid = None
27
+        set_uid = None
36 28
         mocked_returned_uid = 987654321
37 29
         
38 30
         with patch.object(DummyDatasource, 'new_numeric_id', return_value=mocked_returned_uid) as mock_method:
39
-            returned_uid = Testee.construct_data(None, dyncode.Object, None, None, sent_uid)
31
+            returned_uid = Testee.construct_data(None, dyncode.Object, None, None, set_uid)
40 32
             
41 33
             mock_method.assert_called_once_with(dyncode.Object)
42 34
             self.assertEqual(returned_uid, mocked_returned_uid)
43 35
             
44 36
 
45 37
     def test_construct_data_returns_already_set_uid(self):
46
-        sent_uid = 123456789
38
+        set_uid = 123456789
39
+        mocked_returned_uid = 987654321
40
+        
41
+        with patch.object(DummyDatasource, 'new_numeric_id', return_value=mocked_returned_uid) as mock_method:
42
+            returned_uid = Testee.construct_data(None, dyncode.Object, None, None, set_uid)
43
+
44
+            self.assertEqual(returned_uid, set_uid)
45
+            
46
+    
47
+    def test_construct_data_does_not_call_new_numeric_id_if_id_is_set(self):
48
+        set_uid = 123456789
47 49
         mocked_returned_uid = 987654321
48 50
         
49 51
         with patch.object(DummyDatasource, 'new_numeric_id', return_value=mocked_returned_uid) as mock_method:
50
-            returned_uid = Testee.construct_data(None, dyncode.Object, None, None, sent_uid)
52
+            returned_uid = Testee.construct_data(None, dyncode.Object, None, None, set_uid)
51 53
 
52
-            self.assertEqual(returned_uid, sent_uid)
53 54
             mock_method.assert_not_called()     

Loading…
Cancel
Save