Ejemplo n.º 1
0
def settings_report_enable(request, plugin_name):
    # only do this if there isn't a plugin already with the name
    try:
        _ = Report.objects.get(name=plugin_name)
    except Report.DoesNotExist:
        plugin = sal.plugin.PluginManager.get_plugin_by_name(plugin_name)
        if plugin:
            report = Report(name=plugin_name)
            report.save()
    return redirect('settings_reports')
Ejemplo n.º 2
0
class PluginTest(TestCase):

    def setUp(self):
        self.widget = Plugin(name='That gum you like is coming back in style', order=0)
        self.widget.save()
        self.report_plugin = Report(name='Drymouth')
        self.report_plugin.save()
        self.machine_detail_plugin = MachineDetailPlugin(name='Burrito Mojado', order=0)
        self.machine_detail_plugin.save()

    def test_process_plugin_no_yapsy_plugin(self):
        """Test that requesting non-existent plugins via URL 404s"""
        self.assertRaises(Http404, non_ui_views.process_plugin, 'Once a moose bit my sister')

    @patch('sal.plugin.PluginManager.get_plugin_by_name')
    def test_process_widget_not_enabled(self, manager):
        """Test that requesting disabled plugins via URL 404s"""
        manager.return_value = Widget()
        self.assertRaises(Http404, non_ui_views.process_plugin, 'Once a moose bit my sister')

    @patch('sal.plugin.PluginManager.get_plugin_by_name')
    def test_process_report_not_enabled(self, manager):
        """Test that requesting disabled plugins via URL 404s"""
        manager.return_value = ReportPlugin()
        self.assertRaises(Http404, non_ui_views.process_plugin, 'Once a moose bit my sister')

    @patch('sal.plugin.PluginManager.get_plugin_by_name')
    def test_process_detailplugin_not_enabled(self, manager):
        """Test that requesting disabled detail plugins via URL 404s"""
        manager.return_value = DetailPlugin()
        self.assertRaises(Http404, non_ui_views.process_plugin, 'Once a moose bit my sister')

    @patch('sal.plugin.PluginManager.get_plugin_by_name')
    def test_process_widget_enabled(self, manager):
        """Test that requesting enabled, existing plugins works"""
        manager.return_value = Widget()
        self.assertTrue(non_ui_views.process_plugin(plugin_name=self.widget.name))

    @patch('sal.plugin.PluginManager.get_plugin_by_name')
    def test_process_report_enabled(self, manager):
        """Test that requesting enabled, existing reports works"""
        manager.return_value = ReportPlugin()
        self.assertTrue(non_ui_views.process_plugin(plugin_name=self.report_plugin.name))

    @patch('sal.plugin.PluginManager.get_plugin_by_name')
    def test_process_machine_detail_plugin_enabled(self, manager):
        """Test that requesting enabled, existing detail plugins works"""
        manager.return_value = DetailPlugin()
        self.assertTrue(non_ui_views.process_plugin(plugin_name=self.machine_detail_plugin.name))
Ejemplo n.º 3
0
class WidgetSettingsTest(TestCase):
    """Functional tests for Widget settings views."""
    fixtures = ['user_fixture.json']

    def setUp(self):
        self.ga_user = User.objects.get(pk=1)
        user_profile = self.ga_user.userprofile
        user_profile.level = 'GA'
        user_profile.save()
        settings.BASIC_AUTH = False
        self.client = Client()
        self.client.force_login(self.ga_user)
        self.url = '/settings/plugins/enable'
        # Avoid sending analytics to the project while testing!
        server.utils.set_setting('send_data', False)
        self.widget = Plugin(name='Widget', order=0)
        self.widget.save()
        self.report_plugin = Report(name='Report')
        self.report_plugin.save()

    def test_enable_enabled_widget(self):
        """Test that enabling an enabled widget does nothing"""
        self.client.get(f'{self.url}/{self.widget.name}/')
        self.assertEqual(Plugin.objects.count(), 1)

    @patch('sal.plugin.PluginManager.get_plugin_by_name')
    def test_enable_disabled_widget(self, manager):
        """Test that enabling a disabled widget works"""
        # Fake that this plugin has a yapsy file
        manager.return_value = Widget()
        self.client.get(f'{self.url}/tacos/')
        self.assertEqual(Plugin.objects.count(), 2)

    def test_enable_nonexistent_widget(self):
        """If a plugin does not exist, redirect to plugin list."""
        self.client.get(f'{self.url}/tacos/')
        self.assertEqual(Plugin.objects.count(), 1)