Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

vdk-jupyter: remove delete operation #2428

Merged
merged 2 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
{
"command": "jp-vdk:menu-create"
},
{
"command": "jp-vdk:menu-delete"
},
{
"command": "jp-vdk:menu-download"
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import DeployJobDialog, {
showCreateDeploymentDialog
} from '../components/DeployJob';
import CreateJobDialog, { showCreateJobDialog } from '../components/CreateJob';
import DeleteJobDialog, { showDeleteJobDialog } from '../components/DeleteJob';
import { VdkErrorMessage } from '../components/VdkErrorMessage';

// Mock the showDialog function
Expand Down Expand Up @@ -200,66 +199,3 @@ describe('showCreateJobDialog', () => {
expect(jobRequest).toHaveBeenCalledWith('create');
});
});

describe('showDeleteJobDialog', () => {
jobData.set(VdkOption.PATH, 'my-job');
jobData.set(VdkOption.NAME, 'my-team');

afterEach(() => {
jest.clearAllMocks();
});

it('should delete the job when the user confirms', async () => {
const showDialogMock = showDialog as jest.MockedFunction<typeof showDialog>;
const jobRequestMock = jobRequest as jest.MockedFunction<typeof jobRequest>;
const acceptResult = { button: { accept: true } };
const confirmResult = { button: { accept: true } };

// Mock the first dialog
(showDialogMock as jest.Mock).mockResolvedValueOnce(acceptResult);

// Mock the second dialog
(showDialogMock as jest.Mock).mockResolvedValueOnce(confirmResult);

// Call the function
await showDeleteJobDialog();

// Check the results
expect(showDialogMock).toHaveBeenCalledWith({
title: 'Delete Job',
body: (
<DeleteJobDialog
jobName={jobData.get(VdkOption.NAME)!}
jobTeam={jobData.get(VdkOption.TEAM)!}
></DeleteJobDialog>
),
buttons: [Dialog.okButton(), Dialog.cancelButton()]
});
expect(jobRequestMock).toHaveBeenCalledWith('delete');
});

it('should not delete the job when the user does not confirm', async () => {
const showDialogMock = showDialog as jest.MockedFunction<typeof showDialog>;
const jobRequestMock = jobRequest as jest.MockedFunction<typeof jobRequest>;
const refuseResult = { button: { accept: false } };

// Mock the first dialog
(showDialogMock as jest.Mock).mockResolvedValueOnce(refuseResult);

// Call the function
await showDeleteJobDialog();

// Check the results
expect(showDialogMock).toHaveBeenCalledWith({
title: 'Delete Job',
body: (
<DeleteJobDialog
jobName={jobData.get(VdkOption.NAME)!}
jobTeam={jobData.get(VdkOption.TEAM)!}
></DeleteJobDialog>
),
buttons: [Dialog.okButton(), Dialog.cancelButton()]
});
expect(jobRequestMock).toHaveBeenCalledTimes(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { showCreateDeploymentDialog } from './components/DeployJob';
import { showCreateJobDialog } from './components/CreateJob';
import { showDownloadJobDialog } from './components/DownloadJob';
import { showConvertJobToNotebookDialog } from './components/ConvertJobToNotebook';
import { showDeleteJobDialog } from './components/DeleteJob';
import { jobdDataRequest } from './serverRequests';
import { VdkOption } from './vdkOptions/vdk_options';
import { workingDirectory } from '.';
Expand All @@ -21,9 +20,6 @@ export function updateVDKMenu(commands: CommandRegistry, docManager: IDocumentMa
// Add Create job command
add_command(commands, 'jp-vdk:menu-create','Create','Execute VDK Create Command', showCreateJobDialog);

// Add Delete job command
add_command(commands, 'jp-vdk:menu-delete','Delete','Execute VDK Delete Command', showDeleteJobDialog);

// Add Download job command
add_command(commands, 'jp-vdk:menu-download','Download','Execute VDK Download Command', showDownloadJobDialog);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -95,51 +95,6 @@ test('should try to create a job with incorrect input and get error', async ({
await page.getByRole('button', { name: 'OK' }).click();
});

test('should open delete job pop up and then cancel the operation', async ({
page
}) => {
await page.goto('');
await page.menu.open('VDK');
await page.locator('#jp-vdk-menu').getByText('Delete').click();
await page.locator('div').filter({ hasText: 'Delete Job' });
await page.getByRole('button', { name: 'Cancel' }).click();
});

test('should open delete job confirmation pop up', async ({ page }) => {
await page.goto('');
await page.menu.open('VDK');
await page.locator('#jp-vdk-menu').getByText('Delete').click();
await page.locator('div').filter({ hasText: 'Delete Job' });
await page.getByRole('button', { name: 'OK' }).click();
// this is tested with empty input that's why the message is with null
await page.locator('div').filter({
hasText: 'Do you really want to delete the job with name null from null?'
});
await page.getByRole('button', { name: 'Cancel' }).click();
});

test('should try to delete a job with empty input and get error', async ({
page
}) => {
await page.goto('');
await page.menu.open('VDK');
await page.locator('#jp-vdk-menu').getByText('Delete').click();
await page.locator('div').filter({ hasText: 'Delete Job' });
await page.getByRole('button', { name: 'OK' }).click();
// this is tested with empty input that's why the message is with null
await page
.locator('div')
.filter({
hasText: 'Do you really want to delete the job with name null from null?'
})
.first()
.click();
await page.getByRole('button', { name: 'Yes' }).click();
await page
.locator('div')
.filter({ hasText: 'Encountered an error when deleting the job.' });
});

test('should open download job pop up and then cancel the operation', async ({
page
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,6 @@ def post(self):
self.finish(json.dumps(run_result))


class DeleteJobHandler(APIHandler):
"""
Class responsible for handling POST request for deleting a Data Job given its name, team and Rest API URL
Response: return a json formatted str including:
::error field with error message if an error exists
::message field with status of the Vdk operation
"""

@tornado.web.authenticated
def post(self):
input_data = self.get_json_body()
try:
status = VdkUI.delete_job(
input_data[VdkOption.NAME.value], input_data[VdkOption.TEAM.value]
)
self.finish(json.dumps({"message": f"{status}", "error": ""}))
except Exception as e:
self.finish(json.dumps({"message": f"{e}", "error": "true"}))


class DownloadJobHandler(APIHandler):
"""
Class responsible for handling POST request for downloading a Data Job given its name, team,
Expand Down Expand Up @@ -204,7 +184,6 @@ def add_handler(handler, endpoint):
web_app.add_handlers(host_pattern, job_handlers)

add_handler(RunJobHandler, "run")
add_handler(DeleteJobHandler, "delete")
add_handler(DownloadJobHandler, "download")
add_handler(ConvertJobToNotebookHandler, "convertJobToNotebook")
add_handler(CreateJobHandler, "create")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pathlib import Path

from vdk.internal.control.command_groups.job.create import JobCreate
from vdk.internal.control.command_groups.job.delete import JobDelete
from vdk.internal.control.command_groups.job.deploy_cli_impl import JobDeploy
from vdk.internal.control.command_groups.job.download_job import JobDownloadSource
from vdk.internal.control.utils import cli_utils
Expand Down Expand Up @@ -89,18 +88,6 @@ def run_job(path, arguments=None):
return {"message": error["details"]}
return {"message": process.returncode}

@staticmethod
def delete_job(name: str, team: str):
"""
Execute `delete job`.
:param name: the name of the data job that will be deleted
:param team: the team of the data job that will be deleted
:return: message that the job is deleted
"""
cmd = JobDelete(RestApiUrlConfiguration.get_rest_api_url())
cmd.delete_job(name, team)
return f"Deleted the job with name {name} from {team} team. "

@staticmethod
def download_job(name: str, team: str, path: str):
"""
Expand Down