def test_init02(self): name = 'reset' label = 'Delete' icon = 'delete' url = 'https://www.stuff.org' action = WidgetAction(name=name, label=label, icon=icon, enabled=False, url=url) self.assertEqual(name, action.name) self.assertEqual(label, action.label) self.assertEqual(icon, action.icon) self.assertIs(action.enabled, False) self.assertDictEqual({'url': url}, action.attrs) self.assertDictEqual( { 'name': name, 'label': label, 'icon': icon, 'attrs': { 'disabled': True, 'url': url, }, 'title': label, }, action.context, )
def _build_create_action(self, label, title, url='', enabled=True): # return ('create', label, enabled, {'title': title, 'popupUrl': url}) return WidgetAction( name='create', label=label, enabled=enabled, icon='add', title=title, popupUrl=url, )
def _build_reset_action(self, enabled=True, value=''): # return ( # 'reset', _('Clear'), enabled, # {'action': 'reset', 'title': _('Clear'), 'value': value}, # ) return WidgetAction( name='reset', label=_('Clear'), enabled=enabled, icon='delete', action='reset', title=_('Clear'), value=value, )
def test_init01(self): name = 'add' label = 'Create a stuff' action = WidgetAction(name=name, label=label) self.assertEqual(name, action.name) self.assertEqual(label, action.label) self.assertIsNone(action.icon) self.assertIs(action.enabled, True) self.assertDictEqual({}, action.attrs) self.assertDictEqual( { 'name': name, 'label': label, 'icon': None, 'attrs': {}, 'title': label, }, action.context, )
def test_context_title(self): name = 'reset' label = 'Delete' title = 'Delete stuff' icon = 'delete' url = 'https://www.stuff.org' action = WidgetAction(name=name, label=label, icon=icon, url=url, title=title) self.assertDictEqual( { 'name': name, 'label': label, 'icon': icon, 'attrs': { 'url': url, }, 'title': title, }, action.context, )
def test_eq(self): self.assertEqual( WidgetAction(name='name', label='label', enabled=True), WidgetAction(name='name', label='label'), ) url = 'https://www.stuff.org' self.assertEqual( WidgetAction(name='add', label='Create', url=url, enabled=False), WidgetAction(name='add', label='Create', url=url, enabled=False), ) self.assertNotEqual( WidgetAction(name='add', label='Add'), WidgetAction(name='delete', label='Add'), ) self.assertNotEqual( WidgetAction(name='add', label='Add'), WidgetAction(name='add', label='Create'), ) self.assertNotEqual( WidgetAction(name='add', label='Add', enabled=True), WidgetAction(name='add', label='Add', enabled=False), ) self.assertNotEqual( WidgetAction(name='add', label='Add', icon='add'), WidgetAction(name='add', label='Add'), ) self.assertNotEqual( WidgetAction(name='add', label='Add', url=url), WidgetAction(name='add', label='Add'), )
def test_callable_enabled(self): action = WidgetAction(name='name', label='label', enabled=lambda: False) self.assertIs(action.enabled, False)