Skip to content

Commit 6005d49

Browse files
committed
type hints for client query
1 parent 98d7a5d commit 6005d49

File tree

18 files changed

+132
-43
lines changed

18 files changed

+132
-43
lines changed

examples/reports/get_user_mfa_status.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This method doesn't work for disabled users.
44
55
"""
6+
67
from office365.graph_client import GraphClient
78
from tests import test_client_id, test_client_secret, test_tenant
89

office365/directory/authentication/conditions/conditions.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66

77
class AuthenticationConditions(ClientValue):
8-
""""""
8+
"""The conditions on which an authenticationEventListener should trigger."""
99

1010
def __init__(self, applications=AuthenticationConditionsApplications()):
11+
"""
12+
:parm AuthenticationConditionsApplications applications: Applications which trigger a custom authentication
13+
extension.
14+
"""
1115
self.applications = applications

office365/directory/identitygovernance/accessreview/instance.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from office365.directory.identitygovernance.accessreview.stages import AccessReviewStageCollection
1+
from office365.directory.identitygovernance.accessreview.stages import (
2+
AccessReviewStageCollection,
3+
)
24
from office365.entity import Entity
35
from office365.runtime.paths.resource_path import ResourcePath
46

office365/directory/identitygovernance/accessreview/stages.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ class AccessReviewStageCollection(EntityCollection[AccessReviewStage]):
66
"""AccessReviewStage collection"""
77

88
def __init__(self, context, resource_path=None):
9-
super(AccessReviewStageCollection, self).__init__(context, AccessReviewStage, resource_path)
9+
super(AccessReviewStageCollection, self).__init__(
10+
context, AccessReviewStage, resource_path
11+
)

office365/directory/rolemanagement/role.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def members(self):
4141

4242
@property
4343
def scoped_members(self):
44-
"""Members of this directory role that are scoped to administrative units. """
44+
"""Members of this directory role that are scoped to administrative units."""
4545

4646
return self.properties.get(
4747
"scopedMembers",

office365/reports/internal/queries/create_report_query.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010

1111
def create_report_query(report_root, report_name, period=None, return_stream=False):
12-
# type: (ReportRoot, str, str, bool) -> FunctionQuery
1312
"""
1413
Construct Report query
1514

office365/reports/root.py

