Skip to content

Commit 1aedfff

Browse files
author
Bill Prin
committed
Add Parent Field to Resource Manager
1 parent 7f64d75 commit 1aedfff

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

resource_manager/google/cloud/resource_manager/project.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(self, project_id, client, name=None, labels=None):
5858
self.number = None
5959
self.labels = labels or {}
6060
self.status = None
61+
self.parent = None
6162

6263
def __repr__(self):
6364
return '<Project: %r (%r)>' % (self.name, self.project_id)
@@ -85,6 +86,8 @@ def set_properties_from_api_repr(self, resource):
8586
self.number = resource['projectNumber']
8687
self.labels = resource.get('labels', {})
8788
self.status = resource['lifecycleState']
89+
if 'parent' in resource:
90+
self.parent = resource['parent']
8891

8992
@property
9093
def full_name(self):
@@ -202,7 +205,16 @@ def update(self, client=None):
202205
"""
203206
client = self._require_client(client)
204207

205-
data = {'name': self.name, 'labels': self.labels}
208+
data = {}
209+
if self.name:
210+
data['name'] = self.name
211+
212+
if self.labels:
213+
data['labels'] = self.labels
214+
215+
if self.parent:
216+
data['parent'] = self.parent
217+
206218
resp = client._connection.api_request(
207219
method='PUT', path=self.path, data=data)
208220
self.set_properties_from_api_repr(resp)

resource_manager/unit_tests/test_project.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def test_constructor_defaults(self):
3535
self.assertIsNone(project.number)
3636
self.assertEqual(project.labels, {})
3737
self.assertIsNone(project.status)
38+
self.assertIsNone(project.parent)
3839

3940
def test_constructor_explicit(self):
4041
client = object()
@@ -49,6 +50,7 @@ def test_constructor_explicit(self):
4950
self.assertIsNone(project.number)
5051
self.assertEqual(project.labels, LABELS)
5152
self.assertIsNone(project.status)
53+
self.assertIsNone(project.parent)
5254

5355
def test_from_api_repr(self):
5456
client = object()
@@ -57,18 +59,23 @@ def test_from_api_repr(self):
5759
PROJECT_NUMBER = 12345678
5860
PROJECT_LABELS = {'env': 'prod'}
5961
PROJECT_LIFECYCLE_STATE = 'ACTIVE'
62+
PARENT = {'type': 'organization', 'id': 433637338589}
63+
6064
resource = {'projectId': PROJECT_ID,
6165
'name': PROJECT_NAME,
6266
'projectNumber': PROJECT_NUMBER,
6367
'labels': PROJECT_LABELS,
64-
'lifecycleState': PROJECT_LIFECYCLE_STATE}
68+
'lifecycleState': PROJECT_LIFECYCLE_STATE,
69+
'parent': PARENT
70+
}
6571
project = self._get_target_class().from_api_repr(resource, client)
6672
self.assertEqual(project.project_id, PROJECT_ID)
6773
self.assertEqual(project._client, client)
6874
self.assertEqual(project.name, PROJECT_NAME)
6975
self.assertEqual(project.number, PROJECT_NUMBER)
7076
self.assertEqual(project.labels, PROJECT_LABELS)
7177
self.assertEqual(project.status, PROJECT_LIFECYCLE_STATE)
78+
self.assertEqual(project.parent, PARENT)
7279

7380
def test_full_name(self):
7481
PROJECT_ID = 'project-id'
@@ -94,6 +101,10 @@ def test_create(self):
94101
'name': 'Project Name',
95102
'labels': {},
96103
'lifecycleState': 'ACTIVE',
104+
'parent': {
105+
'type': 'organization',
106+
'id': 433637338589
107+
}
97108
}
98109
connection = _Connection(PROJECT_RESOURCE)
99110
client = _Client(connection=connection)
@@ -123,6 +134,10 @@ def test_reload(self):
123134
'name': 'Project Name',
124135
'labels': {'env': 'prod'},
125136
'lifecycleState': 'ACTIVE',
137+
'parent': {
138+
'type': 'organization',
139+
'id': 433637338589
140+
}
126141
}
127142
connection = _Connection(PROJECT_RESOURCE)
128143
client = _Client(connection=connection)
@@ -183,6 +198,10 @@ def test_update(self):
183198
'name': PROJECT_NAME,
184199
'labels': LABELS,
185200
'lifecycleState': 'ACTIVE',
201+
'parent': {
202+
'type': 'organization',
203+
'id': 433637338589
204+
}
186205
}
187206
connection = _Connection(PROJECT_RESOURCE)
188207
client = _Client(connection=connection)
@@ -211,6 +230,10 @@ def test_delete_without_reload_data(self):
211230
'name': 'Project Name',
212231
'labels': {'env': 'prod'},
213232
'lifecycleState': 'ACTIVE',
233+
'parent': {
234+
'type': 'organization',
235+
'id': 433637338589
236+
}
214237
}
215238
connection = _Connection(PROJECT_RESOURCE)
216239
client = _Client(connection=connection)
@@ -234,6 +257,10 @@ def test_delete_with_reload_data(self):
234257
'name': 'Project Name',
235258
'labels': {'env': 'prod'},
236259
'lifecycleState': 'ACTIVE',
260+
'parent': {
261+
'type': 'organization',
262+
'id': 433637338589
263+
}
237264
}
238265
DELETING_PROJECT = PROJECT_RESOURCE.copy()
239266
DELETING_PROJECT['lifecycleState'] = NEW_STATE = 'DELETE_REQUESTED'
@@ -268,6 +295,10 @@ def test_undelete_without_reload_data(self):
268295
'name': 'Project Name',
269296
'labels': {'env': 'prod'},
270297
'lifecycleState': 'DELETE_REQUESTED',
298+
'parent': {
299+
'type': 'organization',
300+
'id': 433637338589
301+
}
271302
}
272303
connection = _Connection(PROJECT_RESOURCE)
273304
client = _Client(connection=connection)
@@ -291,6 +322,10 @@ def test_undelete_with_reload_data(self):
291322
'name': 'Project Name',
292323
'labels': {'env': 'prod'},
293324
'lifecycleState': 'DELETE_REQUESTED',
325+
'parent': {
326+
'type': 'organization',
327+
'id': 433637338589
328+
}
294329
}
295330
UNDELETED_PROJECT = PROJECT_RESOURCE.copy()
296331
UNDELETED_PROJECT['lifecycleState'] = NEW_STATE = 'ACTIVE'

0 commit comments

Comments
 (0)