def test_stop_impersonating_without_impersonating(rf, admin_user, regular_user): get_default_shop() request = apply_request_middleware(rf.post("/"), user=admin_user) assert "impersonator_user_id" not in request.session response = stop_impersonating(request) assert response.status_code == 403
def test_stop_impersonating(rf, admin_user, regular_user): get_default_shop() view_func = LoginAsUserView.as_view() request = apply_request_middleware(rf.post("/"), user=admin_user) assert get_logout_url({"request": request}) == reverse("shuup:logout") get_person_contact(regular_user) response = view_func(request, pk=regular_user.pk) assert response["location"] == reverse("shuup:index") assert get_user(request) == regular_user assert "impersonator_user_id" in request.session assert get_logout_url({"request": request}) == reverse("shuup:stop-impersonating") assert is_authenticated(get_user(request)) response = stop_impersonating(request) assert response.status_code in [301, 302] # redirect assert "impersonator_user_id" not in request.session assert is_authenticated(get_user(request)) assert request.user == admin_user