@@ -99,6 +99,57 @@ def test_get(self):
9999 self .assertEqual ("service_instance_id" , service_instance ["guid" ])
100100 self .assertIsInstance (service_instance , Entity )
101101
102+ def test_get_fields_space (self ):
103+ self .client .get .return_value = self .mock_response (
104+ "/v3/service_instances/service_instance_id"
105+ "?fields[space]=guid,name,relationships.organization"
106+ "&fields[space.organization]=guid,name" ,
107+ HTTPStatus .OK ,
108+ None ,
109+ "v3" ,
110+ "service_instances" ,
111+ "GET_{id}_response_fields_space.json"
112+ )
113+ fields = {
114+ "space" : ["guid,name,relationships.organization" ],
115+ "space.organization" : ["guid" , "name" ],
116+ }
117+ space = self .client .v3 .service_instances .get ("service_instance_id" , fields = fields ).space ()
118+ self .client .get .assert_called_with (self .client .get .return_value .url )
119+ self .assertEqual ("my_space" , space ["name" ])
120+ self .assertIsInstance (space , Entity )
121+
122+ def test_list_fields_space_and_org (self ):
123+ self .client .get .return_value = self .mock_response (
124+ "/v3/service_instances"
125+ "?fields[space]=guid,name,relationships.organization"
126+ "&fields[space.organization]=guid,name" ,
127+ HTTPStatus .OK ,
128+ None ,
129+ "v3" ,
130+ "service_instances" ,
131+ "GET_response_fields_space_and_org.json"
132+ )
133+ fields = {
134+ "space" : ["guid,name,relationships.organization" ],
135+ "space.organization" : ["guid" , "name" ]
136+ }
137+ all_spaces = [app .space () for app in self .client .v3 .service_instances .list (fields = fields )]
138+ self .client .get .assert_called_with (self .client .get .return_value .url )
139+ self .assertEqual (2 , len (all_spaces ))
140+ space1 = all_spaces [0 ]
141+ self .assertEqual (space1 ["name" ], "my_space" )
142+ space1_org = space1 .organization ()
143+ self .assertEqual (space1_org ["name" ], "my_organization" )
144+ self .assertIsInstance (space1 , Entity )
145+ self .assertIsInstance (space1_org , Entity )
146+ space2 = all_spaces [1 ]
147+ self .assertEqual (space2 ["name" ], "my_space" )
148+ space2_org = space2 .organization ()
149+ self .assertEqual (space2_org ["name" ], "my_organization" )
150+ self .assertIsInstance (space2 , Entity )
151+ self .assertIsInstance (space2_org , Entity )
152+
102153 def test_get_then_credentials (self ):
103154 get_service_instance = self .mock_response (
104155 "/v3/service_instances/service_instance_id" , HTTPStatus .OK , None , "v3" , "service_instances" , "GET_{id}_response.json" )
0 commit comments