@pytest.mark.django_db
def test_edit_user_view(team_leaders_group, admin_client):
    user = UserFactory(**USER_DETAILS)
    url = reverse('wagtailusers_users:edit', kwargs={'pk': user.pk})
    post_data = USER_DETAILS_CHANGING.copy()
    post_data['groups'] = [team_leaders_group.pk]
    response = admin_client.post(url, data=post_data)
    assert (response.context['message'] == 'User johnsmith updated.')
    assert (response.status_code == status.HTTP_302_FOUND)
    assert (response.url == reverse('wagtailusers_users:index'))
    user.refresh_from_db()
    for (field_name, changed_value) in USER_DETAILS_CHANGING.items():
        assert (getattr(user, field_name) == changed_value)
    group_ids = set(user.groups.values_list('id', flat=True))
    assert (group_ids == {team_leaders_group.pk})
@pytest.mark.django_db
def test_edit_user_view(team_leaders_group, admin_client):
    user = UserFactory(**USER_DETAILS)
    url = reverse('wagtailusers_users:edit', kwargs={'pk': user.pk})
    post_data = USER_DETAILS_CHANGING.copy()
    post_data['groups'] = [team_leaders_group.pk]
    response = admin_client.post(url, data=post_data)
    assert (response.context['message'] == 'User johnsmith updated.')
    assert (response.status_code == status.HTTP_302_FOUND)
    assert (response.url == reverse('wagtailusers_users:index'))
    user.refresh_from_db()
    for (field_name, changed_value) in USER_DETAILS_CHANGING.items():
        assert (getattr(user, field_name) == changed_value)
    group_ids = set(user.groups.values_list('id', flat=True))
    assert (group_ids == {team_leaders_group.pk})