Skip to content

Commit 190e9dd

Browse files
Refactorings & improvements (fluent interface for ClientResult, crud operations moved to base entity classes), bug fixes
1 parent 48eebbf commit 190e9dd

File tree

87 files changed

+345
-386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+345
-386
lines changed

examples/directory/delete_groups.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
print("Group deleted.")
1414
index += 1
1515

16-
deleted_groups = client.directory.deletedGroups.get().execute_query()
16+
deleted_groups = client.directory.deleted_groups.get().execute_query()
1717
groups_count = len(deleted_groups)
1818
index = 0
1919
while len(deleted_groups) > 0:

office365/actions/download_content_query.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def __init__(self, entity_type, format_name=None):
99
:type entity_type: office365.runtime.client_object.ClientObject
1010
:type format_name: str or None
1111
"""
12-
result = ClientResult(None)
12+
result = ClientResult(entity_type.context)
1313
action_name = "content"
1414
if format_name is not None:
1515
action_name = action_name + r"?format={0}".format(format_name)

office365/directory/application.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def delete_object(self, permanent_delete=False):
3737
"""
3838
super(Application, self).delete_object()
3939
if permanent_delete:
40-
deleted_item = self.context.directory.deletedApplications[self.id]
40+
deleted_item = self.context.directory.deleted_applications[self.id]
4141
deleted_item.delete_object()
4242
return self
4343

office365/directory/directory.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ class Directory(Entity):
88
"container". Deleted items will remain available to restore for up to 30 days. After 30 days, the items are
99
permanently deleted. """
1010

11-
def deletedItems(self, entity_type=None):
11+
def deleted_items(self, entity_type=None):
1212
"""Recently deleted items. Read-only. Nullable."""
1313
if entity_type:
14-
return DirectoryObjectCollection(self.context, ResourcePath(entity_type,
15-
ResourcePath("deletedItems",
16-
self.resource_path)))
14+
return DirectoryObjectCollection(self.context,
15+
ResourcePath(entity_type,
16+
ResourcePath("deletedItems", self.resource_path)))
1717
else:
1818
return self.properties.get('deletedItems',
1919
DirectoryObjectCollection(self.context,
2020
ResourcePath("deletedItems", self.resource_path)))
2121

2222
@property
23-
def deletedGroups(self):
23+
def deleted_groups(self):
2424
"""Recently deleted groups"""
25-
return self.deletedItems("microsoft.graph.group")
25+
return self.deleted_items("microsoft.graph.group")
2626

2727
@property
28-
def deletedUsers(self):
28+
def deleted_users(self):
2929
"""Recently deleted users"""
30-
return self.deletedItems("microsoft.graph.user")
30+
return self.deleted_items("microsoft.graph.user")
3131

3232
@property
33-
def deletedApplications(self):
33+
def deleted_applications(self):
3434
"""Recently deleted applications"""
35-
return self.deletedItems("microsoft.graph.application")
35+
return self.deleted_items("microsoft.graph.application")

office365/directory/directoryObject.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from office365.entity import Entity
22
from office365.runtime.client_result import ClientResult
3+
from office365.runtime.client_value_collection import ClientValueCollection
34
from office365.runtime.queries.service_operation_query import ServiceOperationQuery
45

56

@@ -12,7 +13,7 @@ def get_member_objects(self, security_enabled_only=True):
1213
This function is transitive.
1314
1415
:type security_enabled_only: bool"""
15-
result = ClientResult(None)
16+
result = ClientResult(self.context, ClientValueCollection(str))
1617
payload = {
1718
"securityEnabledOnly": security_enabled_only
1819
}
@@ -25,7 +26,7 @@ def get_member_groups(self, security_enabled_only=True):
2526
transitive.
2627
2728
:type security_enabled_only: bool"""
28-
result = ClientResult(None)
29+
result = ClientResult(self.context)
2930
payload = {
3031
"securityEnabledOnly": security_enabled_only
3132
}

office365/directory/directoryObjectCollection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __getitem__(self, key):
2626

2727
def getByIds(self, ids):
2828
"""Returns the directory objects specified in a list of IDs."""
29-
result = ClientResult(None)
29+
result = ClientResult(self.context)
3030
qry = ServiceOperationQuery(self, "getByIds", None, None, None, result)
3131
self.context.add_query(qry)
3232
return result

office365/directory/group.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def check_member_groups(self, group_ids):
4242
4343
:type group_ids: list
4444
"""
45-
result = ClientResult(None)
45+
result = ClientResult(self.context)
4646
qry = ServiceOperationQuery(self, "checkMemberGroups", None, group_ids, None, result)
4747
self.context.add_query(qry)
4848
return result
@@ -72,7 +72,7 @@ def delete_object(self, permanent_delete=False):
7272
"""
7373
super(Group, self).delete_object()
7474
if permanent_delete:
75-
deleted_item = self.context.directory.deletedGroups[self.id]
75+
deleted_item = self.context.directory.deleted_groups[self.id]
7676
deleted_item.delete_object()
7777
return self
7878

@@ -106,7 +106,7 @@ def events(self):
106106
return self.properties.get('events', EventCollection(self.context, ResourcePath("events", self.resource_path)))
107107

108108
@property
109-
def appRoleAssignments(self):
109+
def app_role_assignments(self):
110110
"""Get an event collection or an appRoleAssignments."""
111111
return self.properties.get('appRoleAssignments',
112112
AppRoleAssignmentCollection(self.context,

office365/directory/permission.py

+3-16
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,13 @@
88
class Permission(Entity):
99
"""The Permission resource provides information about a sharing permission granted for a DriveItem resource."""
1010

11-
def update(self):
12-
"""Updates the Permission entity."""
13-
qry = UpdateEntityQuery(self)
14-
self.context.add_query(qry)
15-
return self
16-
17-
def delete_object(self):
18-
"""Deletes the Permission entity."""
19-
qry = DeleteEntityQuery(self)
20-
self.context.add_query(qry)
21-
self.remove_from_parent_collection()
22-
return self
23-
2411
@property
2512
def invitation(self):
2613
"""For user type permissions, the details of the users & applications for this permission."""
2714
return self.properties.get('invitation', SharingInvitation())
2815

2916
@property
30-
def grantedTo(self):
17+
def granted_to(self):
3118
"""For user type permissions, the details of the users & applications for this permission."""
3219
return self.properties.get('grantedTo', IdentitySet())
3320

@@ -37,15 +24,15 @@ def roles(self):
3724
return self.properties.get('roles', [])
3825

3926
@property
40-
def shareId(self):
27+
def share_id(self):
4128
"""A unique token that can be used to access this shared item via the shares API. Read-only.
4229
4330
:rtype: str
4431
"""
4532
return self.properties.get('shareId', None)
4633

4734
@property
48-
def hasPassword(self):
35+
def has_password(self):
4936
"""This indicates whether password is set for this permission, it's only showing in response.
5037
Optional and Read-only and for OneDrive Personal only.
5138

