1
1
from unittest import TestCase
2
2
3
+ from office365 .runtime .auth .authentication_context import AuthenticationContext
3
4
from office365 .runtime .client_value_collection import ClientValueCollection
4
5
from office365 .sharepoint .tenant .administration .secondary_administrators_fields_data import \
5
6
SecondaryAdministratorsFieldsData
9
10
from office365 .runtime .auth .client_credential import ClientCredential
10
11
from office365 .runtime .auth .providers .acs_token_provider import ACSTokenProvider
11
12
from office365 .runtime .auth .providers .saml_token_provider import SamlTokenProvider
12
- from office365 .runtime .auth .token_response import TokenResponse
13
13
from office365 .runtime .auth .user_credential import UserCredential
14
14
from office365 .runtime .http .request_options import RequestOptions
15
15
from office365 .sharepoint .client_context import ClientContext
@@ -25,26 +25,32 @@ def test1_connect_with_app_principal(self):
25
25
settings .get ('client_credentials' ).get ('client_secret' ))
26
26
ctx = ClientContext (settings ['url' ]).with_credentials (credentials )
27
27
self .assertIsInstance (ctx .authentication_context ._provider , ACSTokenProvider )
28
- # self.assertIsInstance(ctx.authentication_context.provider.token, TokenResponse)
29
28
30
- def test2_connect_with_user_credentials (self ):
29
+ def test2_connect_with_app_principal_alt (self ):
30
+ context_auth = AuthenticationContext (url = settings .get ('url' ))
31
+ context_auth .acquire_token_for_app (client_id = settings .get ('client_credentials' ).get ('client_id' ),
32
+ client_secret = settings .get ('client_credentials' ).get ('client_secret' ))
33
+ ctx = ClientContext (settings .get ('url' ), context_auth )
34
+ self .assertIsInstance (ctx .authentication_context ._provider , ACSTokenProvider )
35
+
36
+ def test4_connect_with_user_credentials (self ):
31
37
ctx = ClientContext (settings ['url' ]).with_credentials (user_credentials )
32
38
self .assertIsInstance (ctx .authentication_context ._provider , SamlTokenProvider )
33
39
34
- def test3_init_from_url (self ):
40
+ def test5_init_from_url (self ):
35
41
ctx = ClientContext .from_url (settings ['url' ]).with_credentials (user_credentials )
36
42
web = ctx .web .get ().execute_query ()
37
43
self .assertIsNotNone (web .url )
38
44
39
- def test4_connect_with_client_cert (self ):
45
+ def test6_connect_with_client_cert (self ):
40
46
pass
41
47
42
- def test5_construct_get_request (self ):
48
+ def test7_construct_get_request (self ):
43
49
client = ClientContext (settings ['url' ]).with_credentials (user_credentials )
44
50
request = client .web .currentUser .get ().build_request ()
45
51
self .assertIsInstance (request , RequestOptions )
46
52
47
- def test7_execute_get_batch_request (self ):
53
+ def test8_execute_get_batch_request (self ):
48
54
client = ClientContext (settings ['url' ]).with_credentials (user_credentials )
49
55
current_user = client .web .currentUser
50
56
client .load (current_user )
@@ -54,7 +60,7 @@ def test7_execute_get_batch_request(self):
54
60
self .assertIsNotNone (current_web .url )
55
61
self .assertIsNotNone (current_user .user_id )
56
62
57
- def test8_execute_update_batch_request (self ):
63
+ def test9_execute_update_batch_request (self ):
58
64
client = ClientContext (settings ['url' ]).with_credentials (user_credentials )
59
65
web = client .web
60
66
new_web_title = "Site %s" % random_seed
@@ -67,7 +73,7 @@ def test8_execute_update_batch_request(self):
67
73
client .execute_query ()
68
74
self .assertEqual (updated_web .properties ['Title' ], new_web_title )
69
75
70
- def test9_execute_get_and_update_batch_request (self ):
76
+ def test_10_execute_get_and_update_batch_request (self ):
71
77
client = ClientContext (settings ['url' ]).with_credentials (user_credentials )
72
78
list_item = client .web .get_file_by_server_relative_url ("/SitePages/Home.aspx" ).listItemAllFields
73
79
new_title = "Page %s" % random_seed
@@ -80,10 +86,10 @@ def test9_execute_get_and_update_batch_request(self):
80
86
client .execute_query ()
81
87
self .assertEqual (updated_list_item .properties ['Title' ], new_title )
82
88
83
- def test_10_create_and_delete_batch_request (self ):
89
+ def test_11_create_and_delete_batch_request (self ):
84
90
pass
85
91
86
- def test_11_get_and_delete_batch_request (self ):
92
+ def test_12_get_and_delete_batch_request (self ):
87
93
file_name = "TestFile{0}.txt" .format (random_seed )
88
94
client = ClientContext (settings ['url' ]).with_credentials (user_credentials )
89
95
list_pages = client .web .lists .get_by_title ("Documents" )
@@ -101,7 +107,7 @@ def test_11_get_and_delete_batch_request(self):
101
107
client .execute_batch ()
102
108
self .assertTrue (len (files_after ), files_count_before )
103
109
104
- def test_12_get_entity_type_name (self ):
110
+ def test_13_get_entity_type_name (self ):
105
111
str_col = ClientValueCollection (str , [])
106
112
self .assertEqual (str_col .entity_type_name , "Collection(Edm.String)" )
107
113
@@ -113,4 +119,5 @@ def test_12_get_entity_type_name(self):
113
119
"Microsoft.Online.SharePoint.TenantAdministration.SecondaryAdministratorsFieldsData" )
114
120
115
121
type_col = ClientValueCollection (SecondaryAdministratorsFieldsData )
116
- self .assertEqual (type_col .entity_type_name , "Collection(Microsoft.Online.SharePoint.TenantAdministration.SecondaryAdministratorsFieldsData)" )
122
+ expected_type = "Collection(Microsoft.Online.SharePoint.TenantAdministration.SecondaryAdministratorsFieldsData)"
123
+ self .assertEqual (type_col .entity_type_name , expected_type )
0 commit comments