Skip to content

Commit 615211c

Browse files
committed
Examples update & Planner API fixes
1 parent 124423a commit 615211c

Some content is hidden

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

51 files changed

+384
-103
lines changed

examples/directory/users/create_activity.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

examples/informationprotection/create_mail_assessment.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
44
"""
55
from office365.graph_client import GraphClient
6-
from tests.graph_case import acquire_token_by_username_password
6+
from tests import test_client_id, test_password, test_tenant, test_username
77

8-
client = GraphClient(acquire_token_by_username_password)
8+
client = GraphClient.with_username_and_password(
9+
test_tenant, test_client_id, test_username, test_password
10+
)
911
messages = client.me.messages.get().filter("isDraft eq false").top(1).execute_query()
1012
result = client.information_protection.create_mail_assessment(
1113
messages[0]

examples/onedrive/bundles/create.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
https://learn.microsoft.com/en-us/graph/api/drive-post-bundles?view=graph-rest-1.0&tabs=http#example-1-create-a-bundle
55
"""
66
from office365.graph_client import GraphClient
7-
from tests.graph_case import acquire_token_by_username_password
7+
from tests import test_client_id, test_password, test_tenant, test_username
88

9-
client = GraphClient(acquire_token_by_username_password)
9+
client = GraphClient.with_username_and_password(
10+
test_tenant, test_client_id, test_username, test_password
11+
)
1012
file_item = client.me.drive.root.get_by_path("Sample.html").get().execute_query()
1113
bundle = client.me.drive.create_bundle(
1214
"Just some files", [file_item.id]

examples/onedrive/columns/create_text.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@
55
"""
66

77
from office365.graph_client import GraphClient
8-
from tests import create_unique_name
9-
from tests.graph_case import acquire_token_by_username_password
8+
from tests import (
9+
create_unique_name,
10+
test_client_id,
11+
test_password,
12+
test_tenant,
13+
test_username,
14+
)
1015

11-
client = GraphClient(acquire_token_by_username_password)
12-
lib = client.sites.root.lists["Docs"]
16+
client = GraphClient.with_username_and_password(
17+
test_tenant, test_client_id, test_username, test_password
18+
)
19+
lib = client.sites.root.lists["Documents"]
1320
column_name = create_unique_name("TextColumn")
1421
column = lib.columns.add_text(column_name).execute_query()
1522
print(column.display_name)

examples/onedrive/drives/list_shared_with_me.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
https://learn.microsoft.com/en-us/graph/api/drive-sharedwithme?view=graph-rest-1.0
55
"""
66
from office365.graph_client import GraphClient
7-
from tests.graph_case import acquire_token_by_username_password
7+
from tests import test_client_id, test_password, test_tenant, test_username
88

9-
client = GraphClient(acquire_token_by_username_password)
9+
client = GraphClient.with_username_and_password(
10+
test_tenant, test_client_id, test_username, test_password
11+
)
1012
drive_items = client.me.drive.shared_with_me().execute_query()
1113
for item in drive_items:
1214
print("Drive Item url: {0}".format(item.web_url))

examples/onedrive/excel/read_table.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
44
https://learn.microsoft.com/en-us/graph/api/resources/excel?view=graph-rest-1.0#get-list-of-table-rows
55
"""
6-
from examples.onedrive import upload_excel_sample
76
from office365.graph_client import GraphClient
8-
from tests.graph_case import acquire_token_by_username_password
7+
from tests import test_client_id, test_password, test_tenant, test_username
98

10-
client = GraphClient(acquire_token_by_username_password)
11-
drive_item = upload_excel_sample(client)
9+
client = GraphClient.with_username_and_password(
10+
test_tenant, test_client_id, test_username, test_password
11+
)
12+
drive_item = client.me.drive.root.get_by_path("Financial Sample.xlsx")
1213
table = (
1314
drive_item.workbook.worksheets["Sheet1"].tables["financials"].get().execute_query()
1415
)

examples/onedrive/files/copy_file.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
This example copies a file identified by {server relative path} into a folder identified with a {server relative path}.
33
The new copy of the file will be named Sample (copy).rtf.
44
5-
https://learn.microsoft.com/en-us/graph/api/driveitem-copy?view=graph-rest-1.0&tabs=http
5+
https://learn.microsoft.com/en-us/graph/api/driveitem-copy?view=graph-rest-1.0
66
"""
77
from office365.graph_client import GraphClient
8-
from tests.graph_case import acquire_token_by_username_password
8+
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient(acquire_token_by_username_password)
10+
client = GraphClient.with_username_and_password(
11+
test_tenant, test_client_id, test_username, test_password
12+
)
1113
source_path = "archive/Sample.rtf"
1214
new_name = "Sample (copy).rtf"
1315
target_path = "archive/2018"

examples/onedrive/files/download.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
import tempfile
88

99
from office365.graph_client import GraphClient
10+
from tests import test_client_id, test_password, test_tenant, test_username
1011
from tests.graph_case import acquire_token_by_username_password
1112

12-
client = GraphClient(acquire_token_by_username_password)
13+
client = GraphClient.with_username_and_password(
14+
test_tenant, test_client_id, test_username, test_password
15+
)
1316
# 1. address file by path
1417
# remote_path = "archive/countries.json"
1518
remote_path = "archive/Financial Sample.xlsx"

examples/onedrive/files/download_large.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
import tempfile
1111

1212
from office365.graph_client import GraphClient
13-
from tests.graph_case import acquire_token_by_username_password
13+
from tests import test_client_id, test_password, test_tenant, test_username
1414

1515

1616
def print_progress(offset):
1717
# type: (int) -> None
1818
print("Downloaded '{0}' bytes...".format(offset))
1919

2020

21-
client = GraphClient(acquire_token_by_username_password)
21+
client = GraphClient.with_username_and_password(
22+
test_tenant, test_client_id, test_username, test_password
23+
)
2224
# # 1. address file by path and get file metadata
2325
file_item = (
2426
client.me.drive.root.get_by_path("archive/big_buck_bunny.mp4").get().execute_query()

examples/onedrive/files/get_by_abs_url.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22
Retrieves file by absolute url
33
"""
44
from office365.graph_client import GraphClient
5-
from tests import test_team_site_url
6-
from tests.graph_case import acquire_token_by_username_password
5+
from tests import (
6+
test_client_id,
7+
test_password,
8+
test_team_site_url,
9+
test_tenant,
10+
test_username,
11+
)
712

813
file_abs_url = "{0}/Shared Documents/Financial Sample.xlsx".format(test_team_site_url)
914

10-
client = GraphClient(acquire_token_by_username_password)
15+
client = GraphClient.with_username_and_password(
16+
test_tenant, test_client_id, test_username, test_password
17+
)
1118
file_item = client.shares.by_url(file_abs_url).drive_item.get().execute_query()
1219
print(file_item.web_url)

examples/onedrive/files/move_file.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
https://learn.microsoft.com/en-us/graph/api/driveitem-move?view=graph-rest-1.0
66
"""
77
from office365.graph_client import GraphClient
8-
from tests.graph_case import acquire_token_by_username_password
8+
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient(acquire_token_by_username_password)
10+
client = GraphClient.with_username_and_password(
11+
test_tenant, test_client_id, test_username, test_password
12+
)
1113
source_path = "archive/Sample.rtf"
1214
target_path = "archive/2018"
1315
source_file_item = client.me.drive.root.get_by_path(source_path)

examples/onedrive/files/search.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"""
66

77
from office365.graph_client import GraphClient
8-
from tests.graph_case import acquire_token_by_username_password
8+
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient(acquire_token_by_username_password)
10+
client = GraphClient.with_username_and_password(
11+
test_tenant, test_client_id, test_username, test_password
12+
)
1113
result = client.search.query_drive_items("Guide.docx").execute_query()
1214
for item in result.value:
1315
for hit_container in item.hitsContainers:

examples/onedrive/files/send_sharing_invitation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
from datetime import datetime, timedelta
1010

1111
from office365.graph_client import GraphClient
12+
from tests import test_client_id, test_password, test_tenant, test_username
1213
from tests.graph_case import acquire_token_by_username_password
1314

1415
file_name = "Financial Sample.xlsx"
15-
client = GraphClient(acquire_token_by_username_password)
16+
client = GraphClient.with_username_and_password(
17+
test_tenant, test_client_id, test_username, test_password
18+
)
1619
file_item = client.me.drive.root.get_by_path(file_name)
1720
expired = datetime.utcnow() + timedelta(days=1)
1821
permissions = file_item.invite(

examples/onedrive/files/upload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
1616
folder = client.users.get_by_principal_name(test_user_principal_name_alt).drive.root
1717

18-
# local_path = "../../data/Financial Sample.xlsx"
19-
local_path = "../../data/countries.json"
18+
local_path = "../../data/Financial Sample.xlsx"
19+
# local_path = "../../data/countries.json"
2020
# file = folder.upload_file(local_path).execute_query()
2121
with open(local_path, "rb") as f:
2222
file = folder.upload_file(f).execute_query()

examples/onedrive/folders/list_files.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-1.0
44
"""
55
from office365.graph_client import GraphClient
6+
from tests import test_client_id, test_password, test_tenant, test_username
67
from tests.graph_case import acquire_token_by_username_password
78

8-
client = GraphClient(acquire_token_by_username_password)
9-
drive = client.me.drive
10-
# items = client.me.drive.root.get_files(True).execute_query()
11-
items = client.sites.root.lists["Documents"].drive.root.get_files(True).execute_query()
9+
client = GraphClient.with_username_and_password(
10+
test_tenant, test_client_id, test_username, test_password
11+
)
12+
items = client.me.drive.root.get_files(False).execute_query()
13+
# items = client.sites.root.lists["Documents"].drive.root.get_files(True).execute_query()
1214
for file_item in items:
1315
print(file_item.web_url)

examples/onedrive/folders/list_with_files.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from office365.graph_client import GraphClient
22
from office365.onedrive.driveitems.driveItem import DriveItem
3-
from tests.graph_case import acquire_token_by_username_password
3+
from tests import test_client_id, test_password, test_tenant, test_username
44

55

66
def enum_folders_and_files(root_folder):
@@ -12,6 +12,8 @@ def enum_folders_and_files(root_folder):
1212
enum_folders_and_files(drive_item)
1313

1414

15-
client = GraphClient(acquire_token_by_username_password)
15+
client = GraphClient.with_username_and_password(
16+
test_tenant, test_client_id, test_username, test_password
17+
)
1618
root = client.me.drive.root
1719
enum_folders_and_files(root)

examples/onedrive/powerpoint/create.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"""
44

55
from office365.graph_client import GraphClient
6-
from tests.graph_case import acquire_token_by_username_password
6+
from tests import test_client_id, test_password, test_tenant, test_username
77

8-
client = GraphClient(acquire_token_by_username_password)
8+
client = GraphClient.with_username_and_password(
9+
test_tenant, test_client_id, test_username, test_password
10+
)
911
remote_drive = client.me.drive.root
1012
pptx_file = remote_drive.create_powerpoint("sample.pptx").execute_query()
1113
print(f"File {pptx_file.web_url} has been uploaded")

examples/onedrive/termstore/get_sets.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"""
44

55
from office365.graph_client import GraphClient
6-
from tests.graph_case import acquire_token_by_username_password
6+
from tests import test_client_id, test_password, test_tenant, test_username
77

8-
client = GraphClient(acquire_token_by_username_password)
8+
client = GraphClient.with_username_and_password(
9+
test_tenant, test_client_id, test_username, test_password
10+
)
911
term_store = client.sites.root.term_store
1012
sets = term_store.groups.get_by_name("Geography").sets.get().execute_query()
1113
# term_set = group.sets.get_by_name("Locations").get().execute_query()

examples/onenote/create_notebook.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55
"""
66

77
from office365.graph_client import GraphClient
8-
from tests import create_unique_name
9-
from tests.graph_case import acquire_token_by_username_password
8+
from tests import (
9+
create_unique_name,
10+
test_client_id,
11+
test_password,
12+
test_tenant,
13+
test_username,
14+
)
1015

11-
client = GraphClient(acquire_token_by_username_password)
16+
client = GraphClient.with_username_and_password(
17+
test_tenant, test_client_id, test_username, test_password
18+
)
1219
display_name = create_unique_name("My Private notebook")
1320
notebook = client.me.onenote.notebooks.add(display_name).execute_query()
1421
print(notebook.display_name)

examples/outlook/calendars/find_meeting_times.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"""
66

77
from office365.graph_client import GraphClient
8-
from tests.graph_case import acquire_token_by_username_password
8+
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient(acquire_token_by_username_password)
10+
client = GraphClient.with_username_and_password(
11+
test_tenant, test_client_id, test_username, test_password
12+
)
1113
result = client.me.find_meeting_times().execute_query()
1214
for suggestion in result.value.meetingTimeSuggestions:
1315
print(suggestion)

examples/outlook/calendars/get_schedule.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@
1010
from datetime import datetime, timedelta
1111

1212
from office365.graph_client import GraphClient
13-
from tests import test_user_principal_name
14-
from tests.graph_case import acquire_token_by_username_password
13+
from tests import (
14+
test_client_id,
15+
test_password,
16+
test_tenant,
17+
test_user_principal_name,
18+
test_username,
19+
)
1520

16-
client = GraphClient(acquire_token_by_username_password)
21+
client = GraphClient.with_username_and_password(
22+
test_tenant, test_client_id, test_username, test_password
23+
)
1724
start_time = datetime.utcnow()
1825
end_time = start_time + timedelta(days=1)
1926
result = client.me.calendar.get_schedule(

examples/outlook/calendars/list_my.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
https://learn.microsoft.com/en-us/graph/api/user-list-calendars?view=graph-rest-1.0
55
"""
66
from office365.graph_client import GraphClient
7-
from tests.graph_case import acquire_token_by_username_password
7+
from tests import test_client_id, test_password, test_tenant, test_username
88

9-
client = GraphClient(acquire_token_by_username_password)
9+
client = GraphClient.with_username_and_password(
10+
test_tenant, test_client_id, test_username, test_password
11+
)
1012
calendars = client.me.calendars.top(10).get().execute_query()
1113
for cal in calendars:
1214
print(cal)

examples/outlook/messages/list_all.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"""
66

77
from office365.graph_client import GraphClient
8-
from tests.graph_case import acquire_token_by_username_password
8+
from tests import test_client_id, test_password, test_tenant, test_username
99

10-
client = GraphClient(acquire_token_by_username_password)
10+
client = GraphClient.with_username_and_password(
11+
test_tenant, test_client_id, test_username, test_password
12+
)
1113
messages = client.me.messages.get().top(10).execute_query()
1214
for m in messages:
1315
print(m.subject)

examples/planner/create_plan.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Creates a new plannerPlan
2+
Creates a new planner plan
33
https://learn.microsoft.com/en-us/graph/api/planner-post-plans?view=graph-rest-1.0
44
"""
55

@@ -12,3 +12,6 @@
1212
group = client.groups.get_by_name("My Sample Team")
1313
plan = client.planner.plans.add("My Plan", group).execute_query()
1414
print(plan)
15+
16+
17+
plan.delete_object().execute_query() # clean up

0 commit comments

Comments
 (0)