+48-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ def get_email_activity_user_detail(self, period):
8989
The supported values for {period_value} are: D7, D30, D90, and D180. These values follow the format
9090
Dn where n represents the number of days over which the report is aggregated. Required.
9191
"""
92-
qry = create_report_query(self, "getEmailActivityUserDetail", period, return_stream=True)
92+
qry = create_report_query(
93+
self, "getEmailActivityUserDetail", period, return_stream=True
94+
)
9395
self.context.add_query(qry)
9496
return qry.return_type
9597

@@ -105,18 +107,48 @@ def get_email_app_usage_apps_user_counts(self, period):
105107
self.context.add_query(qry)
106108
return qry.return_type
107109

110+
def get_email_app_usage_user_counts(self, period):
111+
"""
112+
Get the count of unique users that connected to Exchange Online using any email app.
113+
114+
:param str period: Specifies the length of time over which the report is aggregated.
115+
The supported values for {period_value} are: D7, D30, D90, and D180. These values follow the format
116+
Dn where n represents the number of days over which the report is aggregated. Required.
117+
"""
118+
qry = create_report_query(self, "getEmailAppUsageUserCounts", period, True)
119+
self.context.add_query(qry)
120+
return qry.return_type
121+
122+
def get_mailbox_usage_storage(self, period):
123+
"""
124+
Get the amount of storage used in your organization.
125+
126+
:param str period: Specifies the length of time over which the report is aggregated.
127+
The supported values for {period_value} are: D7, D30, D90, and D180. These values follow the format
128+
Dn where n represents the number of days over which the report is aggregated. Required.
129+
"""
130+
qry = create_report_query(self, "getMailboxUsageStorage", period, True)
131+
self.context.add_query(qry)
132+
return qry.return_type
133+
108134
def get_m365_app_user_counts(self, period=None):
109135
"""
110136
Get a report that provides the trend in the number of active users for each app (Outlook, Word, Excel,
111137
PowerPoint, OneNote, and Teams) in your organization.
112138
"""
113-
return_type = ClientResult(self.context, str())
139+
return_type = ClientResult(self.context, bytes())
114140
qry = FunctionQuery(
115141
self, "getM365AppUserCounts", {"period": period}, return_type
116142
)
117143
self.context.add_query(qry)
118144
return return_type
119145

146+
def get_office365_activation_counts(self):
147+
"""Get the count of Microsoft 365 activations on desktops and devices."""
148+
qry = create_report_query(self, "getOffice365ActivationCounts")
149+
self.context.add_query(qry)
150+
return qry.return_type
151+
120152
def get_office365_activations_user_counts(self):
121153
"""Get the count of Microsoft 365 activations on desktops and devices."""
122154
qry = create_report_query(self, "getOffice365ActivationsUserCounts")
@@ -283,6 +315,20 @@ def get_sharepoint_site_usage_site_counts(self, period):
283315
self.context.add_query(qry)
284316
return qry.return_type
285317

318+
def get_teams_team_counts(self, period):
319+
"""
320+
Get the number of teams of a particular type in an instance of Microsoft Teams.
321+
322+
:param str period: Specifies the length of time over which the report is aggregated.
323+
The supported values for {period_value} are: D7, D30, D90, and D180. These values follow the format
324+
Dn where n represents the number of days over which the report is aggregated. Required.
325+
"""
326+
qry = create_report_query(
327+
self, "getTeamsTeamCounts", period, return_stream=True
328+
)
329+
self.context.add_query(qry)
330+
return qry.return_type
331+
286332
@property
287333
def authentication_methods(self):
288334
"""Container for navigation properties for Azure AD authentication methods resources."""

office365/runtime/queries/client_query.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
class ClientQuery(object):
1+
from typing import TYPE_CHECKING, AnyStr, Dict, Generic, Optional, TypeVar, Union
2+
3+
if TYPE_CHECKING:
4+
from office365.runtime.client_object import ClientObject
5+
from office365.runtime.client_result import ClientResult
6+
from office365.runtime.client_runtime_context import ClientRuntimeContext
7+
from office365.runtime.client_value import ClientValue
8+
9+
T = TypeVar("T", bound=Union["ClientObject", "ClientResult"])
10+
11+
12+
class ClientQuery(Generic[T]):
213
"""Client query"""
314

415
def __init__(
@@ -9,15 +20,9 @@ def __init__(
920
parameters_name=None,
1021
return_type=None,
1122
):
23+
# type: (ClientRuntimeContext, Optional[ClientObject], Optional[ClientObject|ClientValue|Dict|AnyStr], Optional[str], Optional[T]) -> None
1224
"""
1325
Generic query
14-
15-
:type context: office365.runtime.client_runtime_context.ClientRuntimeContext
16-
:type binding_type: office365.runtime.client_object.ClientObject or None
17-
:type parameters_type: office365.runtime.client_object.ClientObject or ClientValue or dict or bytes or None
18-
:type parameters_name: str or None
19-
:type return_type: office365.runtime.client_object.ClientObject
20-
or office365.runtime.client_result.ClientResult or None
2126
"""
2227
self._context = context
2328
self._binding_type = binding_type

office365/runtime/queries/create_entity.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
from typing import Dict
1+
from typing import TYPE_CHECKING, Dict
22

3-
from office365.runtime.client_object import ClientObject
43
from office365.runtime.client_value import ClientValue
5-
from office365.runtime.queries.client_query import ClientQuery
4+
from office365.runtime.queries.client_query import ClientQuery, T
65

6+
if TYPE_CHECKING:
7+
from office365.runtime.client_object import ClientObject
78

8-
class CreateEntityQuery(ClientQuery):
9+
10+
class CreateEntityQuery(ClientQuery[T]):
911
def __init__(self, parent_entity, parameters, return_type=None):
10-
# type: (ClientObject, ClientObject|ClientValue|Dict, ClientObject) -> None
12+
# type: (ClientObject, ClientObject|ClientValue|Dict, T) -> None
1113
"""Create entity query"""
1214
super(CreateEntityQuery, self).__init__(
1315
parent_entity.context, parent_entity, parameters, None, return_type
+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
from typing import TYPE_CHECKING
2+
13
from office365.runtime.queries.client_query import ClientQuery
24

5+
if TYPE_CHECKING:
6+
from office365.runtime.client_object import ClientObject
7+
38

49
class DeleteEntityQuery(ClientQuery):
510
def __init__(self, delete_type):
11+
# type: (ClientObject) -> None
612
"""
713
Delete entity query
8-
9-
:type delete_type: office365.runtime.client_object.ClientObject
1014
"""
1115
super(DeleteEntityQuery, self).__init__(delete_type.context, delete_type)

office365/runtime/queries/function.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
from office365.runtime.client_object import ClientObject
2-
from office365.runtime.client_result import ClientResult
32
from office365.runtime.client_value import ClientValue
43
from office365.runtime.paths.service_operation import ServiceOperationPath
5-
from office365.runtime.queries.client_query import ClientQuery
4+
from office365.runtime.queries.client_query import ClientQuery, T
65

76

8-
class FunctionQuery(ClientQuery):
7+
class FunctionQuery(ClientQuery[T]):
98
"""Function query"""
109

1110
def __init__(
1211
self, binding_type, method_name=None, method_params=None, return_type=None
1312
):
14-
# type: (ClientObject, str, list|dict|ClientValue, ClientObject|ClientResult) -> None
13+
# type: (ClientObject, str, list|dict|ClientValue, T) -> None
1514
"""Function query"""
1615
super(FunctionQuery, self).__init__(
1716
binding_type.context, binding_type, None, None, return_type

office365/runtime/queries/read_entity.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
from office365.runtime.odata.query_options import QueryOptions
2-
from office365.runtime.queries.client_query import ClientQuery
2+
from office365.runtime.queries.client_query import ClientQuery, T
33

44

5-
class ReadEntityQuery(ClientQuery):
5+
class ReadEntityQuery(ClientQuery[T]):
66
def __init__(self, return_type, properties_to_include=None):
7+
# type: (T, list[str]) -> None
78
"""
89
Read client object query
9-
10-
:type properties_to_include: list[str] or None
11-
:type return_type: office365.runtime.client_object.ClientObject
1210
"""
1311
super(ReadEntityQuery, self).__init__(
1412
return_type.context, return_type, None, None, return_type

office365/runtime/queries/service_operation.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from office365.runtime.paths.service_operation import ServiceOperationPath
2-
from office365.runtime.queries.client_query import ClientQuery
2+
from office365.runtime.queries.client_query import ClientQuery, T
33

44

5-
class ServiceOperationQuery(ClientQuery):
5+
class ServiceOperationQuery(ClientQuery[T]):
66
""" "Service operation query"""
77

