@@ -81,6 +81,7 @@ def setUp(self):
8181 fields = [dict (name = 'first_name' , type = 'string' ), dict (name = 'last_name' , type = 'string' ),
8282 dict (name = 'email' , type = 'string' )]
8383 self .us = self .chino .user_schemas .create ('test' , fields )
84+ self .app_list = []
8485
8586 def tearDown (self ):
8687 # if user has been created we remove it.
@@ -93,6 +94,10 @@ def tearDown(self):
9394 if hasattr (self , 'app' ):
9495 self .chino .applications .delete (self .app ._id )
9596
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+
96101 def test_list (self ):
97102 list = self .chino .users .list (self .us ._id )
98103 self .assertIsNotNone (list .paging )
@@ -155,7 +160,39 @@ def test_auth(self):
155160 self .assertEqual (ste_2 .username , EDIT )
156161
157162 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)
159196 self .assertRaises (CallError , self .chino_user .users .create , self .us ._id , username = 'error' , password = '12345678' ,
160197 attributes = dict (first_name = 'john' , last_name = 'doe' ,
161198@@ -178,11 +215,20 @@ def tearDown(self):
178215 self .logger .debug ("tearing down %s" , self .user )
179216
180217 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 )
182227 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+
185230 apps = self .chino .applications .list ()
231+ self .chino .applications .delete (app_public1 ._id , force = True )
186232 self .chino .applications .delete (app1 ._id , force = True )
187233
188234
0 commit comments