Skip to content

Commit 5ab097f

Browse files
committed
Tweak tests for Moodle 5.0 compatibility.
1 parent bf07dbf commit 5ab097f

File tree

2 files changed

+70
-51
lines changed

2 files changed

+70
-51
lines changed

tests/behat/backup_and_restore.feature

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@qtype @qtype_coderunner
1+
@qtype @qtype_coderunner @coderunner_backup_and_restore
22
Feature: Duplicate a course containing a CodeRunner question
33
In order re-use my courses containing CodeRunner questions
44
As a teacher
@@ -30,8 +30,13 @@ Feature: Duplicate a course containing a CodeRunner question
3030
| Confirmation | Filename | test_backup.mbz |
3131
And I restore "test_backup.mbz" backup into a new course using this options:
3232
| Schema | Course name | Course 2 |
33-
And I navigate to "Question bank" in current page administration
33+
34+
And I am on the "Course 2 copy 1" "core_question > course question bank" page
35+
And I should see "Square function"
36+
37+
# Edit the copy and verify the form field contents.
3438
And I choose "Edit question" action for "Square function" in the question bank
39+
3540
Then the following fields match these values:
3641
| Question name | Square function |
3742
| Question text | Write a function sqr(n) that returns n squared. |
Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
@qtype @qtype_coderunner @javascript @pythonpreprocessortest
22
Feature: Check that Python and other languages can be used instead of Twig as a template params preprocessor and that they processes the STUDENT variable correctly.
33
To check that the STUDENT template parameter variables work when a language other than python is the preprocessor
4-
As a teacher
5-
I should be able to write a function that prints the seed and my username it should be marked right
4+
As a teacher or a student
5+
I should be able to write a function that prints the seed and my username
6+
It should be marked right
67

78
Background:
89
Given the CodeRunner test configuration file is loaded
@@ -17,92 +18,105 @@ Feature: Check that Python and other languages can be used instead of Twig as a
1718
| user | course | role |
1819
| teacher1 | C1 | editingteacher |
1920
| student1 | C1 | student |
20-
And the following "question categories" exist:
21-
| contextlevel | reference | name |
22-
| Course | C1 | Test questions |
2321
And the following "activities" exist:
24-
| activity | name | course | idnumber |
25-
| quiz | Test quiz | C1 | quiz1 |
26-
And I am on the "Course 1" "core_question > course question bank" page logged in as teacher1
22+
| activity | name | intro | course | idnumber |
23+
| quiz | Quiz 1 | Quiz 1 for testing the Add menu | C1 | quiz1 |
24+
And the following "question categories" exist:
25+
| contextlevel | reference | name |
26+
| Activity module | quiz1 | Test questions |
27+
28+
Scenario: if evaluate per student is true, both teacher and student should be able to answer with their own names
29+
When I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1"
2730
And I disable UI plugins in the CodeRunner question type
28-
And I add a "CodeRunner" question filling the form with:
29-
| id_coderunnertype | python3 |
30-
| id_customise | 1 |
31-
| id_name | Python preprocessor |
32-
| id_questiontext | Write a program that prints True if seed parameter provided, then {{ firstname }} {{ lastname }} |
33-
| id_answerboxlines | 5 |
34-
| id_validateonsave | 0 |
35-
| id_templateparams | {"firstname": "twaddle", "lastname" : "twaddle" } |
36-
| id_templateparamslang | None |
37-
| id_template | |
38-
| id_iscombinatortemplate | 0 |
39-
| id_testcode_0 | # Unused |
40-
| id_expected_0 | True {{ firstname }} {{ lastname }} |
41-
| id_uiplugin | none |
31+
And I open the "last" add to quiz menu
32+
And I follow "a new question"
33+
And I set the field "item_qtype_coderunner" to "1"
34+
And I press "submitbutton"
35+
Then I should see "Adding a CodeRunner question"
4236

43-
When I choose "Edit question" action for "Python preprocessor" in the question bank
37+
And I set the field "id_coderunnertype" to "python3"
38+
And I set the field "id_customise" to "1"
39+
And I set the field "id_name" to "Python preprocessor"
40+
And I set the field "id_questiontext" to "Write a program that prints True if seed parameter provided, then {{ firstname }} {{ lastname }}"
41+
And I set the field "id_answerboxlines" to "5"
4442
And I set the field "id_templateparams" to "import sys, json; keyvalues = {param.split('=')[0]: param.split('=')[1] for param in sys.argv[1:]}; print(json.dumps(keyvalues))"
4543
And I set the field "id_twigall" to "1"
4644
And I set the field "id_template" to "print({{seed}} > 0, end=' '); {{STUDENT_ANSWER}}"
4745
And I set the field "id_templateparamslang" to "python3"
4846
And I set CodeRunner behat testing flag
4947
And I set the field "id_templateparamsevalpertry" to "1"
50-
And I press "Save changes"
51-
52-
And I am on the "Test quiz" "mod_quiz > Edit" page logged in as teacher1
53-
And I open the "last" add to quiz menu
54-
And I follow "from question bank"
55-
And I set the field with xpath "//input[@type='checkbox' and @id='qbheadercheckbox']" to "1"
56-
And I press "Add selected questions to the quiz"
57-
And I set CodeRunner behat testing flag
48+
And I set the field "id_expected_0" to "True {{ firstname }} {{ lastname }}"
49+
And I set the field "id_uiplugin" to "none"
50+
And I press "id_submitbutton"
51+
Then I should see "Python preprocessor Write a program that prints True if seed"
5852

