Example #1
0
 def test_merge_value(self):
     old = {
         "foo": "bar",
     }
     new = {
         "foo": "quux",
     }
     result = merge_context(old, new)
     assert result["foo"] == ["bar", "quux"], result
Example #2
0
 def test_merge_different(self):
     old = {
         "foo": "quux",
     }
     new = {
         "bar": "quux",
     }
     result = merge_context(old, new)
     assert result["foo"] == ["quux"], result
     assert result["bar"] == ["quux"], result
Example #3
0
    def merge(self, other):
        model = self.schema.model
        self.id = self.id or other.id
        try:
            self.schema = model.common_schema(self.schema, other.schema)
        except InvalidData as e:
            msg = "Cannot merge entities with id %s: %s"
            raise InvalidData(msg % (self.id, e))

        self.context = merge_context(self.context, other.context)
        for prop, values in other._properties.items():
            self.add(prop, values, cleaned=True, quiet=True)
        return self
Example #4
0
    def merge(self, other: "EntityProxy") -> "EntityProxy":
        """Merge another entity proxy into this one. This will try and find
        the common schema between both entities and then add all property
        values from the other entity into this one."""
        model = self.schema.model
        self.id = self.id or other.id
        try:
            self.schema = model.common_schema(self.schema, other.schema)
        except InvalidData as e:
            msg = "Cannot merge entities with id %s: %s"
            raise InvalidData(msg % (self.id, e))

        self.context = merge_context(self.context, other.context)
        for prop, values in other._properties.items():
            self.add(prop, values, cleaned=True, quiet=True)
        return self
Example #5
0
    def merge(self, other):
        model = self.schema.model
        other = self.from_dict(model, other)
        self.id = self.id or other.id
        try:
            self.schema = model.common_schema(self.schema, other.schema)
        except InvalidData as e:
            msg = "Cannot merge entities with id %s: %s"
            raise InvalidData(msg % (self.id, e))

        self.context = merge_context(self.context, other.context)
        self._size = 0
        for prop, values in other._properties.items():
            self._properties.setdefault(prop, set())
            self._properties[prop].update(values)
            self._size += sum([len(v) for v in self._properties[prop]])
        return self