office365/directory/user.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def delete_object(self, permanent_delete=False):
142142
"""
143143
super(User, self).delete_object()
144144
if permanent_delete:
145-
deleted_user = self.context.directory.deletedUsers[self.id]
145+
deleted_user = self.context.directory.deleted_users[self.id]
146146
deleted_user.delete_object()
147147
return self
148148

office365/entity.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
class Entity(ClientObject):
8+
"""Base entity"""
89

910
def update(self):
1011
"""Updates the entity."""
@@ -40,7 +41,5 @@ def id(self):
4041
def set_property(self, name, value, persist_changes=True):
4142
super(Entity, self).set_property(name, value, persist_changes)
4243
if name == "id" and self._resource_path is None:
43-
self._resource_path = ResourcePath(
44-
value,
45-
self._parent_collection.resource_path)
44+
self._resource_path = ResourcePath(value,self._parent_collection.resource_path)
4645
return self

office365/onedrive/columnDefinitionCollection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from office365.entity_collection import EntityCollection
12
from office365.onedrive.columnDefinition import ColumnDefinition
2-
from office365.runtime.client_object_collection import ClientObjectCollection
33

44

5-
class ColumnDefinitionCollection(ClientObjectCollection):
5+
class ColumnDefinitionCollection(EntityCollection):
66
"""Drive column's collection"""
77

88
def __init__(self, context, resource_path=None):

