Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Carrot's API tests and Homepage redirecting #940

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 44 additions & 57 deletions app/api/test/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,43 +222,35 @@ def setUp(self):
# Request factory for setting up requests
self.client = APIClient()

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
)
def test_update_returns(self):
# Authenticate admin user
self.client.force_authenticate(self.admin_user)
# Make the request
response = self.client.patch(
f"/api/datasets/update/{self.dataset.id}/", data={"name": "The Two Towers"}
f"/api/v2/datasets/{self.dataset.id}/",
data={"name": "The Two Towers"},
)
response_data = response.data
# Ensure admin user can update Dataset
self.assertEqual(response.status_code, 200)
self.assertEqual(response_data.get("name"), "The Two Towers")

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
)
def test_non_admin_member_forbidden(self):
# Authenticate non admin user
self.client.force_authenticate(self.non_admin_user)
# Make the request
response = self.client.patch(
f"/api/datasets/update/{self.dataset.id}/", data={"name": "The Two Towers"}
f"/api/v2/datasets/{self.dataset.id}/", data={"name": "The Two Towers"}
)
# Ensure non admin user is Forbidden
self.assertEqual(response.status_code, 403)

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
)
def test_non_project_member_forbidden(self):
# Authenticate non project user
self.client.force_authenticate(self.non_project_user)
# Make the request
response = self.client.patch(
f"/api/datasets/update/{self.dataset.id}/", data={"name": "The Two Towers"}
f"/api/v2/datasets/{self.dataset.id}/", data={"name": "The Two Towers"}
)
# Ensure non project user is Forbidden
self.assertEqual(response.status_code, 403)
Expand Down Expand Up @@ -301,36 +293,27 @@ def setUp(self):
# Request factory for setting up requests
self.client = APIClient()

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
)
def test_non_admin_member_can_see(self):
# Authenticate non admin user
self.client.force_authenticate(self.non_admin_user)
# Make the request
response = self.client.get(f"/api/datasets/{self.dataset.id}/")
response = self.client.get(f"/api/v2/datasets/{self.dataset.id}/")
# Ensure non admin user can see
self.assertEqual(response.status_code, 200)

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
)
def test_admin_member_can_see(self):
# Authenticate admin user
self.client.force_authenticate(self.admin_user)
# Make the request
response = self.client.get(f"/api/datasets/{self.dataset.id}/")
response = self.client.get(f"/api/v2/datasets/{self.dataset.id}/")
# Ensure admin user can see
self.assertEqual(response.status_code, 200)

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
)
def test_non_project_member_forbidden(self):
# Authenticate non project user
self.client.force_authenticate(self.non_project_user)
# Make the request
response = self.client.get(f"/api/datasets/{self.dataset.id}/")
response = self.client.get(f"/api/v2/datasets/{self.dataset.id}/")
# Ensure non project user is Forbidden
self.assertEqual(response.status_code, 403)

