|
|
|
|
@@ -36,6 +36,9 @@ import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
|
|
|
|
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
|
|
|
|
import { uriPrefixes } from 'sql/platform/connection/common/utils';
|
|
|
|
|
import { NullAdsTelemetryService } from 'sql/platform/telemetry/common/adsTelemetryService';
|
|
|
|
|
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
|
|
|
|
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
|
|
|
|
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
|
|
|
|
|
|
|
|
|
let expectedNotebookContent: nb.INotebookContents = {
|
|
|
|
|
cells: [{
|
|
|
|
|
@@ -87,6 +90,7 @@ let mockModelFactory: TypeMoq.Mock<ModelFactory>;
|
|
|
|
|
let notificationService: TypeMoq.Mock<INotificationService>;
|
|
|
|
|
let capabilitiesService: ICapabilitiesService;
|
|
|
|
|
let instantiationService: IInstantiationService;
|
|
|
|
|
let configurationService: IConfigurationService;
|
|
|
|
|
|
|
|
|
|
suite('notebook model', function (): void {
|
|
|
|
|
let notebookManagers = [new NotebookManagerStub()];
|
|
|
|
|
@@ -107,6 +111,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
queryConnectionService.callBase = true;
|
|
|
|
|
let serviceCollection = new ServiceCollection();
|
|
|
|
|
instantiationService = new InstantiationService(serviceCollection, true);
|
|
|
|
|
configurationService = new TestConfigurationService();
|
|
|
|
|
defaultModelOptions = {
|
|
|
|
|
notebookUri: defaultUri,
|
|
|
|
|
factory: new ModelFactory(instantiationService),
|
|
|
|
|
@@ -154,7 +159,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(emptyNotebook));
|
|
|
|
|
defaultModelOptions.contentManager = mockContentManager.object;
|
|
|
|
|
// When I initialize the model
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService());
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
|
|
|
|
await model.loadContents();
|
|
|
|
|
|
|
|
|
|
// Then I expect to have 0 code cell as the contents
|
|
|
|
|
@@ -170,7 +175,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
|
|
|
|
defaultModelOptions.contentManager = mockContentManager.object;
|
|
|
|
|
// When I initialize the model
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService());
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
|
|
|
|
await model.loadContents(true);
|
|
|
|
|
await model.requestModelLoad();
|
|
|
|
|
|
|
|
|
|
@@ -187,7 +192,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
|
|
|
|
|
// When I initalize the model
|
|
|
|
|
// Then it should throw
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService());
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
|
|
|
|
assert.equal(model.inErrorState, false);
|
|
|
|
|
await assert.rejects(async () => { await model.loadContents(); });
|
|
|
|
|
assert.equal(model.inErrorState, true);
|
|
|
|
|
@@ -200,7 +205,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
defaultModelOptions.contentManager = mockContentManager.object;
|
|
|
|
|
|
|
|
|
|
// When I initalize the model
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService());
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
|
|
|
|
await model.loadContents();
|
|
|
|
|
|
|
|
|
|
// Then I expect all cells to be in the model
|
|
|
|
|
@@ -228,7 +233,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
defaultModelOptions.providerId = 'jupyter';
|
|
|
|
|
|
|
|
|
|
// When I initalize the model
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService());
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
|
|
|
|
await model.loadContents();
|
|
|
|
|
|
|
|
|
|
// I expect the default provider to be jupyter
|
|
|
|
|
@@ -238,7 +243,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
defaultModelOptions.providerId = 'SQL';
|
|
|
|
|
|
|
|
|
|
// When I initalize the model
|
|
|
|
|
model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService());
|
|
|
|
|
model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
|
|
|
|
await model.loadContents();
|
|
|
|
|
|
|
|
|
|
// I expect the default provider to be SQL
|
|
|
|
|
@@ -263,7 +268,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
defaultModelOptions.contentManager = mockContentManager.object;
|
|
|
|
|
|
|
|
|
|
// When I initalize the model
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService());
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
|
|
|
|
await model.loadContents();
|
|
|
|
|
|
|
|
|
|
let activeCellChangeCount = 0;
|
|
|
|
|
@@ -320,7 +325,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
defaultModelOptions.contentManager = mockContentManager.object;
|
|
|
|
|
|
|
|
|
|
// When I initalize the model
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService());
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
|
|
|
|
await model.loadContents();
|
|
|
|
|
|
|
|
|
|
// Count number of times onError event is fired
|
|
|
|
|
@@ -375,7 +380,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
sessionReady.resolve();
|
|
|
|
|
let sessionFired = false;
|
|
|
|
|
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService());
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
|
|
|
|
model.onClientSessionReady((session) => sessionFired = true);
|
|
|
|
|
await model.loadContents();
|
|
|
|
|
await model.requestModelLoad();
|
|
|
|
|
@@ -405,7 +410,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
|
|
|
|
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
|
|
|
|
defaultModelOptions.contentManager = mockContentManager.object;
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService());
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
|
|
|
|
await model.requestModelLoad();
|
|
|
|
|
|
|
|
|
|
let actualChanged: NotebookContentChange;
|
|
|
|
|
@@ -474,7 +479,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
|
|
|
|
defaultModelOptions.contentManager = mockContentManager.object;
|
|
|
|
|
// When I initialize the model
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, undefined);
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, undefined, queryConnectionService.object, configurationService);
|
|
|
|
|
await model.loadContents();
|
|
|
|
|
|
|
|
|
|
let output = model.toJSON();
|
|
|
|
|
@@ -570,6 +575,57 @@ suite('notebook model', function (): void {
|
|
|
|
|
queryConnectionService.verify((c) => c.disconnect(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Should read connection name from notebook metadata and use its corresponding connection profile', async function () {
|
|
|
|
|
const connectionName = 'connectionName';
|
|
|
|
|
// Given a notebook with a connection name in metadata
|
|
|
|
|
let notebook: nb.INotebookContents = {
|
|
|
|
|
cells: [],
|
|
|
|
|
metadata: {
|
|
|
|
|
connection_name: connectionName
|
|
|
|
|
},
|
|
|
|
|
nbformat: 4,
|
|
|
|
|
nbformat_minor: 5
|
|
|
|
|
};
|
|
|
|
|
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
|
|
|
|
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(notebook));
|
|
|
|
|
defaultModelOptions.contentManager = mockContentManager.object;
|
|
|
|
|
|
|
|
|
|
// And a matching connection profile
|
|
|
|
|
let expectedConnectionProfile: IConnectionProfile = {
|
|
|
|
|
connectionName: connectionName,
|
|
|
|
|
serverName: '',
|
|
|
|
|
databaseName: '',
|
|
|
|
|
userName: '',
|
|
|
|
|
password: '',
|
|
|
|
|
authenticationType: '',
|
|
|
|
|
savePassword: true,
|
|
|
|
|
groupFullName: '',
|
|
|
|
|
groupId: '',
|
|
|
|
|
getOptionsKey: () => '',
|
|
|
|
|
matches: undefined,
|
|
|
|
|
providerName: '',
|
|
|
|
|
saveProfile: true,
|
|
|
|
|
id: '',
|
|
|
|
|
options: {}
|
|
|
|
|
};
|
|
|
|
|
sinon.stub(queryConnectionService.object, 'getConnections').returns([expectedConnectionProfile]);
|
|
|
|
|
sinon.stub(configurationService, 'getValue').returns(true);
|
|
|
|
|
|
|
|
|
|
// When I initialize the model
|
|
|
|
|
let model = new NotebookModel(defaultModelOptions, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService);
|
|
|
|
|
await model.loadContents();
|
|
|
|
|
|
|
|
|
|
// I expect the saved connection name to be read
|
|
|
|
|
assert.equal(model.savedConnectionName, connectionName);
|
|
|
|
|
|
|
|
|
|
// When I request a connection
|
|
|
|
|
let spy = sinon.stub(model, 'changeContext').returns(Promise.resolve());
|
|
|
|
|
model.requestConnection();
|
|
|
|
|
|
|
|
|
|
// I expect the connection profile matching the saved connection name to be used
|
|
|
|
|
assert.ok(spy.calledWith(connectionName, expectedConnectionProfile));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async function loadModelAndStartClientSession(): Promise<NotebookModel> {
|
|
|
|
|
let mockContentManager = TypeMoq.Mock.ofType(NotebookEditorContentManager);
|
|
|
|
|
mockContentManager.setup(c => c.loadContent()).returns(() => Promise.resolve(expectedNotebookContent));
|
|
|
|
|
@@ -583,7 +639,7 @@ suite('notebook model', function (): void {
|
|
|
|
|
let options: INotebookModelOptions = assign({}, defaultModelOptions, <Partial<INotebookModelOptions>>{
|
|
|
|
|
factory: mockModelFactory.object
|
|
|
|
|
});
|
|
|
|
|
let model = new NotebookModel(options, undefined, logService, undefined, new NullAdsTelemetryService(), capabilitiesService);
|
|
|
|
|
let model = new NotebookModel(options, undefined, logService, undefined, new NullAdsTelemetryService(), queryConnectionService.object, configurationService, capabilitiesService);
|
|
|
|
|
model.onClientSessionReady((session) => actualSession = session);
|
|
|
|
|
await model.requestModelLoad();
|
|
|
|
|
|
|
|
|
|
|