def test_empty_struct(self): """ Tests that the empty Struct deserializes to {}. """ empty = struct_pb2.Struct() deserialized = rpc.deserialize_resource_props(empty) self.assertDictEqual({}, deserialized)
def RegisterResource(self, request, context): type_ = request.type name = request.name props = rpc.deserialize_resource_props(request.object) deps = request.dependencies outs = {} if type_ != "pulumi:pulumi:Stack": outs = self.langhost_test.register_resource( context, self.dryrun, type_, name, props, deps) if outs.get("urn"): urn = outs["urn"] self.registrations[urn] = { "type": type_, "name": name, "props": props } self.reg_count += 1 if outs.has_key("object"): obj_proto = rpc.serialize_resource_props(outs["object"]) else: obj_proto = None return proto.RegisterResourceResponse(urn=outs.get("urn"), id=outs.get("id"), object=obj_proto)
def RegisterResourceOutputs(self, request, context): urn = request.urn outs = rpc.deserialize_resource_props(request.outputs) res = self.registrations.get(urn) if res: self.langhost_test.register_resource_outputs( context, self.dryrun, urn, res.t, res.name, res.props, outs)
def test_unknown_sentinel(self): """ Tests that we deserialize the UNKNOWN sentinel as None. """ proto = struct_pb2.Struct() # pylint: disable=unsupported-assignment-operation proto["vpc_id"] = rpc.UNKNOWN deserialized = rpc.deserialize_resource_props(proto) self.assertTrue(isinstance(deserialized["vpc_id"], Unknown))
def test_struct_with_nested_struct(self): """ Tests that we deserialize nested Structs correctly. """ proto = struct_pb2.Struct() # pylint: disable=no-member subproto = proto.get_or_create_struct("bar") subproto["baz"] = 42 deserialized = rpc.deserialize_resource_props(proto) self.assertDictEqual({"bar": {"baz": 42}}, deserialized)
def test_string_asset(self): """ Tests that we deserialize string assets correctly. """ proto = struct_pb2.Struct() # pylint: disable=no-member subproto = proto.get_or_create_struct("asset") subproto[rpc._special_sig_key] = rpc._special_asset_sig subproto["text"] = u"this is some text" deserialized = rpc.deserialize_resource_props(proto) self.assertIsInstance(deserialized["asset"], StringAsset) self.assertEqual(u"this is some text", deserialized["asset"].text)
def test_file_asset(self): """ Tests that we deserialize file assets correctly. """ proto = struct_pb2.Struct() # pylint: disable=no-member subproto = proto.get_or_create_struct("asset") subproto[rpc._special_sig_key] = rpc._special_asset_sig subproto["path"] = "foo.txt" deserialized = rpc.deserialize_resource_props(proto) self.assertIsInstance(deserialized["asset"], FileAsset) self.assertEqual("foo.txt", deserialized["asset"].path)
def test_struct_with_list_field(self): """ Tests that we serialize Structs containing Lists to dictionaries containing Python lists. """ proto = struct_pb2.Struct() # pylint: disable=no-member proto_list = proto.get_or_create_list("foo") proto_list.append("42") proto_list.append("bar") proto_list.append("baz") deserialized = rpc.deserialize_resource_props(proto) self.assertDictEqual({"foo": ["42", "bar", "baz"]}, deserialized)
def ReadResource(self, request, context): type_ = request.type name = request.name id_ = request.id parent = request.parent state = rpc.deserialize_resource_props(request.properties) outs = self.langhost_test.read_resource(context, type_, name, id_, parent, state) if outs.has_key("properties"): props_proto = rpc.serialize_resource_props(outs["properties"]) else: props_proto = None return proto.ReadResourceResponse(urn=outs.get("urn"), properties=props_proto)
def Invoke(self, request, context): args = rpc.deserialize_resource_props(request.args) failures, ret = self.langhost_test.invoke(context, request.tok, args) return proto.InvokeResponse(failures=failures, ret=ret)