Exemple #1
0
 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')
Exemple #2
0
    def testQueryNoResults(self):
        fd = FetchDefinition(Foo)
        results = fetch(fd, filter=Foo.name=='NOTHING MATCHES THIS')
        self.assertTrue(len(results)==0, "non empty results returned")

        results2, curs, more = fetch_page(fd, 10, filter=Foo.name=='NOTHING MATCHES THIS')
        self.assertTrue(len(results2)==0, "non empty results returned")
Exemple #3
0
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)
Exemple #4
0
 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, [])
Exemple #5
0
 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)
Exemple #6
0
    def testCustomTransformMoodel(self):
        def custom_transform(o):
            o.testattr=True
            return o
        fd=testmodels.get_a1_fullfetchdef()
        filter=testmodels.A1.name=='Full Graph'
        results=fetch(fd, filter=filter, transform=custom_transform)
        
        a1=results[0]
        self.assertTrue(a1.testattr, "testattr should be set to true by custom_transform")
        self.assertFalse(hasattr(a1,'id'), "id attribute has been set even though the custom transform was used.")

        # also test for models deeper in the graph
        self.assertTrue(a1.b1s[0].testattr, "testattr should be set to true by custom_transform")
        self.assertFalse(hasattr(a1.b1s[0],'id'), "id attribute has been set even though the custom transform was used.")

        self.assertTrue(a1.c1.testattr, "testattr should be set to true by custom_transform")
        self.assertFalse(hasattr(a1.c1,'id'), "id attribute has been set even though the custom transform was used.")

        self.assertTrue(a1.d1s[0].testattr, "testattr should be set to true by custom_transform")
        self.assertFalse(hasattr(a1.d1s[0],'id'), "id attribute has been set even though the custom transform was used.")
Exemple #7
0
def get_customer_with_orders_and_details(customer_key):
    customer_fetch=orders.get_full_order_fetchdef()
    customer = graphfetch.fetch(customer_fetch, key=customer_key)
    return customer
Exemple #8
0
 def testBasicKeyList(self):
     fd = FetchDefinition(Foo)
     foo = fetch(fd, filter=Foo.name=='joe')[0]
     self.assertEqual(foo.name, 'joe', "name incorrect")
Exemple #9
0
 def testQueryAll(self):
     fd = FetchDefinition(Foo)
     results = fetch(fd)
     self.assertEqual(len(results), 3, "Querying with no keys, future or filter should return all entities")
Exemple #10
0
 def testBasicQuery(self):
     fd = FetchDefinition(Foo)
     foo = fetch(fd, filter=Foo.name=='joe')[0]
     self.assertJoe(foo)
Exemple #11
0
 def testKeyQuery(self):
     fd = FetchDefinition(Foo)
     key = ndb.Key(Foo, 101)
     foo = fetch(fd, key=key)
     self.assertJoe(foo)
Exemple #12
0
 def testSetup(self):
     fd=orders.get_full_order_fetchdef()
     filter=orders.Customer.account_id>=-1
     values = fetch(fd, filter=filter)
     customer=values[0]
     self.assertTrue(isinstance(customer.orders, types.ListType), "Customer.orders should be a list")
Exemple #13
0
 def testFullGraphBasicImpl(self):
     from graphfetch import basic_graphfetch
     fd=testmodels.get_a1_fullfetchdef()
     filter=testmodels.A1.name=='Full Graph'
     results=fetch(fd, filter=filter, impl=basic_graphfetch.fetch_basic)
     self.assertFullGraphResults(results)
Exemple #14
0
 def testFullGraph(self):
     fd=testmodels.get_a1_fullfetchdef()
     filter=testmodels.A1.name=='Full Graph'
     results=fetch(fd, filter=filter)
     self.assertFullGraphResults(results)
Exemple #15
0
def get_a1(id, impl=None):
    a1_fd = get_a1_fullfetchdef()
    key = ndb.Key(A1, long(id))
    return graphfetch.fetch(a1_fd, key=key, impl=impl)
Exemple #16
0
def get_a1_by_key(id):
    a1_fd = get_a1_fullfetchdef()
    key = ndb.Key(A1, id)
    return graphfetch.fetch(a1_fd, keys=key)