def testSortKey(self): from graphfetch import basic_graphfetch fd = FetchDefinition(testmodels.A1) fd.attach(kind=Target, attachment_type=SOURCE_LIST, sort_key=lambda elem: elem.order) key=ndb.Key(Source, 100) s1=fetch(fd, key=key) self.assertEqual(s1.targets[0].name, 't1')
def get_invoice(invoice_id): invoice_fd = FetchDefinition(kind=Invoice) invoice_fd.attach(kind=Customer, attachment_type=SOURCE_KEY) invoice_fd.attach(kind=Instruction, attachment_TYPE=TARGET_KEY) line_fd = invoice_fd.attach(kind=Line, attachment_type=SOURCE_LIST) line_fd.attach(kind=Item, attachment_type=SOURCE_KEY) key = ndb.Key(Invoice, invoice_id) return fetch(invoice_fd, keys=key)
def testBrokenSourceListReference(self): tbd = Target(name="to be deleted") tbd.put() source = Source(name="source") source.target_keys.append(tbd.key) source.put() tbd.key.delete() fd=FetchDefinition(Source) fd.attach(Target, SOURCE_LIST) result = fetch(fd, key=source.key, transform=lambda x: x) self.assertEqual(result.targets, [])
def testBrokenSourceKeyReference(self): tbd = Source(name="to be deleted") tbd.put() target = Target(name="target", source_key=tbd.key) target.put() tbd.key.delete() fd=FetchDefinition(Target) fd.attach(Source, SOURCE_KEY) result = fetch(fd, key=target.key, transform=lambda x: x) self.assertIsNone(result.source)