@pytest.mark.django_db
def test_edit_user_view_does_not_mark_user_as_approved_if_not_added_to_a_group(admin_client, groups_with_info):
    user = UserFactory(username='some-user')
    profile = user.userprofile
    profile.assignment_status = UserProfile.STATUS_AWAITING_APPROVAL
    profile.self_assigned_group_id = groups_with_info[0].id
    profile.save()
    url = reverse('wagtailusers_users:edit', kwargs={'pk': user.pk})
    with patch('users.views.notify_user_of_access_request_approval') 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})
    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_AWAITING_APPROVAL)
    assert (profile.approved_by_id is None)
    assert (profile.approved_at is None)
    mocked_method.assert_not_called()
@pytest.mark.django_db
def test_edit_user_view_does_not_mark_user_as_approved_if_not_added_to_a_group(admin_client, groups_with_info):
    user = UserFactory(username='some-user')
    profile = user.userprofile
    profile.assignment_status = UserProfile.STATUS_AWAITING_APPROVAL
    profile.self_assigned_group_id = groups_with_info[0].id
    profile.save()
    url = reverse('wagtailusers_users:edit', kwargs={'pk': user.pk})
    with patch('users.views.notify_user_of_access_request_approval') 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})
    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_AWAITING_APPROVAL)
    assert (profile.approved_by_id is None)
    assert (profile.approved_at is None)
    mocked_method.assert_not_called()