Skip to content

Commit

Permalink
refactorings & examples updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Feb 20, 2024
1 parent 187d4d2 commit 96c31ae
Show file tree
Hide file tree
Showing 14 changed files with 397 additions and 42 deletions.
13 changes: 10 additions & 3 deletions examples/directory/applications/app_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
https://learn.microsoft.com/en-us/graph/api/application-addpassword?view=graph-rest-1.0
"""
from office365.graph_client import GraphClient
from tests import test_client_credentials
from tests.graph_case import acquire_token_by_username_password
from tests import (
test_client_credentials,
test_client_id,
test_password,
test_tenant,
test_username,
)

client = GraphClient(acquire_token_by_username_password)
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
target_app = client.applications.get_by_app_id(test_client_credentials.clientId)
result = target_app.add_password("Password friendly name").execute_query()
print(result.value)
4 changes: 2 additions & 2 deletions examples/onedrive/lists/enum_in_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"""

from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_client_credentials
from tests import test_client_id, test_client_secret, test_tenant

client = GraphClient(acquire_token_by_client_credentials)
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
lists = client.sites.root.lists.get().execute_query()
for lst in lists:
print(lst.display_name)
4 changes: 2 additions & 2 deletions examples/onedrive/lists/get_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"""

from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_client_credentials
from tests import test_client_id, test_client_secret, test_tenant

client = GraphClient(acquire_token_by_client_credentials)
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
lib = client.sites.root.lists["Documents"].get().execute_query()
print(lib.web_url)
6 changes: 4 additions & 2 deletions examples/onedrive/workbook/work_with_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
"""
from examples.onedrive import ensure_workbook_sample
from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_username_password
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient(acquire_token_by_username_password)
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
workbook = ensure_workbook_sample(client)

print("Creating a session...")
Expand Down
3 changes: 2 additions & 1 deletion examples/sharepoint/lists/clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@


def print_progress(items_count):
# type: (int) -> None
print("List items count: {0}".format(target_list.item_count))


ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
target_list = ctx.web.lists.get_by_title("Contacts_Large")
target_list.clear().get().execute_query()
target_list.clear().get().execute_batch()
print("List items count: {0}".format(target_list.item_count))
4 changes: 2 additions & 2 deletions generator/import_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def export_to_file(path, content):
"--endpoint",
dest="endpoint",
help="Import metadata endpoint",
default="microsoftgraph",
default="sharepoint",
)
parser.add_argument(
"-p",
"--path",
dest="path",
default="./metadata/MicrosoftGraph.xml",
default="./metadata/SharePoint.xml",
help="Import metadata endpoint",
)

Expand Down
365 changes: 353 additions & 12 deletions generator/metadata/SharePoint.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions office365/directory/password_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ def __init__(
self.keyId = key_id
self.startDateTime = start_datetime
self.endDateTime = end_datetime

def __str__(self):
return self.displayName or self.entity_type_name
6 changes: 2 additions & 4 deletions office365/onedrive/termstore/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from office365.entity import Entity
from office365.entity_collection import EntityCollection
from office365.onedrive.termstore.groups.collection import GroupCollection
from office365.onedrive.termstore.groups.group import Group
from office365.onedrive.termstore.sets.collection import SetCollection
from office365.onedrive.termstore.sets.set import Set
from office365.runtime.paths.resource_path import ResourcePath
Expand All @@ -23,10 +22,9 @@ def _sets_loaded(sets):

def _groups_loaded(groups):
# type: (GroupCollection) -> None
for g in groups:
self.context.load(g.sets, after_loaded=_sets_loaded)
[grp.sets.get().after_execute(_sets_loaded) for grp in groups]

self.context.load(self.groups, after_loaded=_groups_loaded)
self.groups.get().after_execute(_groups_loaded)

return return_type

Expand Down
1 change: 0 additions & 1 deletion office365/runtime/auth/sts_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
class STSProfile(object):
def __init__(self, authority_url, environment):
"""
:type authority_url: str
"""
self.authorityUrl = authority_url
Expand Down
8 changes: 4 additions & 4 deletions office365/sharepoint/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from typing_extensions import Self

from office365.runtime.auth.client_credential import ClientCredential
from office365.runtime.auth.user_credential import UserCredential
from office365.runtime.client_object import ClientObject
from office365.runtime.queries.delete_entity import DeleteEntityQuery
from office365.runtime.queries.update_entity import UpdateEntityQuery
Expand All @@ -19,10 +21,8 @@ def execute_batch(self, items_per_batch=100, success_callback=None):
return self.context.execute_batch(items_per_batch, success_callback)

def with_credentials(self, credentials):
"""
:type self: T
:type credentials: UserCredential or ClientCredential
"""
# type: (UserCredential|ClientCredential) -> Self
""" """
self.context.with_credentials(credentials)
return self

Expand Down
4 changes: 4 additions & 0 deletions office365/sharepoint/folders/coloring.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing_extensions import Self

from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity
from office365.sharepoint.folders.coloring_information import FolderColoringInformation
from office365.sharepoint.folders.folder import Folder


Expand Down Expand Up @@ -34,6 +37,7 @@ def create_folder(
return return_type

def stamp_color(self, decoded_url, coloring_information):
# type: (str, FolderColoringInformation) -> Self
"""
:param str decoded_url:
:param FolderColoringInformation coloring_information:
Expand Down
6 changes: 4 additions & 2 deletions office365/sharepoint/taxonomy/stores/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ def _sets_loaded(sets):

def _groups_loaded(col):
# type: (TermGroupCollection) -> None
for grp in col:
[
grp.get_term_sets_by_name(label, lcid).after_execute(_sets_loaded)
for grp in col
]

self.context.load(self.term_groups, after_loaded=_groups_loaded)
self.term_groups.get().after_execute(_groups_loaded)
return return_type

def search_term(self, label, set_id=None, parent_term_id=None, language_tag=None):
Expand Down
12 changes: 5 additions & 7 deletions office365/teams/operations/async_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,24 @@ def poll_for_status(
"""

def _poll_for_status(polling_number):
"""
:type polling_number: int
"""
# type: (int) -> None
if polling_number > max_polling_count:
if callable(failure_callback):
failure_callback(self)
else:
raise TypeError("The maximum polling count has been reached")

def _verify_status(return_type):
if self.status != status_type:
if return_type.status != status_type:
time.sleep(polling_interval_secs)
_poll_for_status(polling_number + 1)
else:
if callable(success_callback):
success_callback(self)
success_callback(return_type)

self.context.load(self, after_loaded=_verify_status)
self.get().after_execute(_verify_status, execute_first=True)

self.ensure_property("id", _poll_for_status, 1)
_poll_for_status(1)
return self

@property
Expand Down

0 comments on commit 96c31ae

Please sign in to comment.