@@ -318,3 +318,47 @@ def test_repr(target_class):
318318 "Model(reference=ModelReference("
319319 "project_id='my-proj', dataset_id='my_dset', model_id='my_model'))"
320320 )
321+
322+
323+ def test_to_api_repr (target_class ):
324+ from google .protobuf import json_format
325+
326+ model = target_class ("my-proj.my_dset.my_model" )
327+ resource = {
328+ "etag" : "abcdefg" ,
329+ "modelReference" : {
330+ "projectId" : "my-project" ,
331+ "datasetId" : "my_dataset" ,
332+ "modelId" : "my_model" ,
333+ },
334+ "creationTime" : "1274284800000" ,
335+ "lastModifiedTime" : "1317484800000" ,
336+ "modelType" : "LOGISTIC_REGRESSION" ,
337+ "trainingRuns" : [
338+ {
339+ "trainingOptions" : {"initialLearnRate" : 1.0 },
340+ "startTime" : "2010-05-19T16:00:00Z" ,
341+ },
342+ {
343+ "trainingOptions" : {"initialLearnRate" : 0.5 },
344+ "startTime" : "2011-10-01T16:00:00Z" ,
345+ },
346+ {
347+ "trainingOptions" : {"initialLearnRate" : 0.25 },
348+ "startTime" : "2012-12-21T16:00:00Z" ,
349+ },
350+ ],
351+ "description" : "A friendly description." ,
352+ "location" : "US" ,
353+ "friendlyName" : "A friendly name." ,
354+ "labels" : {"greeting" : "こんにちは" },
355+ "expirationTime" : "1356105600000" ,
356+ "encryptionConfiguration" : {
357+ "kmsKeyName" : "projects/1/locations/us/keyRings/1/cryptoKeys/1"
358+ },
359+ }
360+ model ._proto = json_format .ParseDict (
361+ resource , types .Model ()._pb , ignore_unknown_fields = True
362+ )
363+ got = model .to_api_repr ()
364+ assert got == resource
0 commit comments