59-
Scenario: Preview as a teacher, submit answer as a student, review as a teacher
60-
When I am on the "Test quiz" "quiz activity" page
61-
And I press "Preview quiz"
53+
When I am on the "Quiz 1" "quiz activity" page logged in as teacher1
54+
When I press "Preview quiz"
6255
Then I should see "Write a program that prints True if seed parameter provided, then Teacher Last"
6356

6457
When I set the field with xpath "//textarea[contains(@name, 'answer')]" to "print('Teacher Last')"
6558
And I press "Check"
6659
Then I should see "Passed all tests"
6760

6861
When I log out
69-
And I am on the "Test quiz" "quiz activity" page logged in as student1
62+
And I am on the "Quiz 1" "quiz activity" page logged in as student1
7063
And I press "Attempt quiz"
7164
Then I should see "Write a program that prints True if seed parameter provided, then StudentFirst OConnell"
7265
And I set the field with xpath "//textarea[contains(@name, 'answer')]" to "print('StudentFirst OConnell')"
7366
And I press "Check"
7467
Then I should see "Passed all tests"
7568

7669
When I log out
77-
And I am on the "Test quiz" "quiz activity" page logged in as teacher1
70+
And I am on the "Quiz 1" "quiz activity" page logged in as teacher1
7871
And I follow "Attempts: 1"
7972
And I follow "Review attempt"
8073
Then I should see "Write a program that prints True if seed parameter provided, then StudentFirst OConnell"
8174
And I should see "Passed all tests"
8275

83-
Scenario: Turn off per-try evaluation. Question should fail when attempted by student.
84-
When I am on the "Course 1" "core_question > course question bank" page
85-
And I choose "Edit question" action for "Python preprocessor" in the question bank
86-
And I set the following fields to these values:
87-
| id_questiontext | Variant without per-try evaluation |
76+
Scenario: if evaluate per student is unchecked, the teacher's name is displayed not the student's.
77+
When I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1"
78+
And I disable UI plugins in the CodeRunner question type
79+
And I open the "last" add to quiz menu
80+
And I follow "a new question"
81+
And I set the field "item_qtype_coderunner" to "1"
82+
And I press "submitbutton"
83+
Then I should see "Adding a CodeRunner question"
84+
85+
And I set the field "id_coderunnertype" to "python3"
86+
And I set the field "id_customise" to "1"
87+
And I set the field "id_name" to "Python preprocessor"
88+
And I set the field "id_questiontext" to "Write a program that prints True if seed parameter provided, then {{ firstname }} {{ lastname }}"
89+
And I set the field "id_answerboxlines" to "5"
90+
And I set the field "id_templateparams" to "import sys, json; keyvalues = {param.split('=')[0]: param.split('=')[1] for param in sys.argv[1:]}; print(json.dumps(keyvalues))"
91+
And I set the field "id_twigall" to "1"
92+
And I set the field "id_template" to "print({{seed}} > 0, end=' '); {{STUDENT_ANSWER}}"
93+
And I set the field "id_templateparamslang" to "python3"
94+
And I set CodeRunner behat testing flag
8895
And I set the field "id_templateparamsevalpertry" to "0"
96+
And I set the field "id_expected_0" to "True {{ firstname }} {{ lastname }}"
97+
And I set the field "id_uiplugin" to "none"
8998
And I press "id_submitbutton"
90-
Then I should see "Created by"
99+
Then I should see "Python preprocessor Write a program that prints True if seed"
91100

92-
When I am on the "Test quiz" "quiz activity" page
93-
And I press "Preview quiz"
94-
Then I should see "Variant without per-try evaluation"
101+
When I am on the "Quiz 1" "quiz activity" page logged in as teacher1
102+
When I press "Preview quiz"
103+
Then I should see "Write a program that prints True if seed parameter provided, then Teacher Last"
95104

96105
When I set the field with xpath "//textarea[contains(@name, 'answer')]" to "print('Teacher Last')"
97106
And I press "Check"
98107
Then I should see "Passed all tests"
99108

100109
When I log out
101-
And I am on the "Test quiz" "quiz activity" page logged in as student1
110+
And I am on the "Quiz 1" "quiz activity" page logged in as student1
102111
And I press "Attempt quiz"
103-
Then I should see "Variant without per-try evaluation"
112+
Then I should see "Write a program that prints True if seed parameter provided, then Teacher Last"
104113
And I set the field with xpath "//textarea[contains(@name, 'answer')]" to "print('StudentFirst OConnell')"
105114
And I press "Check"
106-
Then I should see "True StudentFirst OConnell"
107-
And I should see "True Teacher Last"
115+
Then I should not see "Passed all tests"
116+
117+
When I log out
118+
And I am on the "Quiz 1" "quiz activity" page logged in as teacher1
119+
And I follow "Attempts: 1"
120+
And I follow "Review attempt"
121+
Then I should not see "Write a program that prints True if seed parameter provided, then StudentFirst OConnell"
108122
And I should not see "Passed all tests"

0 commit comments

Comments
 (0)