1
+ import unittest
2
+ import mock
3
+ from ...management .organizations import Organizations
4
+
5
+
6
+ class TestOrganizations (unittest .TestCase ):
7
+
8
+ def test_init_with_optionals (self ):
9
+ t = Organizations (domain = 'domain' , token = 'jwttoken' , telemetry = False , timeout = (10 , 2 ))
10
+ self .assertEqual (t .client .timeout , (10 , 2 ))
11
+ telemetry_header = t .client .base_headers .get ('Auth0-Client' , None )
12
+ self .assertEqual (telemetry_header , None )
13
+
14
+ @mock .patch ('auth0.v3.management.organizations.RestClient' )
15
+ def test_all_organizations (self , mock_rc ):
16
+ mock_instance = mock_rc .return_value
17
+
18
+ c = Organizations (domain = 'domain' , token = 'jwttoken' )
19
+
20
+ # Default parameters are requested
21
+ c .all_organizations ()
22
+
23
+ args , kwargs = mock_instance .get .call_args
24
+
25
+ self .assertEqual ('https://domain/api/v2/organizations' , args [0 ])
26
+ self .assertEqual (kwargs ['params' ], {'page' : None ,
27
+ 'per_page' : None })
28
+
29
+ # Specific pagination
30
+ c .all_organizations (page = 7 , per_page = 25 )
31
+
32
+ args , kwargs = mock_instance .get .call_args
33
+
34
+ self .assertEqual ('https://domain/api/v2/organizations' , args [0 ])
35
+ self .assertEqual (kwargs ['params' ], {'page' : 7 ,
36
+ 'per_page' : 25 })
37
+
38
+ @mock .patch ('auth0.v3.management.organizations.RestClient' )
39
+ def test_get_organization_by_name (self , mock_rc ):
40
+ mock_instance = mock_rc .return_value
41
+
42
+ c = Organizations (domain = 'domain' , token = 'jwttoken' )
43
+ c .get_organization_by_name ('test-org' )
44
+
45
+ args , kwargs = mock_instance .get .call_args
46
+
47
+ self .assertEqual ('https://domain/api/v2/organizations' , args [0 ])
48
+ self .assertEqual (kwargs ['params' ], {'name' : 'test-org' })
49
+
50
+ @mock .patch ('auth0.v3.management.organizations.RestClient' )
51
+ def test_create_organization (self , mock_rc ):
52
+ mock_instance = mock_rc .return_value
53
+
54
+ c = Organizations (domain = 'domain' , token = 'jwttoken' )
55
+ c .create_organization ({'a' : 'b' , 'c' : 'd' })
56
+
57
+ mock_instance .post .assert_called_with (
58
+ 'https://domain/api/v2/organizations' ,
59
+ data = {'a' : 'b' , 'c' : 'd' }
60
+ )
61
+
62
+ @mock .patch ('auth0.v3.management.organizations.RestClient' )
63
+ def test_update (self , mock_rc ):
64
+ mock_instance = mock_rc .return_value
65
+
66
+ c = Organizations (domain = 'domain' , token = 'jwttoken' )
67
+ c .update ('this-id' , {'a' : 'b' , 'c' : 'd' })
68
+
69
+ args , kwargs = mock_instance .patch .call_args
70
+
71
+ self .assertEqual ('https://domain/api/v2/organizations/this-id' , args [0 ])
72
+ self .assertEqual (kwargs ['data' ], {'a' : 'b' , 'c' : 'd' })
73
+
74
+ @mock .patch ('auth0.v3.management.organizations.RestClient' )
75
+ def test_delete_organization (self , mock_rc ):
76
+ mock_instance = mock_rc .return_value
77
+
78
+ c = Organizations (domain = 'domain' , token = 'jwttoken' )
79
+ c .delete_organization ('this-id' )
80
+
81
+ mock_instance .delete .assert_called_with (
82
+ 'https://domain/api/v2/organizations/this-id'
83
+ )
0 commit comments