Expand Down Expand Up @@ -372,7 +355,7 @@ def setUp(self):
self.client = APIClient()

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
reason="TODO: Carrot doesn't support this Delete dataset function yet. When it does, update test accordingly"
)
def test_update_returns(self):
# Authenticate admin user
Expand All @@ -383,7 +366,7 @@ def test_update_returns(self):
self.assertEqual(response.status_code, 204)

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
reason="TODO: Carrot doesn't support this Delete dataset function yet. When it does, update test accordingly"
)
def test_non_admin_member_forbidden(self):
# Authenticate non admin user
Expand All @@ -394,7 +377,7 @@ def test_non_admin_member_forbidden(self):
self.assertEqual(response.status_code, 403)

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
reason="TODO: Carrot doesn't support this Delete dataset function yet. When it does, update test accordingly"
)
def test_non_project_member_forbidden(self):
# Authenticate non project user
Expand Down Expand Up @@ -451,9 +434,6 @@ def setUp(self):
# Set up API client
self.client = APIClient()

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
)
def test_admin_user_get(self):
"""Users who are admins of the parent dataset can see all public SRs
and restricted SRs whose parent dataset they are the admin of.
Expand All @@ -468,9 +448,11 @@ def test_admin_user_get(self):

# Get data admin_user should be able to see
self.client.force_authenticate(admin_user)
admin_response = self.client.get("/api/scanreports/")
admin_response = self.client.get("/api/v2/scanreports/")
self.assertEqual(admin_response.status_code, 200)
observed_objs = sorted([obj.get("id") for obj in admin_response.data])
observed_objs = sorted(
[obj.get("id") for obj in admin_response.data["results"]]
)
expected_objs = sorted(
[
self.scanreport1.id,
Expand All @@ -489,19 +471,18 @@ def test_admin_user_get(self):
)
self.project.members.add(non_admin_user)

# Get data admin_user should be able to see
# Get data non_admin_user should be able to see
self.client.force_authenticate(non_admin_user)
non_admin_response = self.client.get("/api/scanreports/")
non_admin_response = self.client.get("/api/v2/scanreports/")
self.assertEqual(non_admin_response.status_code, 200)
observed_objs = sorted([obj.get("id") for obj in non_admin_response.data])
observed_objs = sorted(
[obj.get("id") for obj in non_admin_response.data["results"]]
)
expected_objs = [self.scanreport1.id]

# Assert the observed results are the same as the expected
self.assertListEqual(observed_objs, expected_objs)

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
)
def test_editor_get(self):
"""Users who are editors of the parent dataset can see all public SRs
and restricted SRs whose parent dataset they are an editor of.
Expand All @@ -516,9 +497,11 @@ def test_editor_get(self):

