Skip to content

Commit 1394511

Browse files
committed
Examples update & SharePoint model updates
1 parent 615211c commit 1394511

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

+402
-103
lines changed

examples/onedrive/files/download.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from office365.graph_client import GraphClient
1010
from tests import test_client_id, test_password, test_tenant, test_username
11-
from tests.graph_case import acquire_token_by_username_password
1211

1312
client = GraphClient.with_username_and_password(
1413
test_tenant, test_client_id, test_username, test_password

examples/onedrive/files/send_sharing_invitation.py

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

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

1514
file_name = "Financial Sample.xlsx"
1615
client = GraphClient.with_username_and_password(

examples/onedrive/folders/list_files.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55
from office365.graph_client import GraphClient
66
from tests import test_client_id, test_password, test_tenant, test_username
7-
from tests.graph_case import acquire_token_by_username_password
87

98
client = GraphClient.with_username_and_password(
109
test_tenant, test_client_id, test_username, test_password

examples/onenote/create_page.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

1214
files = {}
1315
with open("../data/Sample.html", "rb") as f, open(

examples/outlook/calendars/share_with.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
"""
88
from office365.graph_client import GraphClient
99
from office365.outlook.calendar.role_type import CalendarRoleType
10-
from tests.graph_case import acquire_token_by_username_password
10+
from tests import test_client_id, test_password, test_tenant, test_username
1111

12-
client = GraphClient(acquire_token_by_username_password)
13-
my_cal = client.me.calendar
14-
cal_perm = my_cal.calendar_permissions.add(
12+
client = GraphClient.with_username_and_password(
13+
test_tenant, test_client_id, test_username, test_password
14+
)
15+
16+
cal_perm = client.me.calendar.calendar_permissions.add(
1517
"[email protected]", CalendarRoleType.read
1618
).execute_query()
1719
print(cal_perm)

examples/outlook/events/delete.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
event_id = "--event id goes here--"
1012
event_to_del = client.me.calendar.events[event_id]
1113
event_to_del.delete_object().execute_query()

examples/outlook/events/list.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
https://learn.microsoft.com/en-us/graph/api/calendar-list-events?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
events = (
11-
client.me.calendar.events.get().top(100).select(["subject", "body"]).execute_query()
13+
client.me.calendar.events.get().top(10).select(["subject", "body"]).execute_query()
1214
)
1315
for event in events:
1416
print(event.subject)

examples/outlook/messages/create_draft_with_attachments.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import base64
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

99
with open(r"../../data/Sample.pdf", "rb") as f:
1010
content = base64.b64encode(f.read()).decode()
11-
client = GraphClient(acquire_token_by_username_password)
11+
client = GraphClient.with_username_and_password(
12+
test_tenant, test_client_id, test_username, test_password
13+
)
1214
client.me.messages.add(
1315
subject="Meet for lunch?",
1416
body="The new cafeteria is open.",

examples/outlook/messages/create_property.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import sys
99

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

13-
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+
)
1416
messages = client.me.messages.top(1).get().execute_query()
1517
if len(messages) == 0:
1618
sys.exit("No messages were found")

examples/outlook/messages/create_subscription.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import datetime
77

88
from office365.graph_client import GraphClient
9-
from tests.graph_case import acquire_token_by_username_password
9+
from tests import test_client_id, test_password, test_tenant, test_username
1010

11-
client = GraphClient(acquire_token_by_username_password)
11+
client = GraphClient.with_username_and_password(
12+
test_tenant, test_client_id, test_username, test_password
13+
)
1214

1315
existing_subscriptions = client.subscriptions.get().execute_query()
1416

examples/outlook/messages/download.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import tempfile
1010

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

14-
client = GraphClient(acquire_token_by_username_password)
14+
client = GraphClient.with_username_and_password(
15+
test_tenant, test_client_id, test_username, test_password
16+
)
1517
messages = client.me.messages.select(["id", "subject"]).top(1).get().execute_query()
1618
with tempfile.TemporaryDirectory() as local_path:
1719
for message in messages:

examples/outlook/messages/get_with_body.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
"""
88

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

12-
client = GraphClient(acquire_token_by_username_password)
12+
client = GraphClient.with_username_and_password(
13+
test_tenant, test_client_id, test_username, test_password
14+
)
1315
messages = client.me.messages.select(["subject", "body"]).top(10).get().execute_query()
1416
for message in messages:
1517
print(message.subject)

examples/outlook/messages/list_new.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 = (
1214
client.me.mail_folders["Inbox"]
1315
.messages.delta.change_type("created")

examples/outlook/messages/mark_as_read.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import sys
88

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

12-
client = GraphClient(acquire_token_by_username_password)
12+
client = GraphClient.with_username_and_password(
13+
test_tenant, test_client_id, test_username, test_password
14+
)
1315
messages = client.me.messages.top(1).get().execute_query()
1416
if len(messages) == 0:
1517
sys.exit("No messages were found")

examples/outlook/messages/move.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
Move a message to another folder within the specified user's mailbox.
33
This creates a new copy of the message in the destination folder and removes the original message.
44
5-
https://learn.microsoft.com/en-us/graph/api/message-move?view=graph-rest-1.0&tabs=http
5+
https://learn.microsoft.com/en-us/graph/api/message-move?view=graph-rest-1.0
66
"""
77

88
from office365.graph_client import GraphClient
9-
from tests.graph_case import acquire_token_by_username_password
9+
from tests import test_client_id, test_password, test_tenant, test_username
1010

11-
client = GraphClient(acquire_token_by_username_password)
11+
client = GraphClient.with_username_and_password(
12+
test_tenant, test_client_id, test_username, test_password
13+
)
1214
folder_name = "Archive"
1315
to_folder = client.me.mail_folders[folder_name]
1416

examples/outlook/messages/reply.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import sys
88

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

12-
client = GraphClient(acquire_token_by_username_password)
12+
client = GraphClient.with_username_and_password(
13+
test_tenant, test_client_id, test_username, test_password
14+
)
1315
messages = client.me.messages.top(1).get().execute_query()
1416
if len(messages) == 0:
1517
sys.exit("No messages were found")

examples/outlook/messages/search.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
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_messages("Let's go for lunch").execute_query()
1214
for item in result.value:
1315
for hit in item.hitsContainers[0].hits:
14-
print(hit.resource.properties.get("webLink"))
16+
print(hit.resource.get("webLink"))

examples/outlook/messages/send_with_attachment.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 test_user_principal_name_alt
9-
from tests.graph_case import acquire_token_by_username_password
8+
from tests import (
9+
test_client_id,
10+
test_password,
11+
test_tenant,
12+
test_user_principal_name_alt,
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
client.me.send_mail(
1320
subject="Meet for lunch?",
1421
body="The new cafeteria is open.",

examples/outlook/messages/send_with_large_attachment.py

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

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

1116

1217
def print_progress(range_pos):
18+
# type: (int) -> None
1319
print("{0} bytes uploaded".format(range_pos))
1420

1521

16-
client = GraphClient(acquire_token_by_username_password)
22+
client = GraphClient.with_username_and_password(
23+
test_tenant, test_client_id, test_username, test_password
24+
)
1725
local_path = "../../../tests/data/big_buck_bunny.mp4"
1826
message = (
1927
(

examples/planner/create_task.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import sys
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
group = client.groups.get_by_name("My Sample Team").get().execute_query()
1214
plans = group.planner.plans.get().execute_query()
1315
if len(plans) == 0:

examples/sharepoint/fields/create_lookup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
lookup_field_name="Title",
1515
allow_multiple_values=True,
1616
).execute_query()
17-
print("Field {0} has been created", field.internal_name)
17+
print("Field {0} has been created", field_name)
1818
field.delete_object().execute_query() # clean up

examples/sharepoint/files/delete.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
from tests import test_team_site_url, test_user_credentials
66

77
ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
8-
file_url = "Shared Documents/SharePoint User Guide.docx"
8+
file_url = "Shared Documents/Financial Sample.xlsx"
99
file = ctx.web.get_file_by_server_relative_url(file_url)
10-
file.delete_object().execute_query()
10+
# file.recycle().execute_query()
11+
# or delete permanently via delete_object:
12+
# file.delete_object().execute_query()
13+
print("Deleted file: {0}".format(file_url))
14+
15+
16+
print("Print deleted files...")
17+
result = ctx.web.get_recycle_bin_items().execute_query()
18+
for recycle_bin_item in result:
19+
print(recycle_bin_item)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
Retrieves the locale settings of a site
3+
"""
4+
from office365.sharepoint.client_context import ClientContext
5+
from tests import test_client_credentials, test_site_url
6+
7+
client = ClientContext(test_site_url).with_credentials(test_client_credentials)
8+
result = client.web.regional_settings.get().execute_query()
9+
print(result)

examples/teams/create_team.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
"""
99

1010
from office365.graph_client import GraphClient
11-
from tests import create_unique_name
12-
from tests.graph_case import acquire_token_by_username_password
11+
from tests import (
12+
create_unique_name,
13+
test_client_id,
14+
test_password,
15+
test_tenant,
16+
test_username,
17+
)
1318

14-
client = GraphClient(acquire_token_by_username_password)
19+
client = GraphClient.with_username_and_password(
20+
test_tenant, test_client_id, test_username, test_password
21+
)
1522
team_name = create_unique_name("Team")
1623
print("Creating a team '{0}' ...".format(team_name))
1724
team = client.teams.create(team_name).execute_query_and_wait()

examples/teams/send_message.py

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

77
from office365.graph_client import GraphClient
88
from office365.outlook.mail.item_body import ItemBody
9-
from tests.graph_case import acquire_token_by_username_password
9+
from tests import test_client_id, test_password, test_tenant, test_username
1010

11-
client = GraphClient(acquire_token_by_username_password)
11+
client = GraphClient.with_username_and_password(
12+
test_tenant, test_client_id, test_username, test_password
13+
)
1214
my_teams = client.me.joined_teams.get().top(1).execute_query()
1315
if len(my_teams) == 0:
1416
sys.exit("No teams found")

office365/sharepoint/alerts/collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from office365.sharepoint.entity_collection import EntityCollection
66

77

8-
class AlertCollection(EntityCollection):
8+
class AlertCollection(EntityCollection[Alert]):
99
"""Content Type resource collection"""
1010

1111
def __init__(self, context, resource_path=None):
@@ -26,6 +26,7 @@ def add(self, parameters):
2626
return return_type
2727

2828
def contains(self, id_alert):
29+
# type: (str) -> ClientResult[bool]
2930
"""
3031
Returns true if the given alert exists in the alert collection. False otherwise.
3132

office365/sharepoint/contenttypes/content_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ContentType(Entity):
2020
"""
2121

2222
def __str__(self):
23-
return self.name
23+
return self.name or self.entity_type_name
2424

2525
def __repr__(self):
2626
return self.string_id or str(self.id) or self.entity_type_name

0 commit comments

Comments
 (0)