Browse Source

Add a file to execute tests on plugins + rewrite the tests

- now runtest runs also make refresh_plugins in the test instance
Yann Weber 7 years ago
parent
commit
9b27bd1911
3 changed files with 50 additions and 49 deletions
  1. 1
    0
      runtest
  2. 0
    0
      tests/plugin/__init__.py
  3. 49
    49
      tests/plugin/test_plugin.py

+ 1
- 0
runtest View File

@@ -54,6 +54,7 @@ cp -R tests $testdir
54 54
 cd $testdir
55 55
 rm -R conf.d && mv tests/tests_conf.d conf.d
56 56
 make
57
+make refresh_plugins
57 58
 python3 loader.py $@
58 59
 
59 60
 rm -Rf $testdir

+ 0
- 0
tests/plugin/__init__.py View File


+ 49
- 49
tests/plugin/test_plugin.py View File

@@ -3,62 +3,62 @@
3 3
 import unittest
4 4
 
5 5
 from lodel.plugin.plugins import Plugin, PluginError
6
+from lodel.plugin.datasource_plugin import DatasourcePlugin
7
+from lodel.plugin.sessionhandler import SessionHandlerPlugin
8
+from lodel.plugin.interface import InterfacePlugin
9
+from lodel.plugin.extensions import Extension
6 10
 from lodel.settings.settings import Settings
7 11
 import tests.loader_utils
8 12
 
9 13
 class PluginTestCase(unittest.TestCase):
14
+    """ Test case grouping all tests on Plugin class init procedures """
10 15
 
11
-    def test_plugin_init_right_name(self):
12
-        Plugin.start(['/home/helene/lodel2/plugins'],['dummy'])
16
+    def setUp(self):
13 17
         Plugin.clear()
14
-        
15
-    # With a wrong plugin name, a NameError Exception has to be raised at line 318 of plugin.py
16
-    def test_plugin_init_wrong_name(self):
17
-        with self.assertRaises(NameError):
18
-            Plugin.start(['/home/helene/lodel2/plugins', '/home/helene/lodel2/tests/tests_plugins' ],['wrong_plugin_name'])
19
-        Plugin.clear()
20
-        
21
-    # With a wrong plugin name, a NameError Exception has to be raised at line 318 of plugin.py
22
-    def test_plugin_init_right_wrong_name(self):
23
-        with self.assertRaises(NameError):
24
-            Plugin.start(['/home/helene/lodel2/plugins', '/home/helene/lodel2/tests/tests_plugins'],['dummy', 'wrong_plugin_name'])
18
+
19
+    def test_start(self):
20
+        """ Testing plugin registration with a valid list of plugins name """
21
+        Plugin.start(['dummy', 'dummy_datasource'])
22
+
23
+    def test_double_start(self):
24
+        """ Testing clas behavior when starting it twice """
25
+        Plugin.start(['dummy', 'dummy_datasource'])
26
+        with self.assertRaises(PluginError):
27
+            Plugin.start(['dummy', 'dummy_datasource'])
28
+
29
+    def test_clear(self):
30
+        """ Testing that clear allow to start again Plugin """
31
+        Plugin.start(['dummy', 'dummy_datasource'])
25 32
         Plugin.clear()
26
-    
27
-    def test_plugin_started(self):
28
-        with self.assertRaises(RuntimeError):
29
-            Plugin.started()
30
-            
31
-    def test_plugin_plugin_path(self):
32
-        Plugin.start(['/home/helene/lodel2/plugins', '/home/helene/lodel2/tests/tests_plugins'],['dummy'])
33
-        self.assertEqual(Plugin.plugin_path('dummy'), '/home/helene/lodel2/plugins/dummy/')
33
+        Plugin.start(['dummy', 'dummy_datasource'])
34
+
35
+class PluginStartedTestCase(unittest.TestCase):
36
+    """ Test case grouping all tests on a started Plugin class """
37
+
38
+    @classmethod
39
+    def setUpClass(cls):
34 40
         Plugin.clear()
35
-        
36
-    def test_plugin_get(self):
37
-        Plugin.start(['/home/helene/lodel2/plugins', '/home/helene/lodel2/tests/tests_plugins'],['dummy'])
38
-        with self.assertRaises(PluginError):
39
-            Plugin.get('wrong_plugin_name')
40
-        self.assertTrue(isinstance(Plugin.get('dummy'), Plugin))
41
+        Plugin.start(['dummy', 'dummy_datasource', 'webui', 'ram_session'])
42
+
43
+    @classmethod
44
+    def tearDownClass(cls):
41 45
         Plugin.clear()
42
-        
43
-    def test_plugin_register(self):
44
-        with self.assertRaises(RuntimeError):
45
-            Plugin.register('dummy')
46
-        Plugin.start(['/home/helene/lodel2/plugins'],['dummy'])
46
+
47
+    def test_construct(self):
48
+        """ Testing plugin instanciation """
49
+        pname_type = {
50
+            'dummy': Extension,
51
+            'dummy_datasource': DatasourcePlugin,
52
+            #'webui': InterfacePlugin, #singleton, cannot reinstanciate
53
+            #'ram_session': SessionHandlerPlugin, #singleton, cannot resintanciate
54
+            }
55
+        for pname, ptype in pname_type.items():
56
+            pinstance = Plugin.get(pname)
57
+            self.assertIsInstance(pinstance, ptype, "Expected plugin '%s' \
58
+to be in an %s instance but found an %s instance" % (
59
+                pname, ptype, pinstance.__class__))
60
+
61
+    def test_construct_invalid(self):
62
+        """ Testing plugin instanciation with a non existing name """
47 63
         with self.assertRaises(PluginError):
48
-            Plugin.register('dummy')
49
-        Plugin.clear()
50
-        
51
-    def test_plugin_load_all(self):
52
-        #Plugin.start(['/home/helene/lodel2/plugins'],['dummynotactivable'])
53
-        #Plugin.load_all()
54
-        pass
55
-        
56
-    
57
-     
58
-        
59
-        
60
-        
61
-        
62
-        
63
-        
64
-        
64
+            Plugin.get("fljkhsfh")

Loading…
Cancel
Save