From f0856366957fde84ad29949acdba1b55d1356232 Mon Sep 17 00:00:00 2001 From: Ym <173550318+MaxonT@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:05:39 -0600 Subject: [PATCH] Add a Django project creator to Create New Project from Template Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com> --- README.md | 3 +- docs/managing-python-projects.md | 19 ++ files/templates/newDjangoTemplate/manage.py | 21 ++ .../project_name/__init__.py | 0 .../newDjangoTemplate/project_name/asgi.py | 8 + .../project_name/settings.py | 73 +++++++ .../newDjangoTemplate/project_name/urls.py | 7 + .../newDjangoTemplate/project_name/wsgi.py | 8 + .../newDjangoTemplate/requirements.txt | 1 + src/extension.ts | 5 + src/features/creators/newDjangoProject.ts | 162 ++++++++++++++ .../creators/newDjangoProject.unit.test.ts | 204 ++++++++++++++++++ 12 files changed, 510 insertions(+), 1 deletion(-) create mode 100644 files/templates/newDjangoTemplate/manage.py create mode 100644 files/templates/newDjangoTemplate/project_name/__init__.py create mode 100644 files/templates/newDjangoTemplate/project_name/asgi.py create mode 100644 files/templates/newDjangoTemplate/project_name/settings.py create mode 100644 files/templates/newDjangoTemplate/project_name/urls.py create mode 100644 files/templates/newDjangoTemplate/project_name/wsgi.py create mode 100644 files/templates/newDjangoTemplate/requirements.txt create mode 100644 src/features/creators/newDjangoProject.ts create mode 100644 src/test/features/creators/newDjangoProject.unit.test.ts diff --git a/README.md b/README.md index 841fe718a..1223b318c 100644 --- a/README.md +++ b/README.md @@ -118,10 +118,11 @@ There are a few ways to add a Python Project from the Python Environments panel: #### Create New Project from Template -The **Python Envs: Create New Project from Template** command simplifies the process of starting a new Python project by scaffolding it for you. Whether in a new workspace or an existing one, this command configures the environment and boilerplate file structure, so you don’t have to worry about the initial setup, and only the code you want to write. There are currently two project types supported: +The **Python Envs: Create New Project from Template** command simplifies the process of starting a new Python project by scaffolding it for you. Whether in a new workspace or an existing one, this command configures the environment and boilerplate file structure, so you don’t have to worry about the initial setup, and only the code you want to write. There are currently three project types supported: - Package: A structured Python package with files like `__init__.py` and setup configurations. - Script: A simple project for standalone Python scripts, ideal for quick tasks or just to get you started. +- Django: A minimal Django project with `manage.py`, settings, URL configuration, and ASGI/WSGI entry points. ## Command Reference diff --git a/docs/managing-python-projects.md b/docs/managing-python-projects.md index feaa3a81f..efb99a2a1 100644 --- a/docs/managing-python-projects.md +++ b/docs/managing-python-projects.md @@ -76,6 +76,7 @@ Use this to scaffold a brand new Python project with the correct structure and f 3. Choose a template type: - **Package**: A structured Python package with `pyproject.toml`, tests folder, and package directory - **Script**: A simple standalone Python file using PEP 723 inline metadata + - **Django**: A minimal Django project with `manage.py`, settings, URL, and ASGI/WSGI modules 4. Enter a name for your project. 5. If you're creating a package, choose whether to create a virtual environment. @@ -95,6 +96,24 @@ my_package_project/ └── __init__.py ``` +#### Django template structure + +When you create a Django project named `mysite`, the extension generates: + +``` +mysite_project/ +├── manage.py +├── requirements.txt # Lists django; install it in the project's environment +└── mysite/ # The project package + ├── __init__.py + ├── asgi.py + ├── settings.py # Includes a freshly generated SECRET_KEY + ├── urls.py + └── wsgi.py +``` + +The project name must be a valid Python identifier and cannot be a Python keyword, `django`, or `test`. The extension does not create a virtual environment for Django projects; create one and run `pip install -r requirements.txt` before `python manage.py runserver`. + #### Script template When you create a script, the extension generates a single `.py` file with PEP 723 inline script metadata, which allows you to specify dependencies directly in the file. diff --git a/files/templates/newDjangoTemplate/manage.py b/files/templates/newDjangoTemplate/manage.py new file mode 100644 index 000000000..58e10780b --- /dev/null +++ b/files/templates/newDjangoTemplate/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/files/templates/newDjangoTemplate/project_name/__init__.py b/files/templates/newDjangoTemplate/project_name/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/files/templates/newDjangoTemplate/project_name/asgi.py b/files/templates/newDjangoTemplate/project_name/asgi.py new file mode 100644 index 000000000..0dded74c6 --- /dev/null +++ b/files/templates/newDjangoTemplate/project_name/asgi.py @@ -0,0 +1,8 @@ +"""ASGI config for project_name.""" +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings") + +application = get_asgi_application() diff --git a/files/templates/newDjangoTemplate/project_name/settings.py b/files/templates/newDjangoTemplate/project_name/settings.py new file mode 100644 index 000000000..ea6745884 --- /dev/null +++ b/files/templates/newDjangoTemplate/project_name/settings.py @@ -0,0 +1,73 @@ +"""Django settings for project_name.""" +from pathlib import Path + +BASE_DIR = Path(__file__).resolve().parent.parent + +# This key was generated when the project was created. Keep it secret in production. +SECRET_KEY = "django_secret_key" + +# Turn DEBUG off and set ALLOWED_HOSTS before deploying. +DEBUG = True + +ALLOWED_HOSTS = [] + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "project_name.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "project_name.wsgi.application" +ASGI_APPLICATION = "project_name.asgi.application" + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } +} + +AUTH_PASSWORD_VALIDATORS = [ + {"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"}, + {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"}, + {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"}, + {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"}, +] + +LANGUAGE_CODE = "en-us" +TIME_ZONE = "UTC" +USE_I18N = True +USE_TZ = True + +STATIC_URL = "static/" +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/files/templates/newDjangoTemplate/project_name/urls.py b/files/templates/newDjangoTemplate/project_name/urls.py new file mode 100644 index 000000000..72c05cf02 --- /dev/null +++ b/files/templates/newDjangoTemplate/project_name/urls.py @@ -0,0 +1,7 @@ +"""URL configuration for project_name.""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path("admin/", admin.site.urls), +] diff --git a/files/templates/newDjangoTemplate/project_name/wsgi.py b/files/templates/newDjangoTemplate/project_name/wsgi.py new file mode 100644 index 000000000..b43b99c7c --- /dev/null +++ b/files/templates/newDjangoTemplate/project_name/wsgi.py @@ -0,0 +1,8 @@ +"""WSGI config for project_name.""" +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings") + +application = get_wsgi_application() diff --git a/files/templates/newDjangoTemplate/requirements.txt b/files/templates/newDjangoTemplate/requirements.txt new file mode 100644 index 000000000..d3e4ba564 --- /dev/null +++ b/files/templates/newDjangoTemplate/requirements.txt @@ -0,0 +1 @@ +django diff --git a/src/extension.ts b/src/extension.ts index e088619c2..c402489f7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -42,6 +42,7 @@ import { getPythonApi, setPythonApi } from './extensionApi'; import { createManagerReady } from './features/common/managerReady'; import { AutoFindProjects } from './features/creators/autoFindProjects'; import { ExistingProjects } from './features/creators/existingProjects'; +import { NewDjangoProject } from './features/creators/newDjangoProject'; import { NewPackageProject } from './features/creators/newPackageProject'; import { NewScriptProject } from './features/creators/newScriptProject'; import type { ProjectCreators } from './features/creators/projectCreators'; @@ -207,6 +208,7 @@ export async function activate(context: ExtensionContext): Promise c.name === 'newScript'); } + if (projectType === 'python-django') { + selected = creators.find((c) => c.name === 'newDjango'); + } if (!selected) { throw new Error(`Project creator for type "${projectType}" not found.`); } diff --git a/src/features/creators/newDjangoProject.ts b/src/features/creators/newDjangoProject.ts new file mode 100644 index 000000000..053390e8a --- /dev/null +++ b/src/features/creators/newDjangoProject.ts @@ -0,0 +1,162 @@ +import * as crypto from 'crypto'; +import * as fs from 'fs-extra'; +import * as path from 'path'; +import { commands, l10n, MarkdownString, QuickInputButtons, Uri } from 'vscode'; +import { PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from '../../api'; +import { NEW_PROJECT_TEMPLATES_FOLDER } from '../../common/constants'; +import { traceError } from '../../common/logging'; +import { showErrorMessage, showInputBoxWithButtons, showTextDocument } from '../../common/window.apis'; +import { getWorkspaceFolders } from '../../common/workspace.apis'; +import type { PythonProjectManager } from '../projectManager'; +import { replaceInFilesAndNames } from './creationHelpers'; + +// Names that cannot be used for the inner Django package: Python keywords would +// not import, 'django' or 'test' would shadow modules Django itself uses, and +// 'django_secret_key' is the placeholder the template fills with a generated key. +const RESERVED_DJANGO_PROJECT_NAMES = new Set([ + 'django', + 'django_secret_key', + 'test', + 'False', + 'None', + 'True', + 'and', + 'as', + 'assert', + 'async', + 'await', + 'break', + 'class', + 'continue', + 'def', + 'del', + 'elif', + 'else', + 'except', + 'finally', + 'for', + 'from', + 'global', + 'if', + 'import', + 'in', + 'is', + 'lambda', + 'nonlocal', + 'not', + 'or', + 'pass', + 'raise', + 'return', + 'try', + 'while', + 'with', + 'yield', +]); + +export function validateDjangoProjectName(value: string): string | null { + // The name becomes an importable Python package, so it must be a plain identifier. + if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(value)) { + return l10n.t( + 'Invalid project name. Use only letters, numbers, and underscores, and do not start with a number.', + ); + } + if (RESERVED_DJANGO_PROJECT_NAMES.has(value)) { + return l10n.t('"{0}" cannot be used as a Django project name because it conflicts with a Python name.', value); + } + return null; +} + +export class NewDjangoProject implements PythonProjectCreator { + public readonly name = l10n.t('newDjango'); + public readonly displayName = l10n.t('Django'); + public readonly description = l10n.t('Creates a Django project folder in your current workspace'); + public readonly tooltip = new MarkdownString(l10n.t('Create a new Django project')); + + constructor(private readonly projectManager: PythonProjectManager) {} + + async create(options?: PythonProjectCreatorOptions): Promise { + let projectName = options?.name; + if (!projectName) { + if (options?.quickCreate === true) { + throw new Error('Project name is required in quickCreate mode.'); + } + try { + projectName = await showInputBoxWithButtons({ + prompt: l10n.t('What is the name of the Django project? (e.g. mysite)'), + ignoreFocusOut: true, + showBackButton: true, + validateInput: validateDjangoProjectName, + }); + } catch (ex) { + if (ex === QuickInputButtons.Back) { + await commands.executeCommand('python-envs.createNewProjectFromTemplate'); + } + } + if (!projectName) { + return undefined; + } + } + const validationError = validateDjangoProjectName(projectName); + if (validationError) { + if (options?.quickCreate === true) { + throw new Error(validationError); + } + showErrorMessage(validationError); + return undefined; + } + + // 1. Check the template and the destination + const templateFolder = path.join(NEW_PROJECT_TEMPLATES_FOLDER, 'newDjangoTemplate'); + if (!(await fs.pathExists(templateFolder))) { + showErrorMessage(l10n.t('Template folder does not exist, aborting creation.')); + traceError(`Template folder not found at: ${templateFolder}`); + return undefined; + } + + let destRoot = options?.rootUri?.fsPath; + if (!destRoot) { + const workspaceFolders = getWorkspaceFolders(); + if (!workspaceFolders || workspaceFolders.length === 0) { + showErrorMessage(l10n.t('No workspace folder is open or provided, aborting creation.')); + return undefined; + } + destRoot = workspaceFolders[0].uri.fsPath; + } + + const projectDestinationFolder = path.join(destRoot, `${projectName}_project`); + if (await fs.pathExists(projectDestinationFolder)) { + showErrorMessage( + l10n.t( + 'A project folder by that name already exists, aborting creation. Please retry with a unique project name given your workspace.', + ), + ); + return undefined; + } + + // 2. Copy the template and fill in the project name and a fresh secret key + const createdProject: PythonProject = { + name: projectName, + uri: Uri.file(projectDestinationFolder), + }; + try { + await fs.copy(templateFolder, projectDestinationFolder); + await replaceInFilesAndNames(projectDestinationFolder, 'project_name', projectName); + // Hex only, so the key is safe to use as a regular expression replacement value. + const secretKey = `django-insecure-${crypto.randomBytes(25).toString('hex')}`; + await replaceInFilesAndNames(projectDestinationFolder, 'django_secret_key', secretKey); + await this.projectManager.add(createdProject); + } catch (creationError) { + try { + await fs.remove(projectDestinationFolder); + } catch (rollbackError) { + traceError('Failed to delete the new Django project after creation failed:', rollbackError); + } + throw creationError; + } + + await showTextDocument(Uri.file(path.join(projectDestinationFolder, 'manage.py'))); + + return createdProject; + } +} diff --git a/src/test/features/creators/newDjangoProject.unit.test.ts b/src/test/features/creators/newDjangoProject.unit.test.ts new file mode 100644 index 000000000..234497039 --- /dev/null +++ b/src/test/features/creators/newDjangoProject.unit.test.ts @@ -0,0 +1,204 @@ +import assert from 'assert'; +import fsExtra from 'fs-extra'; +import * as fs from 'fs-extra'; +import * as os from 'os'; +import * as path from 'path'; +import * as sinon from 'sinon'; +import { TextEditor, Uri } from 'vscode'; +import { NEW_PROJECT_TEMPLATES_FOLDER } from '../../../common/constants'; +import * as windowApis from '../../../common/window.apis'; +import * as workspaceApis from '../../../common/workspace.apis'; +import { NewDjangoProject, validateDjangoProjectName } from '../../../features/creators/newDjangoProject'; +import type { PythonProjectManager } from '../../../features/projectManager'; + +// The compiled tests run from out/, which does not contain the bundled template +// tree, so the real template is resolved from the repository root instead. +const TEMPLATE_DIR = path.join(__dirname, '..', '..', '..', '..', 'files', 'templates', 'newDjangoTemplate'); +const TEMPLATE_DIR_IN_EXTENSION = path.resolve(path.join(NEW_PROJECT_TEMPLATES_FOLDER, 'newDjangoTemplate')); + +async function listFiles(root: string): Promise { + const found: string[] = []; + for (const entry of await fs.readdir(root, { withFileTypes: true })) { + const full = path.join(root, entry.name); + if (entry.isDirectory()) { + found.push(...(await listFiles(full))); + } else { + found.push(full); + } + } + return found; +} + +suite('NewDjangoProject', () => { + let tmpDir: string; + let showTextDocumentStub: sinon.SinonStub; + + setup(async () => { + tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'new-django-test-')); + showTextDocumentStub = sinon.stub(windowApis, 'showTextDocument').resolves({} as TextEditor); + // Pretend the bundled template exists, and copy the real one when asked to. + const realPathExists = fsExtra.pathExists.bind(fsExtra); + sinon.stub(fsExtra, 'pathExists').callsFake(async (checkedPath: string) => { + if (path.resolve(String(checkedPath)) === TEMPLATE_DIR_IN_EXTENSION) { + return true; + } + return realPathExists(checkedPath); + }); + sinon.stub(fsExtra, 'copy').callsFake(async (source: string, destination: string) => { + assert.strictEqual(path.resolve(String(source)), TEMPLATE_DIR_IN_EXTENSION); + await fs.promises.cp(TEMPLATE_DIR, destination, { recursive: true }); + }); + }); + + teardown(async () => { + sinon.restore(); + await fs.remove(tmpDir); + }); + + test('validateDjangoProjectName accepts identifiers and rejects names Python cannot import', () => { + assert.strictEqual(validateDjangoProjectName('mysite'), null); + assert.strictEqual(validateDjangoProjectName('_my_site2'), null); + for (const bad of [ + '', + '1site', + 'my-site', + 'my.site', + 'my site', + 'django', + 'test', + 'class', + 'None', + 'django_secret_key', + ]) { + assert.notStrictEqual(validateDjangoProjectName(bad), null, `"${bad}" should be rejected`); + } + }); + + test('shipped template has the Django entry points and no leftover project name in file names', async () => { + const files = (await listFiles(TEMPLATE_DIR)).map((file) => path.relative(TEMPLATE_DIR, file).split(path.sep)); + const joined = files.map((parts) => parts.join('/')); + for (const expected of [ + 'manage.py', + 'requirements.txt', + 'project_name/__init__.py', + 'project_name/asgi.py', + 'project_name/settings.py', + 'project_name/urls.py', + 'project_name/wsgi.py', + ]) { + assert.ok(joined.includes(expected), `template is missing ${expected}`); + } + }); + + test('creates the project, names the package and generates a secret key', async () => { + const addStub = sinon.stub().resolves(); + const creator = new NewDjangoProject({ add: addStub } as unknown as PythonProjectManager); + + const result = await creator.create({ name: 'mysite', rootUri: Uri.file(tmpDir), quickCreate: true }); + + const projectFolder = path.join(tmpDir, 'mysite_project'); + assert.deepStrictEqual(result, { name: 'mysite', uri: Uri.file(projectFolder) }); + assert.ok(addStub.calledOnceWithExactly(result)); + assert.ok(await fs.pathExists(path.join(projectFolder, 'manage.py'))); + assert.ok(await fs.pathExists(path.join(projectFolder, 'mysite', 'settings.py'))); + assert.ok(!(await fs.pathExists(path.join(projectFolder, 'project_name')))); + + for (const file of await listFiles(projectFolder)) { + const content = await fs.readFile(file, 'utf8'); + assert.ok(!content.includes('project_name'), `${file} still contains project_name`); + assert.ok(!content.includes('django_secret_key'), `${file} still contains the key placeholder`); + } + const settings = await fs.readFile(path.join(projectFolder, 'mysite', 'settings.py'), 'utf8'); + assert.match(settings, /SECRET_KEY = "django-insecure-[0-9a-f]{50}"/); + assert.match(settings, /ROOT_URLCONF = "mysite\.urls"/); + const manage = await fs.readFile(path.join(projectFolder, 'manage.py'), 'utf8'); + assert.ok(manage.includes('"mysite.settings"')); + assert.ok(showTextDocumentStub.calledOnce); + }); + + test('each project gets its own secret key', async () => { + const creator = new NewDjangoProject({ add: sinon.stub().resolves() } as unknown as PythonProjectManager); + await creator.create({ name: 'first', rootUri: Uri.file(tmpDir), quickCreate: true }); + await creator.create({ name: 'second', rootUri: Uri.file(tmpDir), quickCreate: true }); + + const keyOf = async (name: string) => + /SECRET_KEY = "([^"]+)"/.exec( + await fs.readFile(path.join(tmpDir, `${name}_project`, name, 'settings.py'), 'utf8'), + )?.[1]; + const [first, second] = [await keyOf('first'), await keyOf('second')]; + assert.ok(first && second); + assert.notStrictEqual(first, second); + }); + + test('quickCreate without a name throws, and an invalid name throws without creating anything', async () => { + const addStub = sinon.stub().resolves(); + const creator = new NewDjangoProject({ add: addStub } as unknown as PythonProjectManager); + + await assert.rejects( + creator.create({ name: '', rootUri: Uri.file(tmpDir), quickCreate: true }), + /name is required/, + ); + await assert.rejects( + creator.create({ name: 'my-site', rootUri: Uri.file(tmpDir), quickCreate: true }), + /Invalid project name/, + ); + assert.ok(addStub.notCalled); + assert.deepStrictEqual(await fs.readdir(tmpDir), []); + }); + + test('does not overwrite an existing project folder', async () => { + const showErrorMessageStub = sinon.stub(windowApis, 'showErrorMessage'); + const addStub = sinon.stub().resolves(); + await fs.ensureDir(path.join(tmpDir, 'mysite_project')); + const creator = new NewDjangoProject({ add: addStub } as unknown as PythonProjectManager); + + const result = await creator.create({ name: 'mysite', rootUri: Uri.file(tmpDir), quickCreate: true }); + + assert.strictEqual(result, undefined); + assert.ok(addStub.notCalled); + assert.ok(showErrorMessageStub.calledOnce); + assert.match(String(showErrorMessageStub.firstCall.args[0]), /already exists/); + assert.deepStrictEqual(await fs.readdir(path.join(tmpDir, 'mysite_project')), []); + }); + + test('removes the half-created folder and rethrows when registering the project fails', async () => { + const addStub = sinon.stub().rejects(new Error('cannot register')); + const creator = new NewDjangoProject({ add: addStub } as unknown as PythonProjectManager); + + await assert.rejects( + creator.create({ name: 'mysite', rootUri: Uri.file(tmpDir), quickCreate: true }), + /cannot register/, + ); + + assert.ok(!(await fs.pathExists(path.join(tmpDir, 'mysite_project')))); + assert.ok(showTextDocumentStub.notCalled); + }); + + test('falls back to the first workspace folder and prompts for the name when none is given', async () => { + sinon.stub(workspaceApis, 'getWorkspaceFolders').returns([{ index: 0, name: 'ws', uri: Uri.file(tmpDir) }]); + const promptStub = sinon.stub(windowApis, 'showInputBoxWithButtons').resolves('prompted'); + const addStub = sinon.stub().resolves(); + const creator = new NewDjangoProject({ add: addStub } as unknown as PythonProjectManager); + + const result = await creator.create({ name: '', rootUri: undefined as unknown as Uri }); + + assert.ok(promptStub.calledOnce); + const validateInput = promptStub.firstCall.args[0]?.validateInput; + assert.ok(validateInput); + assert.notStrictEqual(validateInput('1bad'), null); + assert.deepStrictEqual(result, { + name: 'prompted', + uri: Uri.file(path.join(tmpDir, 'prompted_project')), + }); + assert.ok(await fs.pathExists(path.join(tmpDir, 'prompted_project', 'prompted', 'urls.py'))); + }); + + test('returns undefined when the name prompt is dismissed', async () => { + sinon.stub(windowApis, 'showInputBoxWithButtons').resolves(undefined); + const addStub = sinon.stub().resolves(); + const creator = new NewDjangoProject({ add: addStub } as unknown as PythonProjectManager); + + assert.strictEqual(await creator.create({ name: '', rootUri: Uri.file(tmpDir) }), undefined); + assert.ok(addStub.notCalled); + }); +});