def test_refresh(self): from biohub.core.plugins import install, remove, plugins from django.apps import apps name = 'tests.core.plugins.my_plugin' # Phase 1 install([name], migrate_database=True, update_config=True, migrate_options=dict(test=True, new_process=True)) self.assertIn(name, self.current_settings['PLUGINS']) self.assertIn(name, plugins.plugin_infos) self.assertTrue(apps.is_installed(name)) self.assertEqual( self.client.get('/api/my_plugin/hello/').data, 'Hello') # Phase patch self.write('Patching') plugins.refresh_plugins([name]) self.assertEqual( importlib.import_module( 'tests.core.plugins.my_plugin.consts').String, 'Patching') # Phase 2 remove([name], update_config=True) self.assertNotIn(name, self.current_settings['PLUGINS']) self.assertNotIn(name, plugins.plugin_infos)
def test_install(self): from biohub.core.plugins import install, plugins name = 'tests.core.plugins.my_plugin' # Phase 1 install([name], migrate_database=True, update_config=True, migrate_options=dict(test=True, new_process=True)) self.assertIn(name, self.current_settings['PLUGINS']) self.assertEqual(plugins.plugin_infos[name], ('My Plugin', 'hsfzxjy', 'This is my plugin.', '/_plugins/tests.core.plugins.my_plugin/plugin.js')) # Phase 2 install(['tests.core.plugins.another_plugin'], migrate_database=True, update_config=True, migrate_options=dict(test=True, new_process=True)) resp = self.client.get('/api/another_plugin/') self.assertEqual(resp.data, []) resp = self.client.get('/api/my_plugin/') self.assertEqual(resp.data, [])
def setUp(self): self._protect = plugins.protect(test=True, config=True) self._protect.acquire() install(['tests.core.tasks.myplugin'], update_config=True) subprocess.Popen(['kill', '-USR1', str(self._worker_process.pid)])\ .communicate() super(Test, self).setUp()
def test_list(self): name = 'tests.core.plugins.my_plugin' install([name], update_config=True) resp = self.client.get(reverse('api:plugins:list')) self.assertIn({ 'name': name, 'author': 'hsfzxjy', 'title': 'My Plugin', 'description': 'This is my plugin.' }, resp.data)
def handle(self, plugin, *args, **kwargs): self.plugin_name = self.handle_plugin_name(plugin) plugin_name = self.plugin_name install([plugin_name]) try: self.plugin_config = [ ac for ac in apps.app_configs.values() if ac.name == plugin_name ][0] except IndexError: self.fail_installation()
def test_plugin(self): name = 'tests.core.websocket.my_plugin' install([name]) plugins.populate_plugins() self.client1.send_content({'handler': 'my_plugin', 'data': ''}) self.assertEqual(self.client1.receive()['data'], 'my_plugin') self.assertIsNone(self.client1.receive()) remove([name]) self.client1.send_content({'handler': 'my_plugin', 'data': ''}) self.assertIsNone(self.client1.receive())
def test_remove(self): from biohub.core.plugins import install, remove, plugins from django.apps import apps name = 'tests.core.plugins.my_plugin' # Phase 1 install([name], migrate_database=True, update_config=True, migrate_options=dict(test=True, new_process=True)) self.assertIn(name, self.current_settings['PLUGINS']) self.assertIn(name, plugins.plugin_infos) self.assertTrue(apps.is_installed(name)) # Phase 2 remove([name], update_config=True) resp = self.client.get('/api/my_plugin/') self.assertNotIn(name, self.current_settings['PLUGINS']) self.assertEqual(resp.status_code, 404) self.assertNotIn(name, plugins.plugin_infos) self.assertFalse(apps.is_installed(name)) # Phase 3 install([name], migrate_database=True, update_config=True, migrate_options=dict(test=True, new_process=True)) self.assertIn(name, self.current_settings['PLUGINS']) # Phase 4 remove([name], update_config=True) self.assertNotIn(name, self.current_settings['PLUGINS']) self.assertNotIn(name, plugins.plugin_infos)