office365/onedrive/driveItem.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def create_upload_session(self, item):
120120
121121
:type item: office365.graph.onedrive.driveItemUploadableProperties.DriveItemUploadableProperties
122122
"""
123-
result = ClientResult(UploadSession())
123+
result = ClientResult(self.context, UploadSession())
124124
qry = ServiceOperationQuery(self,
125125
"createUploadSession",
126126
None,
@@ -157,6 +157,9 @@ def get_content(self):
157157
return qry.return_type
158158

159159
def download(self, file_object):
160+
"""
161+
:type file_object: typing.IO
162+
"""
160163
result = self.get_content()
161164

162165
def _content_downloaded(resp):
@@ -198,7 +201,7 @@ def copy(self, name, parent_reference=None):
198201
:type name: str
199202
:type parent_reference: ItemReference or None
200203
"""
201-
result = ClientResult(None)
204+
result = ClientResult(self.context)
202205
qry = ServiceOperationQuery(self,
203206
"copy",
204207
None,
@@ -220,7 +223,7 @@ def move(self, name, parent_reference=None):
220223
:type parent_reference: ItemReference
221224
"""
222225

223-
result = ClientResult(None)
226+
result = ClientResult(self.context)
224227
qry = ServiceOperationQuery(self,
225228
"move",
226229
None,
@@ -244,7 +247,7 @@ def search(self, query_text):
244247
a whole drive, or files shared with the current user.
245248
246249
:type query_text: str"""
247-
result = ClientResult(None)
250+
result = ClientResult(self.context)
248251
qry = SearchQuery(self, query_text, result)
249252
self.context.add_query(qry)
250253
return result
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from office365.entity_collection import EntityCollection
12
from office365.onedrive.driveItemVersion import DriveItemVersion
2-
from office365.runtime.client_object_collection import ClientObjectCollection
33

44

5-
class DriveItemVersionCollection(ClientObjectCollection):
5+
class DriveItemVersionCollection(EntityCollection):
66

77
def __init__(self, context, resource_path=None):
88
super(DriveItemVersionCollection, self).__init__(context, DriveItemVersion, resource_path)

office365/runtime/client_object_collection.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def create_typed_object(self, properties):
4747
return client_object
4848

4949
def set_property(self, name, value, persist_changes=False):
50+
"""
51+
:type name: str
52+
:type value: any
53+
:type persist_changes: bool
54+
"""
5055
child_client_object = self.create_typed_object(value)
5156
self.add_child(child_client_object)
5257

@@ -60,7 +65,10 @@ def add_child(self, client_object):
6065
self._data.append(client_object)
6166

6267
def remove_child(self, client_object):
63-
self._data.remove(client_object)
68+
"""
69+
:type client_object: ClientObject
70+
"""
71+
self._data = [item for item in self._data if item != client_object]
6472

6573
def __iter__(self):
6674
"""
@@ -128,7 +136,7 @@ def get_items_count(self):
128136
Gets total items count
129137
:return: ClientResult
130138
"""
131-
result = ClientResult(None)
139+
result = ClientResult(self.context)
132140

133141
def _calc_items_count(resp):
134142
list(iter(self))

office365/runtime/client_request.py

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def add_query(self, query, to_begin=False):
5252
self._current_query = query
5353

5454
def remove_query(self, query):
55+
"""
56+
:type query: office365.runtime.queries.client_query.ClientQuery
57+
"""
5558
self._queries.remove(query)
5659
self._current_query = None
5760

office365/runtime/client_result.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
from office365.runtime.client_object import ClientObject
2-
from office365.runtime.client_value import ClientValue
3-
4-
51
class ClientResult(object):
62
"""Client result"""
73

8-
def __init__(self, value):
9-
self._value = value
4+
def __init__(self, context, default_value=None):
5+
"""
6+
7+
:type context: office365.runtime.client_runtime_context.ClientRuntimeContext
8+
:type default_value: any
9+
"""
10+
self.context = context
11+
self.value = default_value
1012

11-
@property
12-
def value(self):
13-
return self._value
13+
def build_request(self):
14+
return self.context.build_request()
1415

15-
@value.setter
16-
def value(self, value):
17-
self._value = value
16+
def execute_query(self):
17+
self.context.execute_query()
18+
return self
1819

19-
def set_property(self, key, value, persist_changes=False):
20-
if isinstance(self._value, ClientValue) or isinstance(self._value, ClientObject):
21-
self._value.set_property(key, value, persist_changes)
22-
else:
23-
self._value = value

office365/runtime/client_runtime_context.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _process_response(response):
125125

126126
def execute_request_direct(self, request):
127127
"""
128-
:type request: RequestOptions
128+
:type request: office365.runtime.http.request_options.RequestOptions
129129
"""
130130
return self.pending_request().execute_request_direct(request)
131131

0 commit comments

Comments
 (0)