# Get data editor_user should be able to see
self.client.force_authenticate(editor_user)
editor_response = self.client.get("/api/scanreports/")
editor_response = self.client.get("/api/v2/scanreports/")
self.assertEqual(editor_response.status_code, 200)
observed_objs = sorted([obj.get("id") for obj in editor_response.data])
observed_objs = sorted(
[obj.get("id") for obj in editor_response.data["results"]]
)
expected_objs = sorted(
[
self.scanreport1.id,
Expand All @@ -539,17 +522,16 @@ def test_editor_get(self):

# Get data non_editor_user should be able to see
self.client.force_authenticate(non_editor_user)
non_editor_response = self.client.get("/api/scanreports/")
non_editor_response = self.client.get("/api/v2/scanreports/")
self.assertEqual(non_editor_response.status_code, 200)
observed_objs = sorted([obj.get("id") for obj in non_editor_response.data])
observed_objs = sorted(
[obj.get("id") for obj in non_editor_response.data["results"]]
)
expected_objs = [self.scanreport1.id]

# Assert the observed results are the same as the expected
self.assertListEqual(observed_objs, expected_objs)

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
)
def test_viewer_get(self):
"""Users who are viewers of the parent dataset can see all public SRs
and restricted SRs whose parent dataset they are a viewer of.
Expand All @@ -564,9 +546,11 @@ def test_viewer_get(self):

# Get data viewer_user should be able to see
self.client.force_authenticate(viewer_user)
viewer_response = self.client.get("/api/scanreports/")
viewer_response = self.client.get("/api/v2/scanreports/")
self.assertEqual(viewer_response.status_code, 200)
observed_objs = sorted([obj.get("id") for obj in viewer_response.data])
observed_objs = sorted(
[obj.get("id") for obj in viewer_response.data["results"]]
)
expected_objs = sorted([self.scanreport1.id, self.scanreport4.id])

# Assert the observed results are the same as the expected
Expand All @@ -580,15 +564,16 @@ def test_viewer_get(self):

# Get data non_viewer_user should be able to see
self.client.force_authenticate(non_viewer_user)
non_viewer_response = self.client.get("/api/scanreports/")
non_viewer_response = self.client.get("/api/v2/scanreports/")
self.assertEqual(non_viewer_response.status_code, 200)
observed_objs = sorted([obj.get("id") for obj in non_viewer_response.data])
observed_objs = sorted(
[obj.get("id") for obj in non_viewer_response.data["results"]]
)
expected_objs = [self.scanreport1.id]

# Assert the observed results are the same as the expected
self.assertListEqual(observed_objs, expected_objs)

@pytest.mark.skip(reason="TODO: Fails due to the API query.")
def test_author_get(self):
"""Authors can see all public SRs and restricted SRs they are the author of."""
User = get_user_model()
Expand All @@ -601,9 +586,11 @@ def test_author_get(self):

# Get data admin_user should be able to see
self.client.force_authenticate(author_user)
author_response = self.client.get("/api/scanreports/")
author_response = self.client.get("/api/v2/scanreports/")
self.assertEqual(author_response.status_code, 200)
observed_objs = sorted([obj.get("id") for obj in author_response.data])
observed_objs = sorted(
[obj.get("id") for obj in author_response.data["results"]]
)
expected_objs = sorted([self.scanreport1.id, self.scanreport3.id])

# Assert the observed results are the same as the expected
Expand All @@ -617,17 +604,17 @@ def test_author_get(self):

# Get data non_author_user should be able to see
self.client.force_authenticate(non_author_user)
non_author_response = self.client.get("/api/scanreports/")
non_author_response = self.client.get("/api/v2/scanreports/")
self.assertEqual(non_author_response.status_code, 200)
observed_objs = sorted([obj.get("id") for obj in non_author_response.data])
observed_objs = sorted(
[obj.get("id") for obj in non_author_response.data["results"]]
)
expected_objs = sorted([self.scanreport1.id])

# Assert the observed results are the same as the expected
self.assertListEqual(observed_objs, expected_objs)

@pytest.mark.skip(
reason="TODO: Need updating test according to the current view/API endpoints."
)
@pytest.mark.skip(reason="We don't use AZ_FUNCTION_USER anymore")
@mock.patch.dict(os.environ, {"AZ_FUNCTION_USER": "az_functions"}, clear=True)
def test_az_function_user_get(self):
"""AZ_FUNCTION_USER can see all public SRs and restricted SRs."""
Expand Down
2 changes: 1 addition & 1 deletion app/next-client-app/app/(protected)/datasets/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { EyeNoneIcon, EyeOpenIcon, Pencil2Icon } from "@radix-ui/react-icons";
import { format } from "date-fns/format";
import Link from "next/link";
import { HandleArchive } from "@/components/HandleArchive";
import { HandleArchive } from "@/components/core/HandleArchive";

export const columns: ColumnDef<DataSet>[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ColumnDef } from "@tanstack/react-table";
import { DataTableColumnHeader } from "@/components/data-table/DataTableColumnHeader";
import { Button } from "@/components/ui/button";
import { format } from "date-fns/format";
import { HandleArchive } from "@/components/HandleArchive";
import { HandleArchive } from "@/components/core/HandleArchive";
import { useState } from "react";
import DeleteDialog from "@/components/scanreports/DeleteDialog";
import { MappingStatus } from "@/components/scanreports/MappingStatus";
Expand Down
32 changes: 1 addition & 31 deletions app/next-client-app/app/(public)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
import CallToAction from "@/components/homepage/CTA";
import BentoProjects from "@/components/homepage/bentoProjects";
import Features from "@/components/homepage/features";
import Funders from "@/components/homepage/funders";
import Hero from "@/components/homepage/hero";
import { cn } from "@/lib/utils";
import AnimatedGridPattern from "@/components/magicui/animated-grid-pattern";

export default function Default() {
return (
<>
{/* Background */}
<AnimatedGridPattern
numSquares={60}
maxOpacity={0.1}
duration={1.2}
repeatDelay={1}
className={cn(
"[mask-image:radial-gradient(800px_circle_at_center,white,transparent)]",
"inset-x-0 inset-y-[-30%] h-full skew-y-12 mt-[200px] overflow-hidden",
)}
/>{" "}
{/* Content */}
<div className="space-y-12 lg:space-y-32">
<Hero />
{process.env.ENABLE_FEATURES && <Features />}
{process.env.ENABLE_PROJECTS && <BentoProjects />}
{process.env.ENABLE_FUNDERS && <Funders />}
<CallToAction />
</div>
</>
);
return <></>;
}
2 changes: 1 addition & 1 deletion app/next-client-app/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "./globals.css";
import { Toaster } from "sonner";
import { ThemeProvider } from "@/components/theme-provider";
import { ThemeProvider } from "@/components/core/theme-provider";
import { Metadata } from "next";

export const metadata: Metadata = {
Expand Down
Loading
Loading