def test_find_item_lazy(self): lazy_attribute = lazy(lambda x: x, str)('Test') api = ToolbarAPIMixin() api.add_link_item(lazy_attribute, None) result = api.find_first(LinkItem, name='Test') self.assertNotEqual(result, None) self.assertEqual(result.index, 0)
def test_find_item_lazy(self): lazy_attribute = lazy(lambda x: x, str)("Test") api = ToolbarAPIMixin() api.add_link_item(lazy_attribute, None) result = api.find_first(LinkItem, name="Test") self.assertNotEqual(result, None) self.assertEqual(result.index, 0)
def test_find_item(self): api = ToolbarAPIMixin() first = api.add_link_item('First', 'http://www.example.org') second = api.add_link_item('Second', 'http://www.example.org') all_links = api.find_items(LinkItem) self.assertEqual(len(all_links), 2) result = api.find_first(LinkItem, name='First') self.assertNotEqual(result, None) self.assertEqual(result.index, 0) self.assertEqual(result.item, first) result = api.find_first(LinkItem, name='Second') self.assertNotEqual(result, None) self.assertEqual(result.index, 1) self.assertEqual(result.item, second) no_result = api.find_first(LinkItem, name='Third') self.assertEqual(no_result, None)
def test_find_item(self): api = ToolbarAPIMixin() first = api.add_link_item("First", "http://www.example.org") second = api.add_link_item("Second", "http://www.example.org") all_links = api.find_items(LinkItem) self.assertEqual(len(all_links), 2) result = api.find_first(LinkItem, name="First") self.assertNotEqual(result, None) self.assertEqual(result.index, 0) self.assertEqual(result.item, first) result = api.find_first(LinkItem, name="Second") self.assertNotEqual(result, None) self.assertEqual(result.index, 1) self.assertEqual(result.item, second) no_result = api.find_first(LinkItem, name="Third") self.assertEqual(no_result, None)