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 2ca5a29
Show file tree
Hide file tree
Showing 2 changed files with 247 additions and 23 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", 0o777, 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", 0o777, err => {});

// Check and close the error message
await wait_for_error_modal(page);
await close_error_modal(page);
});
108 changes: 85 additions & 23 deletions nbgrader/tests/nbextensions/test_assignment_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,35 +470,97 @@ def test_validate_failure(browser, port, class_files, tempdir):

@pytest.mark.nbextensions
@notwindows
def test_missing_exchange(exchange, browser, port, class_files, tempdir):
# remove the exchange directory and fetched assignments
rmtree(exchange)
rmtree(os.path.join(tempdir, "Problem Set 1"))

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)

# make sure all the errors are showing
_wait(browser).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#released_assignments_list_error")))
_wait(browser).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#fetched_assignments_list_error")))
_wait(browser).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#submitted_assignments_list_error")))
# choose the course "xyz 200"
_change_course(browser, "xyz 200")

# verify that the dropdown list shows an error too
default = browser.find_element(By.CSS_SELECTOR, "#course_list_default")
assert default.text == "Error fetching courses!"
# 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, 0o777)

# recreate the exchange and make sure refreshing works as expected
os.makedirs(exchange)
# wait for the modal dialog to appear
_wait_for_modal(browser)

# release an assignment
run_nbgrader(["generate_assignment", "Problem Set 1", "--force"])
run_nbgrader(["release_assignment", "Problem Set 1", "--course", "abc101", "--force"])
# check that error message is given
modal = browser.find_element(By.ID, "fetch-message")
assert modal.text[:23] == "Assignment not fetched:"

# click the refresh button
browser.find_element(By.CSS_SELECTOR, "#refresh_assignments_list").click()
# 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)

# wait for the released assignments to update
rows = _wait_for_list(browser, "released", 1)
assert rows[0].find_element(By.CLASS_NAME, "item_name").text == "Problem Set 1"
assert rows[0].find_element(By.CLASS_NAME, "item_course").text == "abc101"
# 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"), 0o777)

# 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):
# # remove the exchange directory and fetched assignments
# rmtree(exchange)
# rmtree(os.path.join(tempdir, "Problem Set 1"))
#
# _load_assignments_list(browser, port)
# _wait_until_loaded(browser)
#
# # make sure all the errors are showing
# _wait(browser).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#released_assignments_list_error")))
# _wait(browser).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#fetched_assignments_list_error")))
# _wait(browser).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#submitted_assignments_list_error")))
#
# # verify that the dropdown list shows an error too
# default = browser.find_element(By.CSS_SELECTOR, "#course_list_default")
# assert default.text == "Error fetching courses!"
#
# # recreate the exchange and make sure refreshing works as expected
# os.makedirs(exchange)
#
# # release an assignment
# run_nbgrader(["generate_assignment", "Problem Set 1", "--force"])
# run_nbgrader(["release_assignment", "Problem Set 1", "--course", "abc101", "--force"])
#
# # click the refresh button
# browser.find_element(By.CSS_SELECTOR, "#refresh_assignments_list").click()
# _wait_until_loaded(browser)
#
# # wait for the released assignments to update
# rows = _wait_for_list(browser, "released", 1)
# assert rows[0].find_element(By.CLASS_NAME, "item_name").text == "Problem Set 1"
# assert rows[0].find_element(By.CLASS_NAME, "item_course").text == "abc101"

0 comments on commit 2ca5a29

Please sign in to comment.