def METHOD_NAME(db, client, username, password, project_id):
    client.login(username=username, password=password)
    # store if the membership exists
    membership_existed = Membership.objects.filter(project_id=project_id, user__username=username).exists()
    url = reverse('project_leave', args=[project_id])
    response = client.post(url)
    if project_id in leave_project_permission_map.get(username, []):
        assert response.status_code == 302
        if username == 'owner':
            if membership_existed:
                assert Membership.objects.filter(project_id=project_id, user__username=username).exists()
        else:
            if membership_existed:
                assert not Membership.objects.filter(project_id=project_id, user__username=username).exists()
    else:
        if membership_existed:
            assert Membership.objects.filter(project_id=project_id, user__username=username).exists()
        if password:
            assert response.status_code == 403
        else:
            assert response.status_code == 302