MCPcopy Create free account
hub / github.com/O365/python-o365 / test_authentication

Method test_authentication

tests/test_account.py:18–60  ·  view source on GitHub ↗

Test the new auth flow type "password"

(self, pop, key_to_pop)

Source from the content-addressed store, hash-verified

16 (True, "auth_flow_type"),
17 ])
18 def test_authentication(self, pop, key_to_pop):
19 """
20 Test the new auth flow type "password"
21 """
22 kwargs = {
23 "scopes" : ["basic"],
24 "tenant_id" : Config.TENANT_ID,
25 "username" : Config.EMAIL,
26 "password" : Config.PASSWORD,
27 "auth_flow_type" : 'password'
28 }
29
30 if pop:
31 kwargs.pop(key_to_pop)
32
33 # ValueError: When using the "credentials" or "password" auth_flow the "tenant_id" must be set
34 if "tenant_id" in key_to_pop:
35 with pytest.raises(ValueError):
36 account = Account((Config.CLIENT_ID),**kwargs)
37
38 # ValueError: auth_flow_type is needed
39 if "auth_flow_type" in key_to_pop:
40 with pytest.raises(ValueError):
41 account = Account((Config.CLIENT_ID),**kwargs)
42
43 if key_to_pop not in ("tenant_id", "auth_flow_type"):
44 account = Account((Config.CLIENT_ID),**kwargs)
45 # instantiate an account with "offline_access" (scopes="basic" is a default scope that includes "offline_access")
46 # will give the possibility to use a refresh_token
47 if not pop:
48 account.authenticate()
49 assert account.is_authenticated
50 assert account.con.refresh_token()
51
52 # instantiate an account without scopes -> no refresh_token
53 if "scopes" in key_to_pop:
54 account.authenticate()
55 assert account.is_authenticated
56 assert not account.con.refresh_token()
57
58 # Cannot account authenticate without password or username
59 if key_to_pop in ("username", "password"):
60 assert not account.authenticate()
61
62
63 @pytest.mark.parametrize("token", [

Callers

nothing calls this directly

Calls 3

authenticateMethod · 0.95
AccountClass · 0.90
refresh_tokenMethod · 0.80

Tested by

no test coverage detected