def __getitem__(self, key): portlet = Portlet.by_id(key) if portlet: portlet.__parent__ = self portlet.__name__ = key return portlet else: raise KeyError
def test_save_success(self): self.request.context = Portlet.by_id(1) result = self.view.save_success(self.APPSTRUCT) self.assertIsInstance(result, HTTPFound) self.assertEqual(result.location, '/portlet/1/edit/') portlet = Portlet.by_id(1) self.assertEqual(portlet.name, 'bar') self.assertEqual(portlet.groups, [Group.by_id(2), Group.by_id(3)]) self.assertEqual(portlet.exclude_groups, [ Group.by_id(4), ]) self.assertEqual(portlet.position, PortletPositions.above_content.name) self.assertEqual(portlet.weight, -10) self.assertEqual(portlet.html, u'Bar') self.assertEqual(self.request.session.pop_flash(), [u'Portlet "bar" modified.'])
def test_appstruct_full_context(self): self.request.context = Portlet.by_id(1) self.assertEqual( self.view.appstruct(), { 'name': 'dummy', 'groups': [ '1', ], 'exclude_groups': [ '3', ], 'position': PortletPositions.below_sidebar.name, 'weight': -127, 'html': u'You are admin.', })
def test_submit_success(self): result = self.view.submit_success(self.APPSTRUCT) self.assertIsInstance(result, HTTPFound) self.assertEqual(result.location, '/portlet/1/edit/') portlet = Portlet.by_id(1) self.assertEqual(portlet.name, 'foo') self.assertEqual(portlet.groups, [Group.by_id(1)]) self.assertEqual(portlet.exclude_groups, [Group.by_id(2)]) self.assertEqual(portlet.position, PortletPositions.below_sidebar.name) self.assertEqual(portlet.weight, 10) self.assertEqual(portlet.html, u'Foo') self.assertEqual(self.request.session.pop_flash(), [u'Portlet "foo" added.'])