-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1194455
commit 0ee684d
Showing
5 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
211 changes: 211 additions & 0 deletions
211
projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/ui-tests/tests/convert-job.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
/* | ||
* Copyright 2021-2023 VMware, Inc. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { galata, test } from '@jupyterlab/galata'; | ||
import { expect } from '@playwright/test'; | ||
import path from 'path'; | ||
import { copyDirectory } from './utils'; | ||
const baseJobPath = 'data/convert-test-job-dirty'; | ||
test.use({ autoGoto: false }); | ||
|
||
test.describe('convert job', () => { | ||
test.beforeEach(async ({ baseURL, page, tmpPath }) => { | ||
await copyDirectory( | ||
baseURL!, | ||
path.resolve(__dirname, baseJobPath), | ||
path.join(tmpPath, 'convert-job') | ||
); | ||
|
||
await page.goto(`tree/${tmpPath}`); | ||
}); | ||
|
||
test('success', async ({ page }) => { | ||
// use VDK menu | ||
await page.menu.open('VDK'); | ||
await page.locator('#jp-vdk-menu').getByText('Convert').click(); | ||
await page.locator('div').filter({ hasText: 'Convert' }); | ||
|
||
// fill the dialog | ||
await page.getByLabel('Path to job directory:').click(); | ||
const serverPath1 = await page.getServerRoot(); | ||
await page | ||
.getByLabel('Path to job directory:') | ||
.fill(serverPath1 + `/tests-convert-job-convert-job-success/convert-job`); | ||
await page.getByRole('button', { name: 'OK' }).click(); | ||
|
||
// agree to continue | ||
await page | ||
.locator('div') | ||
.filter({ hasText: 'Are you sure you want to convert the Data Job' }); | ||
await page.getByRole('button', { name: 'OK' }).click(); | ||
await page.locator('div').filter({ hasText: 'Directory not found' }); | ||
await page.getByRole('button', { name: 'Dismiss' }).click(); | ||
|
||
// get message that the job was converted successfully | ||
await page | ||
.locator('div') | ||
.filter({ hasText: 'convert-job was converted to notebook' }); | ||
await page.getByRole('button', { name: 'OK' }).click(); | ||
|
||
// select kernel for the newly created notebook | ||
await page.locator('div').filter({ hasText: 'Select Kernel' }); | ||
await page.getByText('Select kernel for: "Untitled.ipynb"'); | ||
await page.getByRole('button', { name: 'Select', exact: true }).click(); | ||
|
||
// go through the notebook content - guide | ||
await page.locator('pre').filter({ | ||
hasText: | ||
'### Please go through this guide before continuing with the data job run and dev' | ||
}); | ||
await page | ||
.locator('pre') | ||
.filter({ hasText: '#### Introduction and Preparations' }); | ||
await page | ||
.locator('pre') | ||
.filter({ hasText: '#### Execution Order and Identifying Cells' }); | ||
await page.locator('pre').filter({ hasText: '#### Tips:' }); | ||
|
||
// go through ipython configuration | ||
await page | ||
.locator('pre') | ||
.filter({ hasText: '%reload_ext vdk_ipython' }) | ||
.click(); | ||
await page.locator('pre').filter({ hasText: '%reload_VDK' }).click(); | ||
await page | ||
.locator('pre') | ||
.filter({ hasText: 'job_input = VDK.get_initialized_job_input()' }) | ||
.click(); | ||
|
||
// go through steps | ||
await page.locator('pre').filter({ hasText: '#### 10_drop_table.sql' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ | ||
hasText: | ||
'job_input.execute_query("""DROP TABLE IF EXISTS backup_employees;' | ||
}); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: '""")' }); | ||
|
||
await page.locator('pre').filter({ hasText: '#### 20_create_table.sql' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ | ||
hasText: 'job_input.execute_query("""CREATE TABLE backup_employees (' | ||
}); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'EmployeeId INTEGER,' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'LastName NVARCHAR,' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'FirstName NVARCHAR,' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'ReportsTo INTEGER,' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'BirthDate NVARCHAR,' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'Address NVARCHAR,' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'Country NVARCHAR,' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'PostalCode NVARCHAR,' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'Phone NVARCHAR,' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'Fax NVARCHAR,' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'Email NVARCHAR' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: ');' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: '""")' }); | ||
|
||
await page.locator('pre').filter({ hasText: '#### 30_ingest_to_table.py' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'import sqlite3' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'def run(job_input):' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'db_connection = sqlite3.connect(' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: '"chinook.db"' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ | ||
hasText: | ||
') # if chinook.db file is not in your current directory, replace "chinook.db"' | ||
}); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'cursor = db_connection.cursor()' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'cursor.execute("SELECT * FROM employees")' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'job_input.send_tabular_data_for_ingestion(' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'cursor,' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ | ||
hasText: | ||
'column_names=[column_info[0] for column_info in cursor.description],' | ||
}); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: 'destination_table="backup_employees",' }); | ||
await page | ||
.getByRole('region', { name: 'notebook content' }) | ||
.locator('pre') | ||
.filter({ hasText: ')' }); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
...ter/vdk-jupyterlab-extension/ui-tests/tests/data/convert-test-job-dirty/10_drop_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS backup_employees; |
17 changes: 17 additions & 0 deletions
17
...r/vdk-jupyterlab-extension/ui-tests/tests/data/convert-test-job-dirty/20_create_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
CREATE TABLE backup_employees ( | ||
EmployeeId INTEGER, | ||
LastName NVARCHAR, | ||
FirstName NVARCHAR, | ||
Title NVARCHAR, | ||
ReportsTo INTEGER, | ||
BirthDate NVARCHAR, | ||
HireDate NVARCHAR, | ||
Address NVARCHAR, | ||
City NVARCHAR, | ||
State NVARCHAR, | ||
Country NVARCHAR, | ||
PostalCode NVARCHAR, | ||
Phone NVARCHAR, | ||
Fax NVARCHAR, | ||
Email NVARCHAR | ||
); |
16 changes: 16 additions & 0 deletions
16
...vdk-jupyterlab-extension/ui-tests/tests/data/convert-test-job-dirty/30_ingest_to_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2021-2023 VMware, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import sqlite3 | ||
|
||
|
||
def run(job_input): | ||
db_connection = sqlite3.connect( | ||
"chinook.db" | ||
) # if chinook.db file is not in your current directory, replace "chinook.db" with the path to your chinook.db file | ||
cursor = db_connection.cursor() | ||
cursor.execute("SELECT * FROM employees") | ||
job_input.send_tabular_data_for_ingestion( | ||
cursor, | ||
column_names=[column_info[0] for column_info in cursor.description], | ||
destination_table="backup_employees", | ||
) |
17 changes: 17 additions & 0 deletions
17
projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/ui-tests/tests/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright 2021-2023 VMware, Inc. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { galata } from '@jupyterlab/galata'; | ||
import path from 'path'; | ||
|
||
export async function copyDirectory( | ||
baseURL: string, | ||
sourceDirectory: string, | ||
destination: string | ||
): Promise<void> { | ||
const contents = galata.newContentsHelper(baseURL); | ||
|
||
await contents.uploadDirectory(sourceDirectory, destination); | ||
} |