Revision f432088a snf-astakos-app/astakos/im/tests.py

b/snf-astakos-app/astakos/im/tests.py
269 269
        r = client.get("/im/login/shibboleth?", follow=True)
270 270
        self.assertFalse(r.context['request'].user.is_authenticated())
271 271

  
272
        user2 = get_local_user('kpap@grnet.gr')
272
        # lets remove local password
273
        user = AstakosUser.objects.get(username="kpap@grnet.gr",
274
                                       email="kpap@grnet.gr")
275
        provider_pk = user.auth_providers.get(module='local').pk
276
        provider_shib_pk = user.auth_providers.get(module='shibboleth').pk
277
        client.set_tokens(mail="kpap@shibboleth.gr", eppn="kpapeppn", cn="1")
278
        r = client.get("/im/login/shibboleth?", follow=True)
279
        client.reset_tokens()
280
        r = client.get("/im/remove_auth_provider/%d" % provider_pk)
281
        self.assertEqual(user.auth_providers.count(), 1)
282
        r = client.get("/im/remove_auth_provider/%d" % provider_pk)
283
        self.assertEqual(r.status_code, 404)
284
        r = client.get("/im/remove_auth_provider/%d" % provider_shib_pk)
285
        self.assertEqual(r.status_code, 403)
286

  
287
        self.client.logout()
288
        post_data = {'password': 'password',
289
                     'username': 'kpap@grnet.gr'}
290
        r = self.client.post('/im/local', post_data, follow=True)
291
        self.assertFalse(r.context['request'].user.is_authenticated())
292

  
293
        r = client.get("/im/password_change", follow=True)
294
        r = client.post("/im/password_change", {'new_password1':'111',
295
                                                'new_password2': '111'},
296
                        follow=True)
297
        user = r.context['request'].user
298
        self.assertTrue(user.has_auth_provider('local'))
299
        self.assertTrue(user.has_auth_provider('shibboleth'))
300
        self.assertTrue(user.check_password('111'))
301
        self.assertTrue(user.has_usable_password())
302
        self.client.logout()
303
        post_data = {'password': '111',
304
                     'username': 'kpap@grnet.gr'}
305
        r = self.client.post('/im/local', post_data, follow=True)
306
        self.assertTrue(r.context['request'].user.is_authenticated())
307

  
308
        client.set_tokens(mail="kpap@shibboleth.gr", eppn="kpapeppn", cn="1")
309
        r = client.get("/im/login/shibboleth?", follow=True)
310
        r = client.get("/im/login/shibboleth?", follow=True)
311
        user = AstakosUser.objects.get(username="kpap@grnet.gr",
312
                                       email="kpap@grnet.gr")
313

  
314
        user2 = get_local_user('another@grnet.gr')
315
        user2.add_auth_provider('shibboleth', identifier='existingeppn')
316

  
317
        self.assertEqual(user.auth_providers.count(), 2) # local and 1 shibboleth
318
        client.set_tokens(mail="kpap_second@shibboleth.gr", eppn="kpapeppn2", cn="1")
319
        r = client.get("/im/login/shibboleth?", follow=True)
320
        self.assertEqual(user.auth_providers.count(), 3) # local and 2 shibboleth
321

  
322
        client.set_tokens(mail="kpap_second@shibboleth.gr", eppn="kpapeppn2", cn="1")
323
        r = client.get("/im/login/shibboleth?", follow=True)
324

  
325
        client.set_tokens(mail="kpap_second@shibboleth.gr", eppn="existingeppn", cn="1")
326
        r = client.get("/im/login/shibboleth?", follow=True)
327
        self.assertContains(r, 'Account already exists')
273 328

  
274 329

  
275 330
class LocalUserTests(TestCase):

Also available in: Unified diff