示例#1
0
    def test2(self):
        ldictPerson = {
            "key": "897654",
            "type": "Person",
            "name": "Fred",
            "address": {
                "key": "1234567"
            }
        }

        ldictAddress = {
            "key": "1234567",
            "type": "Address",
            "addr1": "1 thing st",
            "city": "stuffville",
            "zipcode": 54321,
            "tags": ['some', 'tags']
        }

        ldictPersonWithAddress = {
            "key": "897654",
            "type": "Person",
            "name": "Fred",
            "address": {
                "key": "1234567",
                "type": "Address",
                "addr1": "1 thing st",
                "city": "stuffville",
                "zipcode": 54321,
                "tags": ['some', 'tags']
            }
        }

        # first store the address
        laddress = gaedocstore.GDSDocument.ConstructFromDict(ldictAddress)
        self.assertIsNotNone(laddress)
        laddress.put()

        # next store the person
        lperson = gaedocstore.GDSDocument.ConstructFromDict(ldictPerson)
        self.assertIsNotNone(lperson)
        lperson.put()

        lgp = ndb.GenericProperty()
        lgp._name = "address.zipcode"
        lqueriedPerson = GDSDocument.query(lgp == 54321).get()
        self.assertIsNotNone(lqueriedPerson,
                             "could not find person with query")

        # lperson should now be populated to match ldictPersonWithAddress
        lpersonDict2 = lqueriedPerson.to_dict()
        self.assertIsNotNone(lpersonDict2)
        self.assertDictEqual(
            lpersonDict2, ldictPersonWithAddress,
            "person has not been correctly updated with address")
示例#2
0
    def test6(self):
        ldict = {"fred":["111", "222"], "larry":{"gertrude": 47}}

        lgdsdocument = gaedocstore.GDSDocument.ConstructFromDict(ldict)
        self.assertIsNotNone(lgdsdocument, "Constructed document should not be none")
        lgdsdocument.put()

        lgp = ndb.GenericProperty()
        lgp._name = "fred"
        lqueriedDocument = GDSDocument.query(lgp == "111").get() 
        self.assertIsNotNone(lqueriedDocument, "could not find document with query")
示例#3
0
    def test6(self):
        ldict = {"fred": ["111", "222"], "larry": {"gertrude": 47}}

        lgdsdocument = gaedocstore.GDSDocument.ConstructFromDict(ldict)
        self.assertIsNotNone(lgdsdocument,
                             "Constructed document should not be none")
        lgdsdocument.put()

        lgp = ndb.GenericProperty()
        lgp._name = "fred"
        lqueriedDocument = GDSDocument.query(lgp == "111").get()
        self.assertIsNotNone(lqueriedDocument,
                             "could not find document with query")
    def test1(self):
        x = GDSDocument()
        #        x.fred = [GDSDocument(), 5]
        x.fred = GDSDocument()
        x.fred.george = GDSDocument()
        x.fred.george.ringo = "wut"

        x.put()

        gp = ndb.GenericProperty()
        gp._name = "fred.george.ringo"
        y = GDSDocument.query(gp == "wut").get()

        self.assertIsNotNone(y)
        self.assertEqual(y.fred.george.ringo, "wut")
