Пример #1
0
 def create(self, obj: ParaObject):
     """
     Persists an object to the data store. If the object's type and id are given,
     then the request will be a {@code PUT} request and any existing object will be overwritten.
     @param obj: the domain object
     @return: the same object with assigned id or null if not created.
     """
     if not obj:
         return None
     if obj.id and obj.type:
         return self.getEntity(self.invokePut(obj.getObjectURI(), obj.jsonSerialize()), False)
     else:
         return self.getEntity(self.invokePost(self.urlenc(obj.type), obj.jsonSerialize()), False)
Пример #2
0
 def update(self, obj: ParaObject):
     """
     Updates an object permanently. Supports partial updates.
     @param obj: the object to update
     @return: updated object
     """
     if not obj:
         return None
     return self.getEntity(self.invokePatch(obj.getObjectURI(), obj.jsonSerialize()), False)
Пример #3
0
    def testSetFields(self):
        o1 = ParaObject("123", "dog")
        o1.one = 1
        o1.two = "two"

        assert o1.type == "dog"
        assert o1.id == "123"

        obj = json.loads(o1.jsonSerialize())
        obj1 = ParaObject()
        obj1.setFields(obj)

        assert obj1.type == "dog"
        assert obj1.id == "123"
        assert obj1.two == "two"