Skip to content

Commit

Permalink
✅(tests) add open response assessment tests
Browse files Browse the repository at this point in the history
We want to generate some of the available edX open response assessment
events.
  • Loading branch information
SergioSim committed Dec 8, 2022
1 parent 343328e commit edcaa3c
Show file tree
Hide file tree
Showing 24 changed files with 1,571 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"es2021": true
},
"extends": [
"eslint:recommended",
"airbnb-typescript",
"plugin:compat/recommended",
"plugin:cypress/recommended",
Expand All @@ -23,8 +24,10 @@
"formatjs/no-multiple-whitespaces": "error",
"formatjs/enforce-description": "error",
"formatjs/enforce-default-message": "error",
"max-len": ["error", { "code": 120 }],
"no-console": ["error", { "allow": ["warn"] }],
"no-nested-ternary": "warn",
"no-undef": "off",
"react/jsx-filename-extension": "off",
"import/no-extraneous-dependencies": ["error", {"devDependencies": false}]
},
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to
- Add edX problem_check event tests
- Add edX video event tests
- Add edX user generator
- Add edX open response assessment tests


[Unreleased]: https://github.com/openfun/learning-analytics-playground/commits/main
20 changes: 17 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ data/edx/store/.keep:
mkdir -p data/edx/store
touch data/edx/store/.keep

data/edx/openassessment_submissions:
mkdir -p data/edx/openassessment_submissions
touch data/edx/openassessment_submissions/.keep

e2e/data/video.mp4: ## generate a 5 second long video and put it in e2e/data directory
mkdir -p e2e/data
$(COMPOSE_RUN) ffmpeg -y -f lavfi -i testsrc=size=1920x1080:rate=1 -vf hue=s=0 \
Expand All @@ -59,7 +63,8 @@ bootstrap: ## bootstrap the project
bootstrap: \
migrate \
run \
realm
realm \
fix-openassessment-fileupload
.PHONY: bootstrap

clean: \
Expand All @@ -75,6 +80,14 @@ clean-db: ## remove LMS databases
$(COMPOSE) rm edx_mongodb edx_mysql edx_redis keycloak_postgres
.PHONY: clean-db

# Fix open assessment file upload with filesystem backend.
# `reverse_lazy` object cannot be dumped by `json.dumps`, which results in
# TypeError when attempting to convert the xblock response to json.
# https://github.com/openedx/edx-ora2/commit/7b57c910a6438572ee3e2aa7557cd5c8f51be887
fix-openassessment-fileupload: ## fix open assessment file upload bug
$(COMPOSE) exec -uroot edx_lms sed -i "s/reverse_lazy/reverse/g" /usr/local/src/ora2/openassessment/fileupload/backends/filesystem.py
.PHONY: fix-openassessment-fileupload

install: ## install tests dependencies
$(YARN) install
.PHONY: install
Expand Down Expand Up @@ -153,12 +166,13 @@ test: \
e2e/data/video.mp4 \
remove-edx-courses
test: ## run tests
$(COMPOSE_RUN) cypress run
$(COMPOSE_RUN) cypress run --config video=false
.PHONY: test

