class ItemTest(unittest.TestCase): def setUp(self): self.item = Item(groups=[ Group(id='main', refs=[ Ref(), Ref(), ]), Group(id='sidebars', refs=[ Ref(idRef='sidebar_0'), Ref(idRef='sidebar_1'), ]), Group(id='sidebar_0', refs=[ Ref(), Ref(), ]), Group(id='sidebar_1', refs=[ Ref(), Ref(), ]), ]) def test_get_refs(self): items = self.item.get_refs('nonexisting') self.assertEquals(0, len(items)) def test_get_items_main(self): items = self.item.get_refs('main') self.assertEquals(2, len(items)) def test_get_items_sidebars(self): items = self.item.get_refs('sidebars') self.assertEquals(4, len(items))
def load_fixture(fixture): """load fixture from given file """ with open('superdesk/fixtures/%s' % fixture) as fp: items = json.load(fp) for item_data in items: item = Item(**item_data) item.save(validate=False)
def package_items(context, **kwargs): item = context['item'] refs = item.get_refs(kwargs['role']) if 'class' in kwargs: refs = [ref for ref in refs if ref.itemClass == kwargs['class']] if 'limit' in kwargs: refs = refs[:kwargs['limit']] items = [] for ref in refs: items.append(Item.objects(guid=ref.residRef).first()) return items
def render(self, context): context.push() nodelist = NodeList() kwargs = self.resolve_kwargs(context) limit = kwargs.get('limit', 55) start = kwargs.get('start', 0) order = kwargs.get('order', '-versionCreated') items = Item.objects(itemClass=kwargs['class'],publishedOn__ne=None).order_by(order)[start:limit] for item in items: context['item'] = item for node in self.nodelist: nodelist.append(node.render(context)) context.pop() return nodelist.render(context)
def setUp(self): self.item = Item(groups=[ Group(id='main', refs=[ Ref(), Ref(), ]), Group(id='sidebars', refs=[ Ref(idRef='sidebar_0'), Ref(idRef='sidebar_1'), ]), Group(id='sidebar_0', refs=[ Ref(), Ref(), ]), Group(id='sidebar_1', refs=[ Ref(), Ref(), ]), ])
def drop_db(scenario): Item.drop_collection()