Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #-*- coding: utf-8 -*-
  2. import unittest
  3. from lodel.plugin.plugins import Plugin, PluginError
  4. from lodel.plugin.datasource_plugin import DatasourcePlugin
  5. from lodel.plugin.sessionhandler import SessionHandlerPlugin
  6. from lodel.plugin.interface import InterfacePlugin
  7. from lodel.plugin.extensions import Extension
  8. from lodel.settings.settings import Settings
  9. import tests.loader_utils
  10. ##@todo write tests about discovering
  11. class PluginTestCase(unittest.TestCase):
  12. """ Test case grouping all tests on Plugin class init procedures """
  13. def setUp(self):
  14. Plugin.clear()
  15. def test_start(self):
  16. """ Testing plugin registration with a valid list of plugins name """
  17. Plugin.start(['dummy', 'dummy_datasource'])
  18. def test_double_start(self):
  19. """ Testing clas behavior when starting it twice """
  20. Plugin.start(['dummy', 'dummy_datasource'])
  21. with self.assertRaises(PluginError):
  22. Plugin.start(['dummy', 'dummy_datasource'])
  23. def test_clear(self):
  24. """ Testing that clear allow to start again Plugin """
  25. Plugin.start(['dummy', 'dummy_datasource'])
  26. Plugin.clear()
  27. Plugin.start(['dummy', 'dummy_datasource'])
  28. class PluginStartedTestCase(unittest.TestCase):
  29. """ Test case grouping all tests on a started Plugin class """
  30. @classmethod
  31. def setUpClass(cls):
  32. Plugin.clear()
  33. Plugin.start(['dummy', 'dummy_datasource', 'webui', 'ram_session'])
  34. @classmethod
  35. def tearDownClass(cls):
  36. Plugin.clear()
  37. def test_construct(self):
  38. """ Testing plugin instanciation """
  39. pname_type = {
  40. 'dummy': Extension,
  41. 'dummy_datasource': DatasourcePlugin,
  42. #'webui': InterfacePlugin, #singleton, cannot reinstanciate
  43. #'ram_session': SessionHandlerPlugin, #singleton, cannot resintanciate
  44. }
  45. for pname, ptype in pname_type.items():
  46. pinstance = Plugin.get(pname)
  47. self.assertIsInstance(pinstance, ptype, "Expected plugin '%s' \
  48. to be in an %s instance but found an %s instance" % (
  49. pname, ptype, pinstance.__class__))
  50. def test_construct_invalid(self):
  51. """ Testing plugin instanciation with a non existing name """
  52. with self.assertRaises(PluginError):
  53. Plugin.get("fljkhsfh")