mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Remove ApiWrapper from notebook extension (#11224)
* Remove ApiWrapper in notebook extension * delete file * Remove copyrights
This commit is contained in:
@@ -15,8 +15,6 @@ import { BookTreeItem, BookTreeItemType } from '../../book/bookTreeItem';
|
||||
import { promisify } from 'util';
|
||||
import { MockExtensionContext } from '../common/stubs';
|
||||
import { exists } from '../../common/utils';
|
||||
import { AppContext } from '../../common/appContext';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { BookModel } from '../../book/bookModel';
|
||||
import { BookTrustManager } from '../../book/bookTrustManager';
|
||||
import { NavigationProviders } from '../../common/constants';
|
||||
@@ -56,7 +54,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
let expectedMarkdown: IExpectedBookItem;
|
||||
let expectedExternalLink: IExpectedBookItem;
|
||||
let expectedBook: IExpectedBookItem;
|
||||
let appContext: AppContext;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
mockExtensionContext = new MockExtensionContext();
|
||||
@@ -103,7 +100,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
sections: [expectedNotebook1, expectedMarkdown, expectedExternalLink],
|
||||
title: 'Test Book'
|
||||
};
|
||||
appContext = new AppContext(mockExtensionContext, new ApiWrapper());
|
||||
|
||||
await fs.mkdir(rootFolderPath);
|
||||
await fs.mkdir(bookFolderPath);
|
||||
@@ -116,11 +112,10 @@ describe('BookTreeViewProviderTests', function () {
|
||||
await fs.writeFile(notebook2File, '');
|
||||
await fs.writeFile(notebook3File, '');
|
||||
await fs.writeFile(markdownFile, '');
|
||||
appContext = new AppContext(undefined, new ApiWrapper());
|
||||
});
|
||||
|
||||
it('should initialize correctly with empty workspace array', async () => {
|
||||
const bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
const bookTreeViewProvider = new BookTreeViewProvider([], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
await bookTreeViewProvider.initialized;
|
||||
});
|
||||
|
||||
@@ -130,7 +125,7 @@ describe('BookTreeViewProviderTests', function () {
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
const bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
const bookTreeViewProvider = new BookTreeViewProvider([folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
await bookTreeViewProvider.initialized;
|
||||
});
|
||||
|
||||
@@ -145,7 +140,7 @@ describe('BookTreeViewProviderTests', function () {
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
const bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [book, nonBook], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
const bookTreeViewProvider = new BookTreeViewProvider([book, nonBook], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
await bookTreeViewProvider.initialized;
|
||||
should(bookTreeViewProvider.books.length).equal(1, 'Expected book was not initialized');
|
||||
});
|
||||
@@ -162,8 +157,8 @@ describe('BookTreeViewProviderTests', function () {
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
providedbookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [], mockExtensionContext, true, 'providedBooksView', NavigationProviders.ProvidedBooksNavigator);
|
||||
bookTreeViewProvider = new BookTreeViewProvider([folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
providedbookTreeViewProvider = new BookTreeViewProvider([], mockExtensionContext, true, 'providedBooksView', NavigationProviders.ProvidedBooksNavigator);
|
||||
let errorCase = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||
await Promise.race([providedbookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('ProvidedBooksTreeViewProvider did not initialize in time'); })]);
|
||||
@@ -202,7 +197,7 @@ describe('BookTreeViewProviderTests', function () {
|
||||
|
||||
it('bookTreeViewProvider should set notebooks trusted to true on trustBook', async () => {
|
||||
let notebook1Path = path.join(rootFolderPath, 'Book', 'content', 'notebook1.ipynb');
|
||||
let bookTrustManager: BookTrustManager = new BookTrustManager(bookTreeViewProvider.books, appContext.apiWrapper);
|
||||
let bookTrustManager: BookTrustManager = new BookTrustManager(bookTreeViewProvider.books);
|
||||
let isTrusted = bookTrustManager.isNotebookTrustedByDefault(vscode.Uri.file(notebook1Path).fsPath);
|
||||
should(isTrusted).equal(false, 'Notebook should not be trusted by default');
|
||||
|
||||
@@ -280,7 +275,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
let tableOfContentsFile: string;
|
||||
let bookTreeViewProvider: BookTreeViewProvider;
|
||||
let folder: vscode.WorkspaceFolder;
|
||||
let appContext: AppContext;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||
@@ -297,11 +291,9 @@ describe('BookTreeViewProviderTests', function () {
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
appContext = new AppContext(mockExtensionContext, new ApiWrapper());
|
||||
bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
bookTreeViewProvider = new BookTreeViewProvider([folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
let errorCase = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||
appContext = new AppContext(undefined, new ApiWrapper());
|
||||
});
|
||||
|
||||
it('should ignore toc.yml files not in _data folder', async () => {
|
||||
@@ -324,7 +316,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
let folder: vscode.WorkspaceFolder;
|
||||
let bookTreeViewProvider: BookTreeViewProvider;
|
||||
let tocFile: string;
|
||||
let appContext: AppContext;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||
@@ -340,11 +331,9 @@ describe('BookTreeViewProviderTests', function () {
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
appContext = new AppContext(mockExtensionContext, new ApiWrapper());
|
||||
bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
bookTreeViewProvider = new BookTreeViewProvider([folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
let errorCase = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||
appContext = new AppContext(undefined, new ApiWrapper());
|
||||
});
|
||||
|
||||
it('should show error message if config.yml file not found', async () => {
|
||||
@@ -372,7 +361,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
let bookTreeViewProvider: BookTreeViewProvider;
|
||||
let folder: vscode.WorkspaceFolder;
|
||||
let expectedNotebook2: IExpectedBookItem;
|
||||
let appContext: AppContext;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||
@@ -400,11 +388,9 @@ describe('BookTreeViewProviderTests', function () {
|
||||
name: '',
|
||||
index: 0
|
||||
};
|
||||
appContext = new AppContext(mockExtensionContext, new ApiWrapper());
|
||||
bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
bookTreeViewProvider = new BookTreeViewProvider([folder], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
let errorCase = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||
appContext = new AppContext(undefined, new ApiWrapper());
|
||||
});
|
||||
|
||||
it('should show error if notebook or markdown file is missing', async function (): Promise<void> {
|
||||
@@ -426,7 +412,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
let rootFolderPath: string;
|
||||
let tableOfContentsFile: string;
|
||||
let bookTreeViewProvider: BookTreeViewProvider;
|
||||
let appContext: AppContext;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
rootFolderPath = path.join(os.tmpdir(), `BookTestData_${uuid.v4()}`);
|
||||
@@ -443,11 +428,9 @@ describe('BookTreeViewProviderTests', function () {
|
||||
await fs.writeFile(notebook2File, '');
|
||||
|
||||
const mockExtensionContext = new MockExtensionContext();
|
||||
appContext = new AppContext(mockExtensionContext, new ApiWrapper());
|
||||
bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
bookTreeViewProvider = new BookTreeViewProvider([], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
let errorCase = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||
appContext = new AppContext(undefined, new ApiWrapper());
|
||||
});
|
||||
|
||||
it('should add book and initialize book on openBook', async () => {
|
||||
@@ -502,7 +485,6 @@ describe('BookTreeViewProviderTests', function () {
|
||||
let standaloneNotebookTitle: string;
|
||||
let standaloneNotebookFile: string;
|
||||
let bookTreeViewProvider: BookTreeViewProvider;
|
||||
let appContext: AppContext;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
rootFolderPath = path.join(os.tmpdir(), `BookFolderTest_${uuid.v4()}`);
|
||||
@@ -527,11 +509,9 @@ describe('BookTreeViewProviderTests', function () {
|
||||
await fs.writeFile(standaloneNotebookFile, '');
|
||||
|
||||
const mockExtensionContext = new MockExtensionContext();
|
||||
appContext = new AppContext(mockExtensionContext, new ApiWrapper());
|
||||
bookTreeViewProvider = new BookTreeViewProvider(appContext.apiWrapper, [], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
bookTreeViewProvider = new BookTreeViewProvider([], mockExtensionContext, false, 'bookTreeView', NavigationProviders.NotebooksNavigator);
|
||||
let errorCase = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
||||
await Promise.race([bookTreeViewProvider.initialized, errorCase.then(() => { throw new Error('BookTreeViewProvider did not initialize in time'); })]);
|
||||
appContext = new AppContext(undefined, new ApiWrapper());
|
||||
});
|
||||
|
||||
it('should include books and notebooks when opening parent folder', async () => {
|
||||
|
||||
@@ -9,9 +9,9 @@ import * as TypeMoq from 'typemoq';
|
||||
import * as constants from '../../common/constants';
|
||||
import { IBookTrustManager, BookTrustManager } from '../../book/bookTrustManager';
|
||||
import { BookTreeItem, BookTreeItemFormat, BookTreeItemType } from '../../book/bookTreeItem';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { WorkspaceConfiguration, ConfigurationTarget } from 'vscode';
|
||||
import * as vscode from 'vscode';
|
||||
import { BookModel } from '../../book/bookModel';
|
||||
import * as sinon from 'sinon';
|
||||
|
||||
describe('BookTrustManagerTests', function () {
|
||||
|
||||
@@ -20,36 +20,36 @@ describe('BookTrustManagerTests', function () {
|
||||
let trustedSubFolders: string[];
|
||||
let books: BookModel[];
|
||||
|
||||
afterEach(function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
trustedSubFolders = ['/SubFolder/'];
|
||||
|
||||
// Mock Workspace Configuration
|
||||
let workspaceConfigurtionMock: TypeMoq.IMock<WorkspaceConfiguration> = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
|
||||
let workspaceConfigurtionMock: TypeMoq.IMock<vscode.WorkspaceConfiguration> = TypeMoq.Mock.ofType<vscode.WorkspaceConfiguration>();
|
||||
workspaceConfigurtionMock.setup(config => config.get(TypeMoq.It.isValue(constants.trustedBooksConfigKey))).returns(() => [].concat(trustedSubFolders));
|
||||
workspaceConfigurtionMock.setup(config => config.update(TypeMoq.It.isValue(constants.trustedBooksConfigKey), TypeMoq.It.isAny(), TypeMoq.It.isValue(false))).returns((key: string, newValues: string[]) => {
|
||||
trustedSubFolders.splice(0, trustedSubFolders.length, ...newValues); // Replace
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
// Mock Api Wrapper
|
||||
let apiWrapperMock: TypeMoq.IMock<ApiWrapper> = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
|
||||
apiWrapperMock.setup(api => api.getWorkspaceFolders()).returns(() => [
|
||||
{
|
||||
// @ts-ignore - Don't need all URI properties for this tests
|
||||
sinon.replaceGetter(vscode.workspace, 'workspaceFolders', () => {
|
||||
return <vscode.WorkspaceFolder[]>[{
|
||||
uri: {
|
||||
fsPath: '/temp/'
|
||||
},
|
||||
},
|
||||
{
|
||||
// @ts-ignore - Don't need all URI properties for this tests
|
||||
uri: {
|
||||
fsPath: '/temp2/'
|
||||
}
|
||||
},
|
||||
]);
|
||||
];
|
||||
});
|
||||
|
||||
apiWrapperMock.setup(api => api.getConfiguration(TypeMoq.It.isValue(constants.notebookConfigKey))).returns(() => workspaceConfigurtionMock.object);
|
||||
sinon.stub(vscode.workspace, 'getConfiguration').returns(workspaceConfigurtionMock.object);
|
||||
|
||||
// Mock Book Data
|
||||
let bookTreeItemFormat1: BookTreeItemFormat = {
|
||||
@@ -108,24 +108,24 @@ describe('BookTrustManagerTests', function () {
|
||||
|
||||
let bookModel1Mock: TypeMoq.IMock<BookModel> = TypeMoq.Mock.ofType<BookModel>();
|
||||
bookModel1Mock.setup(model => model.bookItems).returns(() => [new BookTreeItem(bookTreeItemFormat1, undefined), new BookTreeItem(bookTreeItemFormat2, undefined)]);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder','content','sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder','content','sample', 'notebook2.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder2','content','sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook2.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isAnyString())).returns((uri: string) => undefined);
|
||||
|
||||
let bookModel2Mock: TypeMoq.IMock<BookModel> = TypeMoq.Mock.ofType<BookModel>();
|
||||
bookModel2Mock.setup(model => model.bookItems).returns(() => [new BookTreeItem(bookTreeItemFormat3, undefined)]);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp2','SubFolder','content','sample','notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp2', 'SubFolder', 'content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isAnyString())).returns((uri: string) => undefined);
|
||||
|
||||
books = [bookModel1Mock.object, bookModel2Mock.object];
|
||||
|
||||
bookTrustManager = new BookTrustManager(books, apiWrapperMock.object);
|
||||
bookTrustManager = new BookTrustManager(books);
|
||||
});
|
||||
|
||||
it('should trust notebooks in a trusted book within a workspace', async () => {
|
||||
let notebookUri1 = path.join(path.sep,'temp','SubFolder','content','sample', 'notebook.ipynb');
|
||||
let notebookUri2 = path.join(path.sep,'temp','SubFolder','content','sample', 'notebook2.ipynb');
|
||||
let notebookUri1 = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri2 = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook2.ipynb');
|
||||
|
||||
let isNotebook1Trusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri1);
|
||||
let isNotebook2Trusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri2);
|
||||
@@ -136,14 +136,14 @@ describe('BookTrustManagerTests', function () {
|
||||
});
|
||||
|
||||
it('should NOT trust a notebook in an untrusted book within a workspace', async () => {
|
||||
let notebookUri = path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook.ipynb');
|
||||
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrusted).be.false('Notebook should be trusted');
|
||||
});
|
||||
|
||||
it('should trust notebook after book has been trusted within a workspace', async () => {
|
||||
let notebookUri = path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook.ipynb');
|
||||
let isNotebookTrustedBeforeChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted');
|
||||
@@ -157,7 +157,7 @@ describe('BookTrustManagerTests', function () {
|
||||
});
|
||||
|
||||
it('should NOT trust a notebook when untrusting a book within a workspace', async () => {
|
||||
let notebookUri = path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook.ipynb');
|
||||
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrusted).be.true('Notebook should be trusted');
|
||||
@@ -195,19 +195,13 @@ describe('BookTrustManagerTests', function () {
|
||||
|
||||
beforeEach(() => {
|
||||
// Mock Workspace Configuration
|
||||
let workspaceConfigurtionMock: TypeMoq.IMock<WorkspaceConfiguration> = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
|
||||
let workspaceConfigurtionMock: TypeMoq.IMock<vscode.WorkspaceConfiguration> = TypeMoq.Mock.ofType<vscode.WorkspaceConfiguration>();
|
||||
workspaceConfigurtionMock.setup(config => config.get(TypeMoq.It.isValue(constants.trustedBooksConfigKey))).returns(() => [].concat(trustedFolders));
|
||||
workspaceConfigurtionMock.setup(config => config.update(TypeMoq.It.isValue(constants.trustedBooksConfigKey), TypeMoq.It.isAny(), TypeMoq.It.isValue(ConfigurationTarget.Global))).returns((key: string, newValues: string[], target: ConfigurationTarget) => {
|
||||
workspaceConfigurtionMock.setup(config => config.update(TypeMoq.It.isValue(constants.trustedBooksConfigKey), TypeMoq.It.isAny(), TypeMoq.It.isValue(vscode.ConfigurationTarget.Global))).returns((key: string, newValues: string[], target: vscode.ConfigurationTarget) => {
|
||||
trustedFolders.splice(0, trustedFolders.length, ...newValues); // Replace
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
|
||||
// Mock Api Wrapper
|
||||
let apiWrapperMock: TypeMoq.IMock<ApiWrapper> = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
|
||||
apiWrapperMock.setup(api => api.getWorkspaceFolders()).returns(() => []);
|
||||
apiWrapperMock.setup(api => api.getConfiguration(TypeMoq.It.isValue(constants.notebookConfigKey))).returns(() => workspaceConfigurtionMock.object);
|
||||
let bookTreeItemFormat1: BookTreeItemFormat = {
|
||||
contentPath: undefined,
|
||||
root: '/temp/SubFolder/',
|
||||
@@ -250,26 +244,26 @@ describe('BookTrustManagerTests', function () {
|
||||
|
||||
let bookModel1Mock: TypeMoq.IMock<BookModel> = TypeMoq.Mock.ofType<BookModel>();
|
||||
bookModel1Mock.setup(model => model.bookItems).returns(() => [new BookTreeItem(bookTreeItemFormat1, undefined)]);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook2.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook2.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel1Mock.setup(model => model.getNotebook(TypeMoq.It.isAnyString())).returns((uri: string) => undefined);
|
||||
|
||||
let bookModel2Mock: TypeMoq.IMock<BookModel> = TypeMoq.Mock.ofType<BookModel>();
|
||||
bookModel2Mock.setup(model => model.bookItems).returns(() => [new BookTreeItem(bookTreeItemFormat2, undefined)]);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook2.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isValue(path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook2.ipynb')))).returns((uri: string) => TypeMoq.Mock.ofType<BookTreeItem>().object);
|
||||
bookModel2Mock.setup(model => model.getNotebook(TypeMoq.It.isAnyString())).returns((uri: string) => undefined);
|
||||
|
||||
books = [bookModel1Mock.object, bookModel2Mock.object];
|
||||
|
||||
bookTrustManager = new BookTrustManager(books, apiWrapperMock.object);
|
||||
bookTrustManager = new BookTrustManager(books);
|
||||
});
|
||||
|
||||
it('should trust notebooks in a trusted book in a folder', async () => {
|
||||
bookTrustManager.setBookAsTrusted('/temp/SubFolder/');
|
||||
|
||||
let notebookUri1 = path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri2 = path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook2.ipynb');
|
||||
let notebookUri1 = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri2 = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook2.ipynb');
|
||||
|
||||
let isNotebook1Trusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri1);
|
||||
let isNotebook2Trusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri2);
|
||||
@@ -280,14 +274,14 @@ describe('BookTrustManagerTests', function () {
|
||||
});
|
||||
|
||||
it('should NOT trust a notebook in an untrusted book in a folder', async () => {
|
||||
let notebookUri = path.join(path.sep,'temp','SubFolder2','content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook.ipynb');
|
||||
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrusted).be.false('Notebook should be trusted');
|
||||
});
|
||||
|
||||
it('should trust notebook after book has been added to a folder', async () => {
|
||||
let notebookUri = path.join(path.sep,'temp','SubFolder2','content', 'sample','notebook.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder2', 'content', 'sample', 'notebook.ipynb');
|
||||
let isNotebookTrustedBeforeChange = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrustedBeforeChange).be.false('Notebook should NOT be trusted');
|
||||
@@ -301,7 +295,7 @@ describe('BookTrustManagerTests', function () {
|
||||
|
||||
it('should NOT trust a notebook when untrusting a book in folder', async () => {
|
||||
bookTrustManager.setBookAsTrusted('/temp/SubFolder/');
|
||||
let notebookUri = path.join(path.sep,'temp','SubFolder','content', 'sample', 'notebook.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notebook.ipynb');
|
||||
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrusted).be.true('Notebook should be trusted');
|
||||
@@ -323,7 +317,7 @@ describe('BookTrustManagerTests', function () {
|
||||
it('should NOT trust notebook inside trusted subfolder when absent in table of contents ', async () => {
|
||||
bookTrustManager.setBookAsTrusted('/temp/SubFolder/');
|
||||
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notInToc.ipynb');
|
||||
let notebookUri = path.join(path.sep, 'temp', 'SubFolder', 'content', 'sample', 'notInToc.ipynb');
|
||||
let isNotebookTrusted = bookTrustManager.isNotebookTrustedByDefault(notebookUri);
|
||||
|
||||
should(isNotebookTrusted).be.false('Notebook should NOT be trusted');
|
||||
|
||||
@@ -8,25 +8,24 @@ import { NotebookUtils } from '../../common/notebookUtils';
|
||||
import * as should from 'should';
|
||||
import * as vscode from 'vscode';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as sinon from 'sinon';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as uuid from 'uuid';
|
||||
import { promises as fs } from 'fs';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { tryDeleteFile } from './testUtils';
|
||||
import { CellTypes } from '../../contracts/content';
|
||||
|
||||
describe('notebookUtils Tests', function (): void {
|
||||
let notebookUtils: NotebookUtils;
|
||||
let apiWrapperMock: TypeMoq.IMock<ApiWrapper>;
|
||||
let notebookUtils: NotebookUtils = new NotebookUtils();
|
||||
let showErrorMessageSpy: sinon.SinonSpy;
|
||||
|
||||
this.beforeAll(async function(): Promise<void> {
|
||||
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||
beforeEach(function(): void {
|
||||
showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
});
|
||||
|
||||
beforeEach(function (): void {
|
||||
apiWrapperMock = TypeMoq.Mock.ofInstance(new ApiWrapper());
|
||||
notebookUtils = new NotebookUtils(apiWrapperMock.object);
|
||||
afterEach(function(): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
this.afterAll(async function (): Promise<void> {
|
||||
@@ -74,7 +73,7 @@ describe('notebookUtils Tests', function (): void {
|
||||
const notebookUri = vscode.Uri.file(notebookPath);
|
||||
try {
|
||||
await fs.writeFile(notebookPath, '');
|
||||
apiWrapperMock.setup(x => x.showOpenDialog(TypeMoq.It.isAny())).returns(() => Promise.resolve([notebookUri]));
|
||||
sinon.stub(vscode.window, 'showOpenDialog').returns(Promise.resolve([notebookUri]));
|
||||
await notebookUtils.openNotebook();
|
||||
should(azdata.nb.notebookDocuments.find(doc => doc.fileName === notebookUri.fsPath)).not.be.undefined();
|
||||
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
|
||||
@@ -84,88 +83,86 @@ describe('notebookUtils Tests', function (): void {
|
||||
});
|
||||
|
||||
it('shows error if unexpected error is thrown', async function (): Promise<void> {
|
||||
apiWrapperMock.setup(x => x.showOpenDialog(TypeMoq.It.isAny())).throws(new Error('Unexpected error'));
|
||||
apiWrapperMock.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns(() => Promise.resolve(''));
|
||||
sinon.stub(vscode.window, 'showOpenDialog').throws(new Error('Unexpected error'));
|
||||
await notebookUtils.openNotebook();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should have been called');
|
||||
});
|
||||
});
|
||||
|
||||
describe('runActiveCell', function () {
|
||||
it('shows error when no notebook visible', async function (): Promise<void> {
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => undefined);
|
||||
await notebookUtils.runActiveCell();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should have been called');
|
||||
});
|
||||
|
||||
it('does not show error when notebook visible', async function (): Promise<void> {
|
||||
let mockNotebookEditor = TypeMoq.Mock.ofType<azdata.nb.NotebookEditor>();
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => mockNotebookEditor.object);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => mockNotebookEditor.object);
|
||||
await notebookUtils.runActiveCell();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not have been called');
|
||||
mockNotebookEditor.verify(x => x.runCell(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
});
|
||||
|
||||
describe('clearActiveCellOutput', function () {
|
||||
it('shows error when no notebook visible', async function (): Promise<void> {
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => undefined);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => undefined);
|
||||
await notebookUtils.clearActiveCellOutput();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should be called exactly once');
|
||||
});
|
||||
|
||||
it('does not show error when notebook visible', async function (): Promise<void> {
|
||||
let mockNotebookEditor = TypeMoq.Mock.ofType<azdata.nb.NotebookEditor>();
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => mockNotebookEditor.object);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => mockNotebookEditor.object);
|
||||
await notebookUtils.clearActiveCellOutput();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not have been called');
|
||||
mockNotebookEditor.verify(x => x.clearOutput(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
});
|
||||
|
||||
describe('runAllCells', function () {
|
||||
it('shows error when no notebook visible', async function (): Promise<void> {
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => undefined);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => undefined);
|
||||
await notebookUtils.runAllCells();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should be called exactly once');
|
||||
});
|
||||
|
||||
it('does not show error when notebook visible', async function (): Promise<void> {
|
||||
let mockNotebookEditor = TypeMoq.Mock.ofType<azdata.nb.NotebookEditor>();
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => mockNotebookEditor.object);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => mockNotebookEditor.object);
|
||||
await notebookUtils.runAllCells();
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not have been called');
|
||||
mockNotebookEditor.verify(x => x.runAllCells(TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
});
|
||||
|
||||
describe('addCell', function () {
|
||||
it('shows error when no notebook visible for code cell', async function (): Promise<void> {
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => undefined);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => undefined);
|
||||
await notebookUtils.addCell('code');
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should be called exactly once');
|
||||
});
|
||||
|
||||
it('shows error when no notebook visible for markdown cell', async function (): Promise<void> {
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => undefined);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => undefined);
|
||||
await notebookUtils.addCell('markdown');
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should be called exactly once');
|
||||
});
|
||||
|
||||
it('does not show error when notebook visible for code cell', async function (): Promise<void> {
|
||||
const notebookEditor = await notebookUtils.newNotebook(undefined);
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => notebookEditor);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => notebookEditor);
|
||||
await notebookUtils.addCell('code');
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should never be called');
|
||||
should(notebookEditor.document.cells.length).equal(1);
|
||||
should(notebookEditor.document.cells[0].contents.cell_type).equal(CellTypes.Code);
|
||||
});
|
||||
|
||||
it('does not show error when notebook visible for markdown cell', async function (): Promise<void> {
|
||||
const notebookEditor = await notebookUtils.newNotebook(undefined);
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => notebookEditor);
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => notebookEditor);
|
||||
await notebookUtils.addCell('markdown');
|
||||
apiWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should never be called');
|
||||
should(notebookEditor.document.cells.length).equal(1);
|
||||
should(notebookEditor.document.cells[0].contents.cell_type).equal(CellTypes.Markdown);
|
||||
});
|
||||
@@ -174,8 +171,8 @@ describe('notebookUtils Tests', function (): void {
|
||||
describe('analyzeNotebook', function () {
|
||||
it('creates cell when oeContext exists', async function (): Promise<void> {
|
||||
const notebookEditor = await notebookUtils.newNotebook(undefined);
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => notebookEditor);
|
||||
apiWrapperMock.setup(x => x.showNotebookDocument(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(notebookEditor));
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => notebookEditor);
|
||||
sinon.stub(azdata.nb, 'showNotebookDocument').returns(Promise.resolve(notebookEditor));
|
||||
const oeContext: azdata.ObjectExplorerContext = {
|
||||
connectionProfile: undefined,
|
||||
isConnectionNode: true,
|
||||
@@ -197,8 +194,8 @@ describe('notebookUtils Tests', function (): void {
|
||||
|
||||
it('does not create new cell when oeContext does not exist', async function (): Promise<void> {
|
||||
const notebookEditor = await notebookUtils.newNotebook(undefined);
|
||||
apiWrapperMock.setup(x => x.getActiveNotebookEditor()).returns(() => notebookEditor);
|
||||
apiWrapperMock.setup(x => x.showNotebookDocument(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(notebookEditor));
|
||||
sinon.replaceGetter(azdata.nb, 'activeNotebookEditor', () => notebookEditor);
|
||||
sinon.stub(azdata.nb, 'showNotebookDocument').returns(Promise.resolve(notebookEditor));
|
||||
await notebookUtils.analyzeNotebook();
|
||||
should(notebookEditor.document.cells.length).equal(0, 'No cells should exist');
|
||||
});
|
||||
|
||||
@@ -3,47 +3,51 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as should from 'should';
|
||||
import * as sinon from 'sinon';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import { IPrompter, confirm, IQuestion } from '../../prompts/question';
|
||||
import CodeAdapter from '../../prompts/adapter';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
|
||||
|
||||
describe('Prompt', () => {
|
||||
|
||||
let prompter: IPrompter;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
|
||||
let showErrorMessageSpy: sinon.SinonSpy;
|
||||
|
||||
before(function () {
|
||||
prompter = new CodeAdapter();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
mockApiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny()));
|
||||
beforeEach(function(): void {
|
||||
showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should not find prompt for invalid question type', async function (): Promise<void> {
|
||||
const showQuickPickSpy = sinon.spy(vscode.window, 'showQuickPick');
|
||||
await prompter.promptSingle<boolean>(<IQuestion>{
|
||||
type: 'invalidType',
|
||||
message: 'sample message',
|
||||
default: false
|
||||
}, mockApiWrapper.object);
|
||||
mockApiWrapper.verify(s => s.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
mockApiWrapper.verify(s => s.showQuickPick(TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
});
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should be called exactly once');
|
||||
should(showQuickPickSpy.notCalled).be.true('showQuickPick should never have been called');
|
||||
});
|
||||
|
||||
it('Should find prompt for confirm type', async function (): Promise<void> {
|
||||
mockApiWrapper.setup(x => x.showQuickPick(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve('Yes'));
|
||||
const quickPickSpy = sinon.stub(vscode.window, 'showQuickPick').returns(Promise.resolve('Yes') as any);
|
||||
await prompter.promptSingle<boolean>(<IQuestion>{
|
||||
type: confirm,
|
||||
message: 'sample message',
|
||||
default: false
|
||||
}, mockApiWrapper.object);
|
||||
mockApiWrapper.verify(s => s.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
mockApiWrapper.verify(s => s.showQuickPick(TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should never be called');
|
||||
should(quickPickSpy.calledOnce).be.true('showQuickPick should have been called once');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import { ConfigurePythonWizard, ConfigurePythonModel } from '../dialog/configurePython/configurePythonWizard';
|
||||
import { JupyterServerInstallation } from '../jupyter/jupyterServerInstallation';
|
||||
import { ConfigurePathPage } from '../dialog/configurePython/configurePathPage';
|
||||
@@ -16,7 +15,6 @@ import { TestContext, createViewContext, TestButton } from './common';
|
||||
import { EventEmitter } from 'vscode';
|
||||
|
||||
describe('Configure Python Wizard', function () {
|
||||
let apiWrapper: ApiWrapper = new ApiWrapper();
|
||||
let testWizard: ConfigurePythonWizard;
|
||||
let viewContext: TestContext;
|
||||
let testInstallation: JupyterServerInstallation;
|
||||
@@ -45,21 +43,21 @@ describe('Configure Python Wizard', function () {
|
||||
// These wizard tests are disabled due to errors with disposable objects
|
||||
//
|
||||
// it('Start wizard test', async () => {
|
||||
// let wizard = new ConfigurePythonWizard(apiWrapper, testInstallation);
|
||||
// let wizard = new ConfigurePythonWizard(testInstallation);
|
||||
// await wizard.start();
|
||||
// await wizard.close();
|
||||
// await should(wizard.setupComplete).be.resolved();
|
||||
// });
|
||||
|
||||
// it('Reject setup on cancel test', async () => {
|
||||
// let wizard = new ConfigurePythonWizard(apiWrapper, testInstallation);
|
||||
// let wizard = new ConfigurePythonWizard(testInstallation);
|
||||
// await wizard.start(undefined, true);
|
||||
// await wizard.close();
|
||||
// await should(wizard.setupComplete).be.rejected();
|
||||
// });
|
||||
|
||||
// it('Error message test', async () => {
|
||||
// let wizard = new ConfigurePythonWizard(apiWrapper, testInstallation);
|
||||
// let wizard = new ConfigurePythonWizard(testInstallation);
|
||||
// await wizard.start();
|
||||
|
||||
// should(wizard.wizard.message).be.undefined();
|
||||
@@ -86,7 +84,7 @@ describe('Configure Python Wizard', function () {
|
||||
};
|
||||
|
||||
let page = azdata.window.createWizardPage('Page 1');
|
||||
let configurePathPage = new ConfigurePathPage(apiWrapper, testWizard, page, model, viewContext.view);
|
||||
let configurePathPage = new ConfigurePathPage(testWizard, page, model, viewContext.view);
|
||||
|
||||
should(await configurePathPage.initialize()).be.true();
|
||||
|
||||
@@ -108,7 +106,7 @@ describe('Configure Python Wizard', function () {
|
||||
};
|
||||
|
||||
let page = azdata.window.createWizardPage('Page 2');
|
||||
let pickPackagesPage = new PickPackagesPage(apiWrapper, testWizard, page, model, viewContext.view);
|
||||
let pickPackagesPage = new PickPackagesPage(testWizard, page, model, viewContext.view);
|
||||
|
||||
should(await pickPackagesPage.initialize()).be.true();
|
||||
|
||||
@@ -132,7 +130,7 @@ describe('Configure Python Wizard', function () {
|
||||
};
|
||||
|
||||
let page = azdata.window.createWizardPage('Page 2');
|
||||
let pickPackagesPage = new PickPackagesPage(apiWrapper, testWizard, page, model, viewContext.view);
|
||||
let pickPackagesPage = new PickPackagesPage(testWizard, page, model, viewContext.view);
|
||||
|
||||
should(await pickPackagesPage.initialize()).be.true();
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as should from 'should';
|
||||
import { ManagePackagesDialog } from '../../dialog/managePackages/managePackagesDialog';
|
||||
import { ManagePackagesDialogModel } from '../../dialog/managePackages/managePackagesDialogModel';
|
||||
import { IPackageManageProvider, IPackageLocation } from '../../types';
|
||||
import { LocalCondaPackageManageProvider } from '../../jupyter/localCondaPackageManageProvider';
|
||||
import { InstalledPackagesTab } from '../../dialog/managePackages/installedPackagesTab';
|
||||
import should = require('should');
|
||||
|
||||
interface TestContext {
|
||||
view: azdata.ModelView;
|
||||
|
||||
@@ -19,7 +19,7 @@ interface TestContext {
|
||||
describe('Manage Packages', () => {
|
||||
let jupyterServerInstallation: JupyterServerInstallation;
|
||||
beforeEach(() => {
|
||||
jupyterServerInstallation = new JupyterServerInstallation(undefined, undefined, undefined);
|
||||
jupyterServerInstallation = new JupyterServerInstallation(undefined, undefined);
|
||||
});
|
||||
|
||||
it('Should throw exception given undefined providers', async function (): Promise<void> {
|
||||
|
||||
@@ -11,7 +11,6 @@ import * as TypeMoq from 'typemoq';
|
||||
import { NotebookCompletionItemProvider } from '../../intellisense/completionItemProvider';
|
||||
import { JupyterNotebookProvider } from '../../jupyter/jupyterNotebookProvider';
|
||||
import { NotebookUtils } from '../../common/notebookUtils';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { JupyterNotebookManager } from '../../jupyter/jupyterNotebookManager';
|
||||
import { JupyterSessionManager, JupyterSession } from '../../jupyter/jupyterSessionManager';
|
||||
import { LocalJupyterServerManager } from '../../jupyter/jupyterServerManager';
|
||||
@@ -22,7 +21,6 @@ describe('Completion Item Provider', function () {
|
||||
let notebookProviderMock: TypeMoq.IMock<JupyterNotebookProvider>;
|
||||
let notebookUtils: NotebookUtils;
|
||||
let notebookManager: JupyterNotebookManager;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
let mockSessionManager: TypeMoq.IMock<JupyterSessionManager>;
|
||||
let mockServerManager: TypeMoq.IMock<LocalJupyterServerManager>;
|
||||
let mockJupyterSession: TypeMoq.IMock<JupyterSession>;
|
||||
@@ -31,8 +29,7 @@ describe('Completion Item Provider', function () {
|
||||
let token: vscode.CancellationToken;
|
||||
|
||||
this.beforeAll(async () => {
|
||||
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
notebookUtils = new NotebookUtils(new ApiWrapper());
|
||||
notebookUtils = new NotebookUtils();
|
||||
mockServerManager = TypeMoq.Mock.ofType<LocalJupyterServerManager>();
|
||||
testEvent = new vscode.EventEmitter();
|
||||
token = {
|
||||
@@ -47,7 +44,7 @@ describe('Completion Item Provider', function () {
|
||||
mockSessionManager = TypeMoq.Mock.ofType<JupyterSessionManager>();
|
||||
mockJupyterSession = TypeMoq.Mock.ofType<JupyterSession>();
|
||||
kernel = new TestKernel(true, true);
|
||||
notebookManager = new JupyterNotebookManager(mockServerManager.object, mockSessionManager.object, mockApiWrapper.object);
|
||||
notebookManager = new JupyterNotebookManager(mockServerManager.object, mockSessionManager.object);
|
||||
notebookProviderMock = TypeMoq.Mock.ofType<JupyterNotebookProvider>();
|
||||
notebookProviderMock.setup(n => n.getNotebookManager(TypeMoq.It.isAny())).returns(() => Promise.resolve(notebookManager));
|
||||
completionItemProvider = new NotebookCompletionItemProvider(notebookProviderMock.object);
|
||||
|
||||
@@ -7,8 +7,8 @@ import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as should from 'should';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as sinon from 'sinon';
|
||||
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { AppContext } from '../../common/appContext';
|
||||
import { JupyterController } from '../../jupyter/jupyterController';
|
||||
import { LocalPipPackageManageProvider } from '../../jupyter/localPipPackageManageProvider';
|
||||
@@ -16,24 +16,24 @@ import { MockExtensionContext } from '../common/stubs';
|
||||
import { NotebookUtils } from '../../common/notebookUtils';
|
||||
|
||||
describe('Jupyter Controller', function () {
|
||||
let mockExtensionContext: vscode.ExtensionContext;
|
||||
let appContext: AppContext;
|
||||
let mockExtensionContext: vscode.ExtensionContext = new MockExtensionContext();
|
||||
let appContext = new AppContext(mockExtensionContext);
|
||||
let controller: JupyterController;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
let connection: azdata.connection.ConnectionProfile;
|
||||
|
||||
this.beforeAll(() => {
|
||||
mockExtensionContext = new MockExtensionContext();
|
||||
connection = new azdata.connection.ConnectionProfile();
|
||||
});
|
||||
let connection: azdata.connection.ConnectionProfile = new azdata.connection.ConnectionProfile();
|
||||
let showErrorMessageSpy: sinon.SinonSpy;
|
||||
|
||||
this.beforeEach(() => {
|
||||
mockApiWrapper = TypeMoq.Mock.ofType<ApiWrapper>();
|
||||
mockApiWrapper.setup(x => x.getCurrentConnection()).returns(() => { return Promise.resolve(connection); });
|
||||
appContext = new AppContext(mockExtensionContext, mockApiWrapper.object);
|
||||
showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
sinon.stub(azdata.connection, 'getCurrentConnection').returns(Promise.resolve(connection));
|
||||
sinon.stub(azdata.tasks, 'registerTask');
|
||||
sinon.stub(vscode.commands, 'registerCommand');
|
||||
controller = new JupyterController(appContext);
|
||||
});
|
||||
|
||||
this.afterEach(function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('should activate new JupyterController successfully', async () => {
|
||||
should(controller.extensionContext).deepEqual(appContext.extensionContext, 'Extension context should be passed through');
|
||||
should(controller.jupyterInstallation).equal(undefined, 'JupyterInstallation should be undefined before controller activation');
|
||||
@@ -65,13 +65,13 @@ describe('Jupyter Controller', function () {
|
||||
|
||||
it('should show error message for doManagePackages before activation', async () => {
|
||||
await controller.doManagePackages();
|
||||
mockApiWrapper.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
should(showErrorMessageSpy.calledOnce).be.true('showErrorMessage should be called');
|
||||
});
|
||||
|
||||
it('should not show error message for doManagePackages after activation', async () => {
|
||||
await controller.activate();
|
||||
await controller.doManagePackages();
|
||||
mockApiWrapper.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
|
||||
should(showErrorMessageSpy.notCalled).be.true('showErrorMessage should not be called');
|
||||
});
|
||||
|
||||
it('Returns expected values from notebook provider', async () => {
|
||||
@@ -85,7 +85,7 @@ describe('Jupyter Controller', function () {
|
||||
|
||||
it('Returns notebook manager for real notebook editor', async () => {
|
||||
await controller.activate();
|
||||
let notebookUtils = new NotebookUtils(mockApiWrapper.object);
|
||||
let notebookUtils = new NotebookUtils();
|
||||
const notebookEditor = await notebookUtils.newNotebook(undefined);
|
||||
let notebookManager = await controller.notebookProvider.getNotebookManager(notebookEditor.document.uri);
|
||||
should(controller.notebookProvider.notebookManagerCount).equal(1);
|
||||
|
||||
@@ -12,7 +12,6 @@ import 'mocha';
|
||||
import { LocalJupyterServerManager, ServerInstanceFactory, IServerManagerOptions } from '../../jupyter/jupyterServerManager';
|
||||
import { JupyterServerInstallation } from '../../jupyter/jupyterServerInstallation';
|
||||
import { Deferred } from '../../common/promise';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import { MockExtensionContext } from '../common/stubs';
|
||||
import { JupyterSessionManager } from '../../jupyter/jupyterSessionManager';
|
||||
import { JupyterNotebookManager } from '../../jupyter/jupyterNotebookManager';
|
||||
@@ -28,15 +27,11 @@ describe('Jupyter Notebook Manager', function (): void {
|
||||
let sessionManager: JupyterSessionManager;
|
||||
let notebookManager: JupyterNotebookManager;
|
||||
let deferredInstall: Deferred<void>;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
let mockExtensionContext: MockExtensionContext;
|
||||
let mockFactory: TypeMoq.IMock<ServerInstanceFactory>;
|
||||
let serverManagerOptions: IServerManagerOptions;
|
||||
beforeEach(() => {
|
||||
mockExtensionContext = new MockExtensionContext();
|
||||
mockApiWrapper = TypeMoq.Mock.ofType(ApiWrapper);
|
||||
mockApiWrapper.setup(a => a.showErrorMessage(TypeMoq.It.isAny()));
|
||||
mockApiWrapper.setup(a => a.getWorkspacePathFromUri(TypeMoq.It.isAny())).returns(() => undefined);
|
||||
mockFactory = TypeMoq.Mock.ofType(ServerInstanceFactory);
|
||||
|
||||
deferredInstall = new Deferred<void>();
|
||||
@@ -48,7 +43,6 @@ describe('Jupyter Notebook Manager', function (): void {
|
||||
documentPath: expectedPath,
|
||||
jupyterInstallation: mockInstall.object,
|
||||
extensionContext: mockExtensionContext,
|
||||
apiWrapper: mockApiWrapper.object,
|
||||
factory: mockFactory.object
|
||||
};
|
||||
serverManager = new LocalJupyterServerManager(serverManagerOptions);
|
||||
@@ -90,7 +84,7 @@ describe('Jupyter Notebook Manager', function (): void {
|
||||
it('Session and server managers should be shutdown/stopped on dispose', async function(): Promise<void> {
|
||||
let sessionManager = TypeMoq.Mock.ofType<JupyterSessionManager>();
|
||||
let serverManager = TypeMoq.Mock.ofType<LocalJupyterServerManager>();
|
||||
notebookManager = new JupyterNotebookManager(serverManager.object, sessionManager.object, mockApiWrapper.object);
|
||||
notebookManager = new JupyterNotebookManager(serverManager.object, sessionManager.object);
|
||||
sessionManager.setup(s => s.shutdownAll()).returns(() => new Promise((resolve) => resolve()));
|
||||
serverManager.setup(s => s.stopServer()).returns(() => new Promise((resolve) => resolve()));
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import { ChildProcess } from 'child_process';
|
||||
import 'mocha';
|
||||
|
||||
import { JupyterServerInstallation } from '../../jupyter/jupyterServerInstallation';
|
||||
import { ApiWrapper } from '../..//common/apiWrapper';
|
||||
import { PerFolderServerInstance, ServerInstanceUtils } from '../../jupyter/serverInstance';
|
||||
import { MockOutputChannel } from '../common/stubs';
|
||||
import * as testUtils from '../common/testUtils';
|
||||
@@ -25,14 +24,10 @@ describe('Jupyter server instance', function (): void {
|
||||
let expectedPath = 'mydir/notebook.ipynb';
|
||||
let mockInstall: TypeMoq.IMock<JupyterServerInstallation>;
|
||||
let mockOutputChannel: TypeMoq.IMock<MockOutputChannel>;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
let mockUtils: TypeMoq.IMock<ServerInstanceUtils>;
|
||||
let serverInstance: PerFolderServerInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
mockApiWrapper = TypeMoq.Mock.ofType(ApiWrapper);
|
||||
mockApiWrapper.setup(a => a.showErrorMessage(TypeMoq.It.isAny()));
|
||||
mockApiWrapper.setup(a => a.getWorkspacePathFromUri(TypeMoq.It.isAny())).returns(() => undefined);
|
||||
mockInstall = TypeMoq.Mock.ofType(JupyterServerInstallation, undefined, undefined, '/root');
|
||||
mockOutputChannel = TypeMoq.Mock.ofType(MockOutputChannel);
|
||||
mockInstall.setup(i => i.outputChannel).returns(() => mockOutputChannel.object);
|
||||
|
||||
@@ -13,7 +13,6 @@ import { JupyterServerInstanceStub } from '../common';
|
||||
import { LocalJupyterServerManager, ServerInstanceFactory } from '../../jupyter/jupyterServerManager';
|
||||
import { JupyterServerInstallation } from '../../jupyter/jupyterServerInstallation';
|
||||
import { Deferred } from '../../common/promise';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
import * as testUtils from '../common/testUtils';
|
||||
import { IServerInstance } from '../../jupyter/common';
|
||||
import { MockExtensionContext } from '../common/stubs';
|
||||
@@ -26,14 +25,10 @@ describe('Local Jupyter Server Manager', function (): void {
|
||||
let expectedPath = 'my/notebook.ipynb';
|
||||
let serverManager: LocalJupyterServerManager;
|
||||
let deferredInstall: Deferred<void>;
|
||||
let mockApiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
let mockExtensionContext: MockExtensionContext;
|
||||
let mockFactory: TypeMoq.IMock<ServerInstanceFactory>;
|
||||
beforeEach(() => {
|
||||
mockExtensionContext = new MockExtensionContext();
|
||||
mockApiWrapper = TypeMoq.Mock.ofType(ApiWrapper);
|
||||
mockApiWrapper.setup(a => a.showErrorMessage(TypeMoq.It.isAny()));
|
||||
mockApiWrapper.setup(a => a.getWorkspacePathFromUri(TypeMoq.It.isAny())).returns(() => undefined);
|
||||
mockFactory = TypeMoq.Mock.ofType(ServerInstanceFactory);
|
||||
|
||||
deferredInstall = new Deferred<void>();
|
||||
@@ -45,7 +40,6 @@ describe('Local Jupyter Server Manager', function (): void {
|
||||
documentPath: expectedPath,
|
||||
jupyterInstallation: mockInstall.object,
|
||||
extensionContext: mockExtensionContext,
|
||||
apiWrapper: mockApiWrapper.object,
|
||||
factory: mockFactory.object
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user