Skip to content
test_auth.py 88 KiB
Newer Older
Dong Zhuang's avatar
Dong Zhuang committed

        user_attribute = {
            'PrincipalName': (user.username,),
            'iTrustUIN': (expected_inst_id,),
            'givenName': (expected_first,),
            'sn': (expected_last,),
        }

        with mock.patch("accounts.models.User.save") as mock_save:
            user = backend.update_user(user, user_attribute, saml_attribute_mapping)
            self.assertEqual(mock_save.call_count, 1)

        user = backend.update_user(user, user_attribute, saml_attribute_mapping)
        self.assertEqual(user.first_name, expected_first)
        self.assertEqual(user.last_name, expected_last)
        self.assertTrue(user.name_verified)
        self.assertEqual(user.status, constants.user_status.unconfirmed)
        self.assertTrue(user.institutional_id_verified)

        user_attribute = {
            'PrincipalName': (user.username,),
            'iTrustUIN': (expected_inst_id,),
            'mail': (user.email,),
            'givenName': (expected_first,),
            'sn': (expected_last,),
        }
        user = backend.update_user(user, user_attribute, saml_attribute_mapping)
        self.assertEqual(user.first_name, expected_first)
        self.assertEqual(user.last_name, expected_last)
        self.assertTrue(user.name_verified)
        self.assertEqual(user.status, constants.user_status.active)
        self.assertTrue(user.institutional_id_verified)

        with mock.patch("accounts.models.User.save") as mock_save:
            # no changes
            backend.update_user(user, user_attribute, saml_attribute_mapping)
            self.assertEqual(mock_save.call_count, 0)

Dong Zhuang's avatar
Dong Zhuang committed
# vim: foldmethod=marker