示例#5
0
 def test2(self):
     ldictPerson = {
         "key": "897654",
         "type": "Person",
         "name": "Fred",
         "address": {"key": "1234567"}
     }
     
     ldictAddress = {
         "key": "1234567", 
         "type": "Address", 
         "addr1": "1 thing st", 
         "city": "stuffville", 
         "zipcode": 54321,
         "tags": ['some', 'tags']
     }
     
     ldictPersonWithAddress = {
         "key": "897654",
         "type": "Person",
         "name": "Fred",
         "address": 
         {
             "key": "1234567",
             "type": "Address",
             "addr1": "1 thing st",
             "city": "stuffville",
             "zipcode": 54321,
             "tags": ['some', 'tags']
         }
     }
     
     # first store the address
     laddress = gaedocstore.GDSDocument.ConstructFromDict(ldictAddress)
     self.assertIsNotNone(laddress)
     laddress.put()
     
     # next store the person
     lperson = gaedocstore.GDSDocument.ConstructFromDict(ldictPerson)
     self.assertIsNotNone(lperson)
     lperson.put()
     
     lgp = ndb.GenericProperty()
     lgp._name = "address.zipcode"
     lqueriedPerson = GDSDocument.query(lgp == 54321).get() 
     self.assertIsNotNone(lqueriedPerson, "could not find person with query")
     
     # lperson should now be populated to match ldictPersonWithAddress
     lpersonDict2 = lqueriedPerson.to_dict()
     self.assertIsNotNone(lpersonDict2)
     self.assertDictEqual(lpersonDict2, ldictPersonWithAddress, "person has not been correctly updated with address")
示例#6
0
    def test8(self):
        ldictPerson = {
            "key": "897654",
            "type": "Person",
            "name": "Fred",
            "address": {
                "key": "1234567"
            }
        }

        ldictAddress = {
            "key": "1234567",
            "type": "Address",
            "addr1": "1 thing st",
            "city": "stuffville",
            "zipcode": 54321,
            "tags": ['some', 'tags']
        }

        laddressTransform = {
            "fulladdress": "{{.addr1}}, {{.city}} {{.zipcode}}"
        }

        ldictPersonWithTransformedAddress = {
            "key": "897654",
            "type": "Person",
            "name": "Fred",
            "address": {
                "key": "1234567",
                "fulladdress": "1 thing st, stuffville 54321"
            }
        }

        GDSDocument.StorebOTLTransform("address", laddressTransform)

        # first store the address
        laddress = gaedocstore.GDSDocument.ConstructFromDict(ldictAddress)
        self.assertIsNotNone(laddress)
        laddress.put()

        # next store the person
        lperson = gaedocstore.GDSDocument.ConstructFromDict(ldictPerson)
        self.assertIsNotNone(lperson)

        # lperson should now be populated to match ldictPersonWithAddress
        lpersonDict2 = lperson.to_dict()
        self.assertIsNotNone(lpersonDict2)
        self.assertDictEqual(
            lpersonDict2, ldictPersonWithTransformedAddress,
            "person has not been correctly updated with transformed address")
    def convertToGDSAndQuery(self, aDict, aQueryField, aQueryValue):
        lgdsDocument = gaedocstore.DictToGDSDocument(aDict)
        lgdsDocument.put()

        self.assertIsNotNone(lgdsDocument, "lgdsDocument should not be None")

        lgp = ndb.GenericProperty()
        lgp._name = aQueryField
        lgdsDocument = GDSDocument.query(lgp == aQueryValue).get()

        self.assertIsNotNone(lgdsDocument)

        ldict2 = lgdsDocument.to_dict()

        self.assertIsNotNone(ldict2, "ldict2 should not be None")

        self.assertDictEqual(aDict, ldict2)
    def test2(self):
        x = GDSDocument()
        #        x.fred = [GDSDocument(), 5]
        x.fred = GDSDocument()
        x.fred.george = GDSDocument()
        x.fred.george.ringo = "wut"
        x.fred.george.ttt = GDSJson()
        x.fred.george.ttt.json = [3, 4, {'x': 'thingo'}]
        #        x.fred.george.ttt = ndb.JsonProperty()
        #        x.fred.george.ttt = {"item":[3, 4, {'x':'thingo'}]}

        x.put()

        gp = ndb.GenericProperty()
        gp._name = "fred.george.ringo"
        y = GDSDocument.query(gp == "wut").get()

        self.assertIsNotNone(y)
        self.assertEqual(y.fred.george.ringo, "wut")

        z = y.to_dict()
        #        s = FixToDict(z)
        json.dumps(z, indent=True)