tree: \
data/edx/media/.keep \
data/edx/store/.keep
data/edx/store/.keep \
data/edx/openassessment_submissions
tree: ## create data directories mounted as volumes
.PHONY: tree

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.cypress.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.2"
services:
cypress:
image: "cypress/included:10.11.0"
image: "cypress/included:12.0.1"
entrypoint: cypress
env_file:
- env.d/cypress
Expand Down
1 change: 1 addition & 0 deletions docker-compose.edx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ services:
volumes:
- ./data/edx/media:/edx/var/edxapp/media
- ./data/edx/store:/edx/app/edxapp/data
- ./data/edx/openassessment_submissions:/edx/app/edxapp/data/shared/openassessment_submissions
- ./edx/config:/config
- ./docker/files/usr/local/bin/auth_init:/usr/local/bin/auth_init
command: >
Expand Down
17 changes: 10 additions & 7 deletions e2e/cypress/e2e/lms_enrollment.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ describe("LMS Change Enrollment Test", () => {
before(() => {
const { courseId } = Cypress.env("EDX_COURSES").demoCourse1;

// Note: enrolling the student before adding a new enrollment mode
// avoids additional steps during enrollment.
cy.lmsCreateUser().then(({ email, password }) => {
cy.lmsLogin(email, password);
cy.lmsEnroll(true);
cy.lmsLoginAdmin();
// Note: enrolling the student before adding a new enrollment mode
// avoids additional steps during enrollment.
cy.session("student", () => {
cy.lmsLogin(email, password).then(() => cy.lmsEnroll(true));
});

// Add `verified` enrollment mode from the admin panel.
cy.session("admin", () => cy.lmsLoginAdmin());
cy.visit("/admin/course_modes/coursemode/add/");
cy.get("#id_course_id").type(courseId);
cy.get("#id_mode_slug").select("verified");
Expand Down Expand Up @@ -59,7 +60,9 @@ describe("LMS Change Enrollment Test", () => {

// Upgrade enrollment to verified mode.
// Triggers edx.course.enrollment.upgrade.clicked
cy.lmsLogin(email, password);
cy.session("student", () => {
cy.lmsLogin(email, password).then(() => cy.lmsEnroll(true));
});
cy.visit("/dashboard");
cy.get("#upgrade-to-verified").click();
cy.url().should("include", "/verify_student/upgrade/");
Expand All @@ -72,7 +75,7 @@ describe("LMS Change Enrollment Test", () => {
});

// Remove verified enrollment mode from the admin panel.
cy.lmsLoginAdmin();
cy.session("admin", () => cy.lmsLoginAdmin());
cy.visit("/admin/course_modes/coursemode/");
cy.get("#action-toggle").check();
cy.get("#changelist-form select").select("delete_selected");
Expand Down
196 changes: 196 additions & 0 deletions e2e/cypress/e2e/lms_open_assessment/create_submission.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
// LMS Open Assessment Create Submission Test

import { getProblem, getSectionAndURL } from "../../support/utils";

describe("LMS Open Assessment Create Submission Test", () => {
const [section, sectionUrl] = getSectionAndURL("defaultOpenAssessment");
const problem = getProblem(section, "defaultOpenAssessment");

before(() => {
cy.on("uncaught:exception", (err) => {
// The Electron browser fails to load files from the `edx-ui-toolkit`.
if (err.message.includes("edx-ui-toolkit")) {
return false;
}
return true;
});

cy.lmsCreateUser().then(({ email, password }) => {
cy.lmsLogin(email, password);
cy.lmsEnroll(true);
});

// Navigate to the courseware.
cy.visit(sectionUrl);

// Input answer.
const escapedProblemLocator = problem.locator
.replaceAll(":", "\\:")
.replaceAll("+", "\\+")
.replaceAll("@", "\\@");
cy.get(`#submission__answer__part__text__1__${escapedProblemLocator}`)
.clear()
.type("Student answer");

// Submit answer.
// Triggers `openassessmentblock.create_submission` event.
cy.get("button.action--submit:nth-child(1)").click();

// Check that the answer was submitted with success.
cy.get("#oa_step_status_response .copy").should("have.text", "Complet");
});

it("should log openassessmentblock.create_submission server event", () => {
cy.graylogPartialMatch({
event_type: "openassessmentblock.create_submission",
event: {
answer: {
parts: [{ text: "Student answer" }],
},
},
});
});
});

describe("LMS Open Assessment Create Submission Test With Two Prompts", () => {
const [section, sectionUrl] = getSectionAndURL(
"openAssessmentWithTwoTextPrompts"
);
const problem = getProblem(section, "openAssessmentWithTwoTextPrompts");

before(() => {
cy.on("uncaught:exception", (err) => {
// The Electron browser fails to load files from the `edx-ui-toolkit`.
if (err.message.includes("edx-ui-toolkit")) {
return false;
}
return true;
});

cy.lmsCreateUser().then(({ email, password }) => {
cy.lmsLogin(email, password);
cy.lmsEnroll(true);
});

// Navigate to the courseware.
cy.visit(sectionUrl);

// Input two answers.
const escapedProblemLocator = problem.locator
.replaceAll(":", "\\:")
.replaceAll("+", "\\+")
.replaceAll("@", "\\@");
cy.get(`#submission__answer__part__text__1__${escapedProblemLocator}`)
.clear()
.type("Student answer 1");
cy.get(`#submission__answer__part__text__2__${escapedProblemLocator}`)
.clear()
.type("Student answer 2");

// Submit answer.
// Triggers `openassessmentblock.create_submission` event.
cy.get("button.action--submit:nth-child(1)").click();

// Check that the answer was submitted with success.
cy.get("#oa_step_status_response .copy").should("have.text", "Complet");
});

it("should log openassessmentblock.create_submission server event", () => {
cy.graylogPartialMatch({
event_type: "openassessmentblock.create_submission",
event: {
answer: {
parts: [{ text: "Student answer 1" }, { text: "Student answer 2" }],
},
},
});
});
});

describe("LMS Open Assessment Create Submission Test With One File Upload", () => {
const [section, sectionUrl] = getSectionAndURL(
"openAssessmentWithTwoTextPromptsAndOptionalFile"
);
const problem = getProblem(
section,
"openAssessmentWithTwoTextPromptsAndOptionalFile"
);

before(() => {
cy.on("uncaught:exception", (err) => {
// The Electron browser fails to load files from the `edx-ui-toolkit`.
if (err.message.includes("edx-ui-toolkit")) {
return false;
}
return true;
});

cy.lmsCreateUser().then(({ email, password }) => {
cy.lmsLogin(email, password);
cy.lmsEnroll(true);
});

// Navigate to the courseware.
cy.visit(sectionUrl);

// Select 1 file for upload.
const escapedProblemLocator = problem.locator
.replaceAll(":", "\\:")
.replaceAll("+", "\\+")
.replaceAll("@", "\\@");
cy.get(`#submission_answer_upload_${escapedProblemLocator}`).selectFile(
"cypress/fixtures/pdf_file_1.pdf"
);
cy.get(".file__description.file__description__0").type("Description");

// Upload the selected file.
// Triggers `openassessmentblock.save_files_descriptions` and
// `openassessment.upload_file` events.
cy.get(".file__upload").click();

// Check that the file was uploaded with success.
cy.get(".submission__answer__file").should("have.text", "Description");

// Input one answer.
cy.get(`#submission__answer__part__text__1__${escapedProblemLocator}`)
.clear()
.type("Student answer 1");

// Submit answer.
// Triggers `openassessmentblock.create_submission` event.
cy.get("button.action--submit:nth-child(1)").click();

// Check that the answer was submitted with success.
cy.get("#oa_step_status_response .copy").should("have.text", "Complet");
});

it("should log openassessmentblock.save_files_descriptions server event", () => {
cy.graylogPartialMatch({
event_type: "openassessmentblock.save_files_descriptions",
event: {
saved_response: '["Description"]',
},
});
});

it("should log long openassessment.upload_file browser event", () => {
cy.graylogPartialMatch({
event_type: "openassessment.upload_file",
event:
'{"fileType": "application/pdf", "fileSize": 1174, ' +
'"fileName": "pdf_file_1.pdf"}',
});
});

it("should log openassessmentblock.create_submission server event", () => {
cy.graylogPartialMatch({
event_type: "openassessmentblock.create_submission",
event: {
answer: {
parts: [{ text: "Student answer 1" }, { text: "" }],
files_descriptions: ["Description"].concat(...new Array(19).fill("")),
},
},
});
});
});
Loading

0 comments on commit edcaa3c

Please sign in to comment.