@pytest.mark.django_db
def test_edit_user_view_marks_user_as_approved_if_added_to_group(admin_client, admin_user, user_awaiting_approval):
    settings.FEATURE_FLAGS['ENFORCE_STAFF_SSO_ON'] = True
    user = user_awaiting_approval
    profile = user_awaiting_approval.userprofile
    url = reverse('wagtailusers_users:edit', kwargs={'pk': user.pk})
    group = Group.objects.get(pk=profile.self_assigned_group_id)
    group.permissions.add(Permission.objects.get(codename='access_admin'))
    with patch('users.views.notify_user_of_access_request_approval', autospec=True) as mocked_method:
        response = admin_client.post(url, {'username': user.username, 'first_name': user.first_name, 'last_name': user.last_name, 'email': user.email, 'is_active': True, 'groups': [group.pk]})
    assert (response.context['message'] == ('User %s updated.' % user.username))
    assert (response.status_code == status.HTTP_302_FOUND)
    assert (response.url == reverse('wagtailusers_users:index'))
    profile.refresh_from_db()
    assert (profile.assignment_status == UserProfile.STATUS_APPROVED)
    assert (profile.approved_by_id == admin_user.id)
    assert (profile.approved_at is not None)
    expected_call_args = dict(request=response.wsgi_request, user_email=user.email, user_name=user.first_name, reviewer_name=admin_user.get_full_name())
    mocked_method.assert_called_with(**expected_call_args)
    settings.FEATURE_FLAGS['ENFORCE_STAFF_SSO_ON'] = False
    reload_urlconf()
@pytest.mark.django_db
def test_edit_user_view_marks_user_as_approved_if_added_to_group(admin_client, admin_user, user_awaiting_approval):
    settings.FEATURE_FLAGS['ENFORCE_STAFF_SSO_ON'] = True
    user = user_awaiting_approval
    profile = user_awaiting_approval.userprofile
    url = reverse('wagtailusers_users:edit', kwargs={'pk': user.pk})
    group = Group.objects.get(pk=profile.self_assigned_group_id)
    group.permissions.add(Permission.objects.get(codename='access_admin'))
    with patch('users.views.notify_user_of_access_request_approval', autospec=True) as mocked_method:
        response = admin_client.post(url, {'username': user.username, 'first_name': user.first_name, 'last_name': user.last_name, 'email': user.email, 'is_active': True, 'groups': [group.pk]})
    assert (response.context['message'] == ('User %s updated.' % user.username))
    assert (response.status_code == status.HTTP_302_FOUND)
    assert (response.url == reverse('wagtailusers_users:index'))
    profile.refresh_from_db()
    assert (profile.assignment_status == UserProfile.STATUS_APPROVED)
    assert (profile.approved_by_id == admin_user.id)
    assert (profile.approved_at is not None)
    expected_call_args = dict(request=response.wsgi_request, user_email=user.email, user_name=user.first_name, reviewer_name=admin_user.get_full_name())
    mocked_method.assert_called_with(**expected_call_args)
    settings.FEATURE_FLAGS['ENFORCE_STAFF_SSO_ON'] = False
    reload_urlconf()