@@ -81,6 +81,7 @@ def setUp(self):
81
81
fields = [dict (name = 'first_name' , type = 'string' ), dict (name = 'last_name' , type = 'string' ),
82
82
dict (name = 'email' , type = 'string' )]
83
83
self .us = self .chino .user_schemas .create ('test' , fields )
84
+ self .app_list = []
84
85
85
86
def tearDown (self ):
86
87
# if user has been created we remove it.
@@ -93,6 +94,10 @@ def tearDown(self):
93
94
if hasattr (self , 'app' ):
94
95
self .chino .applications .delete (self .app ._id )
95
96
97
+ # delete also every Application which was created forthis test
98
+ for app in self .chino .applications .list ().to_dict ()['applications' ]:
99
+ self .chino .applications .delete (app ['app_id' ], force = True )
100
+
96
101
def test_list (self ):
97
102
list = self .chino .users .list (self .us ._id )
98
103
self .assertIsNotNone (list .paging )
@@ -155,7 +160,39 @@ def test_auth(self):
155
160
self .assertEqual (ste_2 .username , EDIT )
156
161
157
162
self .chino_user .users .refresh ()
158
- # now should be impossible to create the user
163
+ # it should be impossible to create the user after login with self.chino_user (no admin access)
164
+ self .assertRaises (CallError , self .chino_user .users .create , self .us ._id , username = 'error' , password = '12345678' ,
165
+ attributes = dict (first_name = 'john' , last_name = 'doe' ,
166
+
167
+
168
+ self .chino_user .users .logout ()
169
+ self .assertRaises (Exception , self .chino_user .users .login , EDIT , '' )
170
+
171
+ self .assertRaises (CallError , self .chino .users .current )
172
+
173
+ def test_auth_public (self ):
174
+ # login
175
+ NAME = 'test.user.new'
176
+ EDIT = NAME + '.edited'
177
+ self .app = self .chino .applications .create ("test" , grant_type = 'password' , client_type = 'public' )
178
+ # Init 'public' client
179
+ self .chino_user = ChinoAPIClient (customer_id = cfg .customer_id ,
180
+ url = cfg .url ,
181
+ client_id = self .app .app_id ,
182
+ client_secret = None
183
+ )
184
+ self .assertIsNone (self .chino_user .auth .client_secret )
185
+
186
+ user = self .chino .users .create (self .us ._id , username = EDIT , password = '12345678' ,
187
+ attributes = dict (first_name = 'john' , last_name = 'doe' ,
188
+
189
+
190
+ self .chino_user .users .login (EDIT , '12345678' )
191
+ ste_2 = self .chino_user .users .current ()
192
+ self .assertEqual (ste_2 .username , EDIT )
193
+
194
+ self .chino_user .users .refresh ()
195
+ # it should be impossible to create the user after login with self.chino_user (no admin access)
159
196
self .assertRaises (CallError , self .chino_user .users .create , self .us ._id , username = 'error' , password = '12345678' ,
160
197
attributes = dict (first_name = 'john' , last_name = 'doe' ,
161
198
@@ -178,11 +215,20 @@ def tearDown(self):
178
215
self .logger .debug ("tearing down %s" , self .user )
179
216
180
217
def test_CRUD (self ):
181
- app = self .chino .applications .create (name = 'tessst' , grant_type = 'password' )
218
+ app = self .chino .applications .create (name = 'tesssst_confidential' , grant_type = 'password' )
219
+ app_public = self .chino .applications .create (name = 'test_public' , grant_type = 'password' , client_type = 'public' )
220
+
221
+ app_public1 = self .chino .applications .detail (app_public ._id )
222
+ self .assertEqual (app_public ._id , app_public1 ._id )
223
+ self .assertEqual (app_public .app_name , app_public1 .app_name )
224
+
225
+ newname = 'test_confidential'
226
+ self .chino .applications .update (app ._id , name = newname )
182
227
app1 = self .chino .applications .detail (app ._id )
183
- self .chino . applications . update (app1 ._id , name = 'asds' )
184
- app2 = self . chino . applications . detail ( app1 . _id )
228
+ self .assertEqual (app1 .app_name , newname )
229
+
185
230
apps = self .chino .applications .list ()
231
+ self .chino .applications .delete (app_public1 ._id , force = True )
186
232
self .chino .applications .delete (app1 ._id , force = True )
187
233
188
234
0 commit comments