Skip to content

Commit 988bb7b

Browse files
committed
Add vue test for DOI on draft dandiset
1 parent 3d41c8c commit 988bb7b

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from __future__ import annotations
2+
3+
from django.core.management.base import BaseCommand
4+
5+
from dandiapi.api.models import Dandiset, Version
6+
7+
8+
class Command(BaseCommand):
9+
help = 'Inject a DOI into a dandiset version for testing'
10+
11+
def add_arguments(self, parser):
12+
parser.add_argument(
13+
'dandiset_identifier', type=str, help='Dandiset identifier (e.g., 000001)'
14+
)
15+
parser.add_argument(
16+
'--dandiset-version', type=str, default='draft', help='Version (default: draft)'
17+
)
18+
parser.add_argument(
19+
'--doi', type=str, help='DOI to inject (if not provided, will generate one)'
20+
)
21+
22+
def handle(self, *args, **options):
23+
dandiset_identifier = options['dandiset_identifier']
24+
version = options['dandiset_version']
25+
doi = options['doi']
26+
27+
try:
28+
try:
29+
dandiset = Dandiset.objects.get(id=int(dandiset_identifier))
30+
except (ValueError, Dandiset.DoesNotExist):
31+
numeric_id = (
32+
int(dandiset_identifier.lstrip('0')) if dandiset_identifier.lstrip('0') else 0
33+
)
34+
dandiset = Dandiset.objects.get(id=numeric_id)
35+
36+
version_obj = Version.objects.get(dandiset=dandiset, version=version)
37+
38+
if not doi:
39+
# TODO: this prefix needs to be updated for non-dandi deployments
40+
doi = f'10.80507/dandi.{dandiset_identifier}'
41+
42+
version_obj.metadata['doi'] = doi
43+
version_obj.save()
44+
45+
self.stdout.write(
46+
self.style.SUCCESS(
47+
f'Successfully injected DOI "{doi}" into {dandiset_identifier}/{version}'
48+
)
49+
)
50+
51+
except Dandiset.DoesNotExist:
52+
self.stdout.write(self.style.ERROR(f'Dandiset {dandiset_identifier} not found'))
53+
except Version.DoesNotExist:
54+
self.stdout.write(
55+
self.style.ERROR(f'Version {version} not found for dandiset {dandiset_identifier}')
56+
)

e2e/tests/dandisetLandingPage.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect, test } from "@playwright/test";
22
import { clientUrl, registerNewUser, LOGOUT_BUTTON_TEXT, registerDandiset } from "../utils.ts";
33
import { faker } from "@faker-js/faker";
4+
import { execSync } from "child_process";
45

56
test.describe("dandiset landing page", async () => {
67
test("add an owner to the dandiset", async ({ page, browser }) => {
@@ -40,9 +41,42 @@ test.describe("dandiset landing page", async () => {
4041
await expect(newPage.getByText(otherUserName)).toHaveCount(1);
4142
await context.close();
4243
});
44+
4345
test("navigate to an invalid dandiset URL", async ({ page }) => {
4446
await page.goto(`${clientUrl}/dandiset/1`);
4547
await page.waitForLoadState("networkidle");
4648
await expect(page.getByText("Error: Dandiset does not exist")).toHaveCount(1);
4749
});
50+
51+
test("draft dandiset shows dandiset DOI", async ({ page }) => {
52+
// Register a new user and create a dandiset
53+
await registerNewUser(page);
54+
const dandisetName = faker.lorem.words();
55+
const dandisetDescription = faker.lorem.sentences();
56+
const dandisetId = await registerDandiset(page, dandisetName, dandisetDescription);
57+
58+
// Inject a DOI directly using Django management command
59+
const testDoi = `10.80507/dandi.${dandisetId}`;
60+
61+
// Execute the Django management command to inject DOI
62+
try {
63+
execSync(`cd .. && python manage.py inject_doi ${dandisetId} --dandiset-version=draft --doi="${testDoi}"`, {
64+
stdio: 'inherit',
65+
timeout: 10000
66+
});
67+
} catch (error) {
68+
console.error('Failed to inject DOI:', error);
69+
}
70+
71+
// Refresh the page to see the updated DOI
72+
await page.reload();
73+
await page.waitForLoadState("networkidle");
74+
75+
// The draft version should show the injected Dandiset DOI
76+
await expect(page.getByText(testDoi)).toHaveCount(1);
77+
78+
// Should not show a version DOI (since it's a draft)
79+
const versionDoiPattern = new RegExp(`10\\.(48324|80507)/dandi\\.${dandisetId}/`);
80+
await expect(page.getByText(versionDoiPattern)).toHaveCount(0);
81+
});
4882
});

0 commit comments

Comments
 (0)