Beispiel #1
0
 def test9_execute_get_batch_request(self):
     client = ClientContext(test_site_url).with_credentials(test_user_credentials)
     current_user = client.web.current_user
     client.load(current_user)
     current_web = client.web
     client.load(current_web)
     client.execute_batch()
     self.assertIsNotNone(current_web.url)
     self.assertIsNotNone(current_user.user_id)
Beispiel #2
0
    def test_10_execute_update_batch_request(self):
        client = ClientContext(test_site_url).with_credentials(test_user_credentials)
        web = client.web
        new_web_title = create_unique_name("Site")
        web.set_property("Title", new_web_title).update()
        client.execute_batch()

        updated_web = client.web.get().execute_query()
        self.assertEqual(updated_web.properties['Title'], new_web_title)
Beispiel #3
0
 def test5_get_batch_request(self):
     client = ClientContext(settings['url']).with_credentials(user_credentials)
     current_user = client.web.currentUser
     client.load(current_user)
     current_web = client.web
     client.load(current_web)
     client.execute_batch()
     self.assertIsNotNone(current_web.url)
     self.assertIsNotNone(current_user.user_id)
Beispiel #4
0
    def test_11_execute_get_and_update_batch_request(self):
        client = ClientContext(test_site_url).with_credentials(test_user_credentials)
        list_item = client.web.get_file_by_server_relative_url("/SitePages/Home.aspx").listItemAllFields
        new_title = create_unique_name("Page")
        list_item.set_property("Title", new_title).update()
        client.execute_batch()

        updated_list_item = client.web.get_file_by_server_relative_url("/SitePages/Home.aspx").listItemAllFields
        client.load(updated_list_item)
        client.execute_query()
        self.assertEqual(updated_list_item.properties['Title'], new_title)
    def test_10_execute_get_and_update_batch_request(self):
        client = ClientContext(settings['url']).with_credentials(user_credentials)
        list_item = client.web.get_file_by_server_relative_url("/SitePages/Home.aspx").listItemAllFields
        new_title = "Page %s" % random_seed
        list_item.set_property("Title", new_title)
        list_item.update()
        client.execute_batch()

        updated_list_item = client.web.get_file_by_server_relative_url("/SitePages/Home.aspx").listItemAllFields
        client.load(updated_list_item)
        client.execute_query()
        self.assertEqual(updated_list_item.properties['Title'], new_title)
    def test9_execute_update_batch_request(self):
        client = ClientContext(settings['url']).with_credentials(user_credentials)
        web = client.web
        new_web_title = "Site %s" % random_seed
        web.set_property("Title", new_web_title)
        web.update()
        client.execute_batch()

        updated_web = client.web
        client.load(updated_web)
        client.execute_query()
        self.assertEqual(updated_web.properties['Title'], new_web_title)
Beispiel #7
0
    def test_13_get_and_delete_batch_request(self):
        file_name = create_unique_file_name("TestFile", "txt")
        client = ClientContext(test_site_url).with_credentials(test_user_credentials)
        list_pages = client.web.lists.get_by_title("Documents")
        files = list_pages.root_folder.files.get().execute_query()
        files_count_before = len(files)
        new_file = list_pages.root_folder.upload_file(file_name, "-some content goes here-").execute_query()
        self.assertTrue(new_file.name, file_name)

        new_file.delete_object()
        files_after = list_pages.root_folder.files
        client.load(files_after)
        client.execute_batch()
        self.assertTrue(len(files_after), files_count_before)
    def test_12_get_and_delete_batch_request(self):
        file_name = "TestFile{0}.txt".format(random_seed)
        client = ClientContext(settings['url']).with_credentials(user_credentials)
        list_pages = client.web.lists.get_by_title("Documents")
        files = list_pages.rootFolder.files
        client.load(files)
        client.execute_query()
        files_count_before = len(files)
        new_file = list_pages.rootFolder.upload_file(file_name, "-some content goes here-")
        client.execute_query()
        self.assertTrue(new_file.name, file_name)

        new_file.delete_object()
        files_after = list_pages.rootFolder.files
        client.load(files_after)
        client.execute_batch()
        self.assertTrue(len(files_after), files_count_before)
Beispiel #9
0
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.listitems.listitem import ListItem
from tests import test_team_site_url, test_client_credentials

ctx = ClientContext(test_team_site_url).with_credentials(
    test_client_credentials)
items_count = 2

# 1. Load existing list items
list_tasks = ctx.web.lists.get_by_title("Tasks")
items = list_tasks.items.get().top(items_count).execute_query()

# 2. Delete list items (via batch mode)
for item in items:  # type: ListItem
    item.delete_object()
ctx.execute_batch()
print("{0} items have been deleted".format(items_count))
import json

from office365.sharepoint.client_context import ClientContext
from tests import test_team_site_url, test_client_credentials
list_title = "Site Pages"
view_title = "By Author"

ctx = ClientContext(test_team_site_url).with_credentials(
    test_client_credentials)
list_object = ctx.web.lists.get_by_title(list_title)
# 1. First request to retrieve view fields
view_fields = list_object.views.get_by_title(
    view_title).view_fields.get().execute_query()
# 2. Second request to retrieve fields
fields = [
    list_object.fields.get_by_internal_name_or_title(field_name).get()
    for field_name in view_fields
]
ctx.execute_batch(
)  # From performance perspective i would prefer execute_batch over execute_query here

fields_json = {f.internal_name: f.title for f in fields}
print(json.dumps(fields_json))