def test_user_group_creation(self): group_model = MagicMock() instance = MagicMock() instance.social_auth.count.return_value = 1 social_mock = MagicMock(extra_data={'roles': ['manager']}) instance.social_auth.all.return_value = [social_mock] group_instance = MagicMock() group_model.objects.get_or_create.return_value = (group_instance, True) from wirecloud.keycloak import social_auth_backend social_auth_backend.get_group_model = MagicMock() social_auth_backend.get_group_model.return_value = group_model social_auth_backend.add_user_groups(MagicMock(), instance, True) # Check calls instance.social_auth.count.assert_called_once_with() instance.social_auth.all.assert_called_once_with() instance.groups.clear.assert_called_once_with() group_model.objects.get_or_create.assert_called_once_with( name='manager') instance.groups.add.assert_called_once_with(group_instance)
def test_user_group_no_social_profile(self): instance = MagicMock() instance.social_auth.count.return_value = 0 from wirecloud.keycloak import social_auth_backend social_auth_backend.add_user_groups(MagicMock(), instance, True) instance.social_auth.count.assert_called_once_with() self.assertEqual(0, instance.social_auth.all.call_count)
def test_user_group_remove_roles(self): instance = MagicMock() instance.social_auth.count.return_value = 1 social_mock = MagicMock(extra_data={}) instance.social_auth.all.return_value = [social_mock] from wirecloud.keycloak import social_auth_backend social_auth_backend.get_group_model = MagicMock() social_auth_backend.add_user_groups(MagicMock(), instance, True) instance.social_auth.count.assert_called_once_with() instance.social_auth.all.assert_called_once_with() instance.groups.clear.assert_called_once_with() self.assertEqual(0, social_auth_backend.get_group_model.call_count)