Пример #1
0
    def _test_broken_widget(self, widget_cls, expected_msg):
        """Test that a broken widget doesn't break the dashboard view.

        Args:
            widget_cls (type):
                The broken widget to register and test against.

            expected_msg (unicode, optional):
                The expected error message raised by the broken method.
        """
        admin_widgets_registry.register(widget_cls)
        self.spy_on(logger.exception)

        try:
            self.client.login(username='******', password='******')
            response = self.client.get('/admin/')
            self.assertEqual(response.status_code, 200)

            self.assertIn('page_model_attrs', response.context)
            widgets = response.context['page_model_attrs']['widgetsData']

            self.assertEqual(len(widgets), len(admin_widgets_registry) - 1)
            self.assertNotEqual(widgets[-1]['id'], widget_cls.widget_id)
            self.assertNotIn(
                b'id="admin-widget-%s"' % widget_cls.widget_id.encode('utf-8'),
                response.content)

            spy_call = logger.exception.last_call
            self.assertEqual(spy_call.args[0],
                             'Error setting up administration widget %r: %s')
            self.assertEqual(spy_call.args[1], widget_cls)
            self.assertIsInstance(spy_call.args[2], Exception)
            self.assertEqual(six.text_type(spy_call.args[2]), expected_msg)
        finally:
            admin_widgets_registry.unregister(widget_cls)
    def test_unregister_admin_widget(self):
        """Testing unregister_admin_widget"""
        admin_widgets_registry.register(MyLegacyWidget)

        message = (
            'reviewboard.admin.widgets.unregister_admin_widget() is '
            'deprecated and will be removed in Review Board 5.0. Use '
            'reviewboard.admin.widgets.admin_widgets_registry.unregister() '
            'to unregister %r instead.' % MyLegacyWidget)

        with self.assertWarns(RemovedInReviewBoard50Warning, message):
            unregister_admin_widget(MyLegacyWidget)

        self.assertNotIn(MyLegacyWidget, admin_widgets_registry)
Пример #3
0
    def test_get_with_widget_can_render_false(self):
        """Testing admin_dashboard_view with widget.can_render() == False"""
        admin_widgets_registry.register(HiddenWidget)

        try:
            self.client.login(username='******', password='******')
            response = self.client.get('/admin/')
            self.assertEqual(response.status_code, 200)

            self.assertIn('page_model_attrs', response.context)
            widgets = response.context['page_model_attrs']['widgetsData']

            self.assertEqual(len(widgets), len(admin_widgets_registry) - 1)

            self.assertNotEqual(widgets[-1]['id'], 'hidden-widget')
        finally:
            admin_widgets_registry.unregister(HiddenWidget)
Пример #4
0
    def test_get(self):
        """Testing admin_dashboard_view"""
        admin_widgets_registry.register(MyWidget)

        try:
            self.client.login(username='******', password='******')
            response = self.client.get('/admin/')
            self.assertEqual(response.status_code, 200)

            self.assertIn('page_model_attrs', response.context)
            widgets = response.context['page_model_attrs']['widgetsData']

            self.assertEqual(len(widgets), len(admin_widgets_registry))

            self.assertEqual(
                widgets[-1], {
                    'id': 'my-widget',
                    'domID': 'admin-widget-my-widget',
                    'viewClass': 'RB.Admin.WidgetView',
                    'modelClass': 'RB.Admin.Widget',
                    'viewOptions': {
                        'test_option': 'test-value',
                    },
                    'modelAttrs': {
                        'test_attr': 'test-value',
                    },
                    'modelOptions': {
                        'test_option': 'test-value',
                    },
                })

            self.assertIn(
                b'<div class="rb-c-admin-widget test-c-my-widget -is-large"'
                b' id="admin-widget-my-widget">', response.content)
        finally:
            admin_widgets_registry.unregister(MyWidget)