Esempio n. 1
0
    def test_create_uses_template_if_provided(self):
        template = SettingsHandler()
        template.a = 'a'
        template.b = 'b'
        with self.override_default_settings(SimpleWidget):
            handler = SettingsHandler.create(SimpleWidget, template)
        self.assertEqual(handler.a, 'a')
        self.assertEqual(handler.b, 'b')

        # create should copy the template
        handler.b = 'B'
        self.assertEqual(template.b, 'b')
Esempio n. 2
0
    def test_create(self, SettingProvider):
        """:type SettingProvider: unittest.mock.Mock"""

        mock_read_defaults = Mock()
        with patch.object(SettingsHandler, 'read_defaults', mock_read_defaults):
            handler = SettingsHandler.create(SimpleWidget)

            self.assertEqual(handler.widget_class, SimpleWidget)
            # create needs to create a SettingProvider which traverses
            # the widget definition and collects all settings and read
            # all settings and for widget class
            SettingProvider.assert_called_once_with(SimpleWidget)
            mock_read_defaults.assert_called_once_with()