Skip to content

Commit

Permalink
fetch/fetch_feedback failure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tuncbkose committed Jul 12, 2023
1 parent b30b1b1 commit 17dfda2
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,54 @@ test('Fetch assignments', async({

});

/*
* Test fetch failure
*/
test('Fetch failure', async({
page,
baseURL,
tmpPath
}) => {

test.skip(is_windows, 'This feature is not implemented for Windows');

if (baseURL === undefined) throw new Error("BaseURL is undefined.");

// create directories and config files, and open assignment_list tab
await create_env(page, tmpPath, exchange_dir, cache_dir, is_windows);
await add_courses(page, baseURL, tmpPath);
await open_assignment_list(page);

// release some assignments
await execute_command("nbgrader generate_assignment 'Problem Set 1' --force");
await execute_command("nbgrader release_assignment 'Problem Set 1' --course 'abc101' --force");
await execute_command("nbgrader generate_assignment 'ps.01' --force");
await execute_command("nbgrader release_assignment 'ps.01' --course 'xyz 200' --force");

// refresh assignment list
await page.locator('#refresh_assignments_list').click();

// select one course
await select_course(page, 'abc101');

// remove write permissions
// check that there is only one released, and try fetch it
// then restore permissions again
await fs.chmod("nbgrader-assignment-list-test", 0o555, err => {});
var rows = await wait_for_list(page, 'released', 1);
await rows.first().locator('.item_status button').click();
await new Promise(resolve => setTimeout(resolve, 1000)); // to make sure permissions are not restored too fast
await fs.chmod("nbgrader-assignment-list-test", 0o755, err => {});

// check that there is still only one released
rows = await wait_for_list(page, 'released', 1);

// Check and close the error message
await wait_for_error_modal(page);
await close_error_modal(page);

});

/*
* Test submit assignment
*/
Expand Down Expand Up @@ -711,3 +759,117 @@ test('Missing exchange directory', async({
expect(rows.first().locator('.item_course')).toHaveText("abc101");

});

/*
* Test fetching feedback
*/
test('Fetch feedback', async({
page,
baseURL,
tmpPath
}) => {

test.skip(is_windows, 'This feature is not implemented for Windows');

if (baseURL === undefined) throw new Error("BaseURL is undefined.");

// create directories and config files, and open assignment_list tab
await create_env(page, tmpPath, exchange_dir, cache_dir, is_windows);
await add_courses(page, baseURL, tmpPath);
await open_assignment_list(page);

// release some assignments
await execute_command("nbgrader generate_assignment 'Problem Set 1' --force");
await execute_command("nbgrader release_assignment 'Problem Set 1' --course 'abc101' --force");
await execute_command("nbgrader generate_assignment 'ps.01' --force");
await execute_command("nbgrader release_assignment 'ps.01' --course 'xyz 200' --force");

// refresh assignment list
await page.locator('#refresh_assignments_list').click();

// select one course
await select_course(page, 'xyz 200');

// check that there is only one released, and fetch it
var rows = await wait_for_list(page, 'released', 1);
await rows.first().locator('.item_status button').click();

// check that there is only one fetched and submit
rows = await wait_for_list(page, 'fetched', 1);
await rows.first().locator('.item_status button:text("Submit")').click();

// collect submitted assignment and process it
await execute_command("nbgrader collect 'ps.01' --course 'xyz 200'");
await execute_command("nbgrader autograde 'ps.01' --course 'xyz 200'");
await execute_command("nbgrader generate_feedback 'ps.01' --course 'xyz 200'");
await execute_command("nbgrader release_feedback 'ps.01' --course 'xyz 200'");

// check that there is only one submitted and fetch feedback
rows = await wait_for_list(page, 'submitted', 1);
await rows.first().locator('.item_status button:text("Fetch feedback")').click();

// check that there is only one fetched
rows = await wait_for_list(page, 'submitted', 1);
expect(rows.first().locator('.item_name').first()).toHaveText("ps.01");
expect(rows.first().locator('.item_course').first()).toHaveText("xyz 200");

// check that the directory has been created
const contents = galata.newContentsHelper(baseURL);
expect(contents.directoryExists('ps.01/feedback'));
});

/*
* Test fetch feedback failure
*/
test('Fetch feedback failure', async({
page,
baseURL,
tmpPath
}) => {

test.skip(is_windows, 'This feature is not implemented for Windows');

if (baseURL === undefined) throw new Error("BaseURL is undefined.");

// create directories and config files, and open assignment_list tab
await create_env(page, tmpPath, exchange_dir, cache_dir, is_windows);
await add_courses(page, baseURL, tmpPath);
await open_assignment_list(page);

// release some assignments
await execute_command("nbgrader generate_assignment 'Problem Set 1' --force");
await execute_command("nbgrader release_assignment 'Problem Set 1' --course 'abc101' --force");
await execute_command("nbgrader generate_assignment 'ps.01' --force");
await execute_command("nbgrader release_assignment 'ps.01' --course 'xyz 200' --force");

// refresh assignment list
await page.locator('#refresh_assignments_list').click();

// select one course
await select_course(page, 'xyz 200');

// check that there is only one released, and fetch it
var rows = await wait_for_list(page, 'released', 1);
await rows.first().locator('.item_status button').click();

// check that there is only one fetched and submit
rows = await wait_for_list(page, 'fetched', 1);
await rows.first().locator('.item_status button:text("Submit")').click();

// collect submitted assignment and process it
await execute_command("nbgrader collect 'ps.01' --course 'xyz 200'");
await execute_command("nbgrader autograde 'ps.01' --course 'xyz 200'");
await execute_command("nbgrader generate_feedback 'ps.01' --course 'xyz 200'");
await execute_command("nbgrader release_feedback 'ps.01' --course 'xyz 200'");

// check that there is only one submitted and try fetching feedback
await fs.chmod("nbgrader-assignment-list-test/ps.01", 0o555, err => {console.log(err)});
rows = await wait_for_list(page, 'submitted', 1);
await rows.first().locator('.item_status button:text("Fetch Feedback")').click();
await new Promise(resolve => setTimeout(resolve, 5000)); // to make sure permissions are not restored too fast
await fs.chmod("nbgrader-assignment-list-test/ps.01", 0o755, err => {});

// Check and close the error message
await wait_for_error_modal(page);
await close_error_modal(page);
});
62 changes: 62 additions & 0 deletions nbgrader/tests/nbextensions/test_assignment_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,68 @@ def test_validate_failure(browser, port, class_files, tempdir):
_dismiss_modal(browser)


@pytest.mark.nbextensions
@notwindows
def test_fetch_failure(browser, port, class_files, tempdir):
# remove already fetched assignment to try fetching again
shutil.rmtree('ps.01')
_load_assignments_list(browser, port)
_wait_until_loaded(browser)

# choose the course "xyz 200"
_change_course(browser, "xyz 200")

# remove write permissions, click the "fetch" button, and restore permissions
os.chmod(tempdir, 0o555)
rows = _wait_for_list(browser, "released", 1)
rows[0].find_element(By.CSS_SELECTOR, ".item_status button").click()
os.chmod(tempdir, 0o755)

# wait for the modal dialog to appear
_wait_for_modal(browser)

# check that error message is given
modal = browser.find_element(By.ID, "fetch-message")
assert modal.text[:23] == "Assignment not fetched:"

# close the modal dialog
_dismiss_modal(browser)


@pytest.mark.nbextensions
@notwindows
def test_fetch_feedback_failure(browser, port, class_files, tempdir):
_load_assignments_list(browser, port)
_wait_until_loaded(browser)

# generate fetchable feedback
run_nbgrader(["fetch_assignment", "ps.01", "--course", "xyz 200"])
run_nbgrader(["submit", "ps.01", "--course", "xyz 200"])
run_nbgrader(["collect", "ps.01", "--course", "xyz 200"])
run_nbgrader(["autograde", "ps.01", "--course", "xyz 200"])
run_nbgrader(["generate_feedback", "ps.01", "--course", "xyz 200"])
run_nbgrader(["release_feedback", "ps.01", "--course", "xyz 200"])

# choose the course "xyz 200"
_change_course(browser, "xyz 200")

# try fetching feedback without write permissions
os.chmod(os.path.join(tempdir, "ps.01"), 0o555)
rows = _wait_for_list(browser, "submitted", 1)
rows[0].find_element(By.CSS_SELECTOR, ".item_status button").click()
os.chmod(os.path.join(tempdir, "ps.01"), 0o755)

# wait for the modal dialog to appear
_wait_for_modal(browser)

# check that error message is given
modal = browser.find_element(By.ID, "fetchfeedback-message")
assert modal.text[:21] == "Feedback not fetched:"

# close the modal dialog
_dismiss_modal(browser)


@pytest.mark.nbextensions
@notwindows
def test_missing_exchange(exchange, browser, port, class_files, tempdir):
Expand Down

0 comments on commit 17dfda2

Please sign in to comment.