Skip to content

Commit c64adb6

Browse files
Implementation of execute_batch method, refactorings, preparation for 2.2.0 release
1 parent 19b93ba commit c64adb6

File tree

10 files changed

+37
-22
lines changed

10 files changed

+37
-22
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ctx = ClientContext(site_url).with_credentials(UserCredential(username, password
5353
web = ctx.web
5454
ctx.load(web)
5555
ctx.execute_query()
56-
print "Web title: {0}".format(web.properties['Title'])
56+
print("Web title: {0}".format(web.properties['Title']))
5757
```
5858
or alternatively via method chaining (a.k.a Fluent Interface):
5959

@@ -62,7 +62,7 @@ from office365.sharepoint.client_context import ClientContext
6262

6363
ctx = ClientContext(site_url).with_credentials(UserCredential(username, password))
6464
web = ctx.web.load().execute_query()
65-
print "Web title: {0}".format(web.properties['Title'])
65+
print("Web title: {0}".format(web.properties['Title']))
6666
```
6767

6868

@@ -77,7 +77,7 @@ from office365.runtime.http.request_options import RequestOptions
7777
from office365.sharepoint.client_context import ClientContext
7878

7979
ctx = ClientContext(site_url).with_credentials(UserCredential(username, password))
80-
request = RequestOptions("{0}/_api/web/".format(settings['url']))
80+
request = RequestOptions("{0}/_api/web/".format(site_url))
8181
response = ctx.execute_request_direct(request)
8282
json = json.loads(response.content)
8383
web_title = json['d']['Title']

office365/runtime/odata/odata_batch_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def _deserialize_response(self, raw_response):
115115
status_result = re.match(response_status_regex, lines[0])
116116
status_info = status_result.groups()
117117

118-
if status_info[1] == "No Content":
118+
if status_info[1] == "No Content" or len(lines) < 3:
119119
headers_raw = lines[1:]
120120
return {
121121
"status": status_info,

office365/sharepoint/contenttypes/content_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from office365.runtime.resource_path import ResourcePath
33
from office365.runtime.resource_path_service_operation import ResourcePathServiceOperation
44
from office365.sharepoint.base_entity import BaseEntity
5-
from office365.sharepoint.contenttypes.contentTypeId import ContentTypeId
5+
from office365.sharepoint.contenttypes.content_type_id import ContentTypeId
66
from office365.sharepoint.fields.field_collection import FieldCollection
77

88

office365/sharepoint/contenttypes/contentTypeId.py renamed to office365/sharepoint/contenttypes/content_type_id.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
class ContentTypeId(ClientValue):
55

6-
def __init__(self, stringValue=None):
6+
def __init__(self, string_value=None):
77
"""
88
Represents the content type identifier (ID) of a content type.
99
10-
:param str stringValue: Hexadecimal string value of content type identifier. String value MUST start with "0x".
10+
:param str string_value: Hexadecimal string value of content type identifier. String value MUST start with "0x".
1111
"""
1212
super().__init__("SP")
13-
self.StringValue = stringValue
13+
self.StringValue = string_value

office365/sharepoint/files/file_collection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def create_upload_session(self, source_path, chunk_size, chunk_uploaded=None):
1818
:param str source_path: path where file to upload resides
1919
:param int chunk_size: upload chunk size
2020
:param (long)->None or None chunk_uploaded: uploaded event
21-
:return: office365.sharepoint.file.File
21+
:return: office365.sharepoint.files.file.File
2222
"""
2323
qry = UploadSessionQuery(self, source_path, chunk_size, chunk_uploaded)
2424
self.context.add_query(qry)
@@ -27,8 +27,8 @@ def create_upload_session(self, source_path, chunk_size, chunk_uploaded=None):
2727
def add(self, file_creation_information):
2828
"""Creates a File resource
2929
30-
:type file_creation_information: office365.sharepoint.file_creation_information.FileCreationInformation
31-
:return File
30+
:type file_creation_information: office365.sharepoint.files.file_creation_information.FileCreationInformation
31+
:rtype: office365.sharepoint.files.file.File
3232
"""
3333
qry = CreateFileQuery(self, file_creation_information)
3434
self.context.add_query(qry)

office365/sharepoint/lists/list.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,16 @@ def delete_object(self):
148148
self.remove_from_parent_collection()
149149

150150
@property
151-
def enableFolderCreation(self):
151+
def enable_folder_creation(self):
152152
"""
153153
Specifies whether new list folders can be added to the list.
154154
155155
:rtype: bool or None
156156
"""
157157
return self.properties.get("EnableFolderCreation", None)
158158

159-
@enableFolderCreation.setter
160-
def enableFolderCreation(self, value):
159+
@enable_folder_creation.setter
160+
def enable_folder_creation(self, value):
161161
self.set_property("EnableFolderCreation", value, True)
162162

163163
@property
@@ -217,7 +217,7 @@ def forms(self):
217217
FormCollection(self.context, ResourcePath("forms", self.resource_path)))
218218

219219
@property
220-
def itemCount(self):
220+
def item_count(self):
221221
"""Gets a value that specifies the number of list items in the list.
222222
:rtype: int or None
223223
"""

office365/sharepoint/views/view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from office365.runtime.resource_path import ResourcePath
44
from office365.runtime.resource_path_service_operation import ResourcePathServiceOperation
55
from office365.sharepoint.base_entity import BaseEntity
6-
from office365.sharepoint.contenttypes.contentTypeId import ContentTypeId
6+
from office365.sharepoint.contenttypes.content_type_id import ContentTypeId
77
from office365.sharepoint.listitems.caml.camlQuery import CamlQuery
88
from office365.sharepoint.views.view_field_collection import ViewFieldCollection
99

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name="Office365-REST-Python-Client",
13-
version="2.1.10",
13+
version="2.2.0",
1414
author="Vadim Gremyachev",
1515
author_email="[email protected]",
1616
maintainer="Konrad Gądek",

tests/sharepoint/test_sharepoint_client.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,23 @@ def test7_get_and_update_batch_request(self):
7272
client.execute_query()
7373
self.assertEqual(updated_list_item.properties['Title'], new_title)
7474

75-
def test8_delete_batch_request(self):
75+
def test8_create_and_delete_batch_request(self):
7676
pass
7777

7878
def test9_get_and_delete_batch_request(self):
79-
pass
79+
file_name = "TestFile{0}.txt".format(random_seed)
80+
client = ClientContext(settings['url']).with_credentials(user_credentials)
81+
list_pages = client.web.lists.get_by_title("Documents")
82+
files = list_pages.rootFolder.files
83+
client.load(files)
84+
client.execute_query()
85+
files_count_before = len(files)
86+
new_file = list_pages.rootFolder.upload_file(file_name, "-some content goes here-")
87+
client.execute_query()
88+
self.assertTrue(new_file.name, file_name)
89+
90+
new_file.delete_object()
91+
files_after = list_pages.rootFolder.files
92+
client.load(files_after)
93+
client.execute_batch()
94+
self.assertTrue(len(files_after), files_count_before)

tests/sharepoint/test_sharepoint_listItem.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def test1_create_list_item(self):
3838

3939
def test2_enable_folders_in_list(self):
4040
def _init_list():
41-
if not self.target_list.enableFolderCreation:
42-
self.target_list.enableFolderCreation = True
41+
if not self.target_list.enable_folder_creation:
42+
self.target_list.enable_folder_creation = True
4343
self.target_list.update()
4444
self.client.execute_query()
45-
self.assertTrue(self.target_list.enableFolderCreation, "Folder creation enabled")
45+
self.assertTrue(self.target_list.enable_folder_creation, "Folder creation enabled")
4646

4747
self.target_list.ensure_property("EnableFolderCreation", _init_list)
4848
self.client.execute_query()

0 commit comments

Comments
 (0)