88
def __init__(
@@ -15,11 +15,6 @@ def __init__(
1515
return_type=None,
1616
is_static=False,
1717
):
18-
"""
19-
20-
:type method_params: list or dict or office365.runtime.client_value.ClientValue or None
21-
:type method_name: str or None
22-
"""
2318
super(ServiceOperationQuery, self).__init__(
2419
binding_type.context,
2520
binding_type,

office365/teams/fun_settings.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@
44
class TeamFunSettings(ClientValue):
55
"""Settings to configure use of Giphy, memes, and stickers in the team."""
66

7-
def __init__(self, allow_giphy=True):
7+
def __init__(
8+
self,
9+
allow_custom_memes=None,
10+
allow_giphy=None,
11+
allow_stickers_and_memes=None,
12+
giphy_content_rating=None,
13+
):
814
"""
9-
:param bool allow_giphy:
15+
:param bool allow_custom_memes: f set to true, enables users to include custom memes.
16+
:param bool allow_giphy: If set to true, enables Giphy use.
17+
:param bool allow_stickers_and_memes: If set to true, enables users to include stickers and memes.
18+
:param str giphy_content_rating: Giphy content rating. Possible values are: moderate, strict.
1019
"""
1120
super(TeamFunSettings, self).__init__()
21+
self.allowCustomMemes = allow_custom_memes
1222
self.allowGiphy = allow_giphy
23+
self.allowStickersAndMemes = allow_stickers_and_memes
24+
self.giphyContentRating = giphy_content_rating

office365/teams/teamwork/user.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def get_property(self, name, default_value=None):
9797
if default_value is None:
9898
property_mapping = {
9999
"associatedTeams": self.associated_teams,
100-
"installedApps": self.installed_apps
100+
"installedApps": self.installed_apps,
101101
}
102102
default_value = property_mapping.get(name, None)
103103
return super(UserTeamwork, self).get_property(name, default_value)

tests/reports/test_insights.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
class TestInsights(GraphTestCase):
55

6-
76
def test1_list_trending(self):
87
result = self.client.me.insights.trending.get().execute_query()
98
self.assertIsNotNone(result.resource_path)

tests/reports/test_outlook_reports.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,11 @@ def test2_get_m365_app_user_counts(self):
1919
self.assertIsNotNone(result.value)
2020

2121
def test3_get_email_activity_user_detail(self):
22-
result = self.client.reports.get_email_activity_user_detail("D7").execute_query()
22+
result = self.client.reports.get_email_activity_user_detail(
23+
"D7"
24+
).execute_query()
25+
self.assertIsNotNone(result.value)
26+
27+
def test4_get_mailbox_usage_storage(self):
28+
result = self.client.reports.get_mailbox_usage_storage("D30").execute_query()
2329
self.assertIsNotNone(result.value)

tests/reports/test_teams_reports.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from tests.graph_case import GraphTestCase
2+
3+
4+
class TestTeamsReports(GraphTestCase):
5+
@classmethod
6+
def setUpClass(cls):
7+
super(TestTeamsReports, cls).setUpClass()
8+
9+
@classmethod
10+
def tearDownClass(cls):
11+
pass
12+
13+
def test1_get_teams_team_counts(self):
14+
result = self.client.reports.get_teams_team_counts("D90").execute_query()
15+
self.assertIsNotNone(result.value)

0 commit comments

Comments
 (0)