Skip to content

Commit a4cecad

Browse files
committed
support for advanced query capabilities & update unit tests
1 parent ed16055 commit a4cecad

File tree

11 files changed

+57
-46
lines changed

11 files changed

+57
-46
lines changed

examples/onedrive/bundles/create.py

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

generator/generate_model.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from configparser import ConfigParser
2+
13
from generator import load_settings
24
from generator.builders.type_builder import TypeBuilder
5+
from office365.runtime.odata.model import ODataModel
36
from office365.runtime.odata.v3.metadata_reader import ODataV3Reader
47
from office365.runtime.odata.v4.metadata_reader import ODataV4Reader
58

office365/count_collection.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from requests import Response
2+
13
from office365.delta_collection import DeltaCollection
24
from office365.runtime.client_object import T
35
from office365.runtime.client_result import ClientResult
@@ -18,6 +20,14 @@ def _construct_request(request):
1820
request.headers.pop("Accept", None)
1921
request.ensure_header("ConsistencyLevel", "eventual")
2022

21-
qry = FunctionQuery(self, "$count", None, return_type)
22-
self.context.add_query(qry).before_execute(_construct_request)
23+
def _process_response(response):
24+
# type: (Response) -> None
25+
response.raise_for_status()
26+
value = int(response.content.decode("utf-8"))
27+
return_type.set_property("__value", value)
28+
29+
qry = FunctionQuery(self, "$count")
30+
self.context.add_query(qry).before_execute(_construct_request).after_execute(
31+
_process_response
32+
)
2333
return return_type

office365/directory/applications/collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from office365.delta_collection import DeltaCollection
1+
from office365.count_collection import CountCollection
22
from office365.directory.applications.application import Application
33
from office365.runtime.paths.appid import AppIdPath
44

55

6-
class ApplicationCollection(DeltaCollection[Application]):
6+
class ApplicationCollection(CountCollection[Application]):
77
"""DirectoryObject's collection"""
88

99
def __init__(self, context, resource_path=None):

office365/directory/serviceprincipals/collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from office365.delta_collection import DeltaCollection
1+
from office365.count_collection import CountCollection
22
from office365.directory.applications.application import Application
33
from office365.directory.serviceprincipals.service_principal import ServicePrincipal
44
from office365.runtime.paths.appid import AppIdPath
55

66

7-
class ServicePrincipalCollection(DeltaCollection[ServicePrincipal]):
7+
class ServicePrincipalCollection(CountCollection[ServicePrincipal]):
88
"""Service Principal's collection"""
99

1010
def __init__(self, context, resource_path=None):

office365/runtime/client_result.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,9 @@ def set_property(self, key, value, persist_changes=False):
4343
elif isinstance(self._value, dict):
4444
self._value[key] = value
4545
else:
46-
self._value = self._try_cast(value)
46+
self._value = value
4747
return self
4848

49-
def _try_cast(self, value):
50-
# type: (Any) -> Optional[T]
51-
52-
if isinstance(self._value, (int, float)) and isinstance(value, bytes):
53-
try:
54-
return type(self._value)(value.decode("utf-8"))
55-
except (UnicodeDecodeError, ValueError):
56-
return None
57-
return value
58-
5949
@property
6050
def value(self):
6151
"""Returns the value"""

office365/runtime/client_runtime_context.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,10 @@ def _process_response(response):
199199
return_type.set_property("__value", response.content)
200200

201201
qry = ClientQuery(self)
202-
self.add_query(qry).before_execute(_construct_request).after_execute(
203-
_process_response
202+
(
203+
self.add_query(qry)
204+
.before_execute(_construct_request)
205+
.after_execute(_process_response)
204206
)
205207
return return_type
206208

tests/directory/test_application.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@ def test2_create_app(self):
2121
self.assertIsNotNone(new_app.resource_path)
2222
self.__class__.target_app = new_app
2323

24-
def test3_add_password(self):
24+
def test3_get_apps_count(self):
25+
result = self.client.applications.count().execute_query()
26+
self.assertIsNotNone(result.value)
27+
28+
def test4_add_password(self):
2529
result = self.__class__.target_app.add_password("New password").execute_query()
2630
self.assertIsNotNone(result.value.secretText)
2731
self.__class__.target_password = result.value
2832

29-
def test4_remove_password(self):
33+
def test5_remove_password(self):
3034
self.__class__.target_app.remove_password(
3135
self.__class__.target_password.keyId
3236
).execute_query()
3337

34-
def test5_delete_app(self):
38+
def test6_delete_app(self):
3539
app_to_del = self.__class__.target_app
3640
app_to_del.delete_object(True).execute_query()

tests/directory/test_identity.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from office365.graph_client import GraphClient
44
from tests import test_client_id, test_client_secret, test_tenant
5+
from tests.decorators import requires_app_permission
56

67

78
class TestIdentity(TestCase):
@@ -11,6 +12,9 @@ def setUpClass(cls):
1112
test_client_id, test_client_secret
1213
)
1314

15+
@requires_app_permission(
16+
"IdentityProvider.Read.All", "IdentityProvider.ReadWrite.All"
17+
)
1418
def test1_list_identity_providers(self):
1519
result = self.client.identity.identity_providers.get().execute_query()
1620
self.assertIsNotNone(result.resource_path)

tests/directory/test_invitations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from office365.graph_client import GraphClient
44
from tests import test_client_id, test_client_secret, test_tenant
5+
from tests.decorators import requires_app_permission
56

67

78
class TestInvitations(TestCase):
@@ -11,6 +12,9 @@ def setUpClass(cls):
1112
test_client_id, test_client_secret
1213
)
1314

15+
@requires_app_permission(
16+
"User.Invite.All", "Directory.ReadWrite.All", "User.ReadWrite.All"
17+
)
1418
def test1_create_invitation(self):
1519
invitation = self.client.invitations.create(
1620
"[email protected]", "https://myapp.contoso.com"

0 commit comments

Comments
 (0)