From fb2f72e7a96517b611b2a207f5b7929a17947ae1 Mon Sep 17 00:00:00 2001 From: Richard Lobb Date: Fri, 15 Mar 2024 12:02:26 +1300 Subject: [PATCH] Update behat testing to always use test config in test-sandbox-config.php. --- classes/jobesandbox.php | 10 +++------- classes/sandbox.php | 4 ++++ edit_coderunner_form.php | 2 +- renderer.php | 2 +- tests/behat/ace_scratchpad_compatibility.feature | 2 +- tests/behat/attachmentimportexport.feature | 2 +- tests/behat/behat_coderunner.php | 6 ++---- tests/behat/scratchpad_ui.feature | 2 +- tests/behat/scratchpad_ui_params.feature | 2 +- version.php | 4 ++-- 10 files changed, 17 insertions(+), 19 deletions(-) diff --git a/classes/jobesandbox.php b/classes/jobesandbox.php index 5f9d33fa2..725e87fb0 100644 --- a/classes/jobesandbox.php +++ b/classes/jobesandbox.php @@ -70,14 +70,10 @@ class qtype_coderunner_jobesandbox extends qtype_coderunner_sandbox { public function __construct() { global $CFG; qtype_coderunner_sandbox::__construct(); - - // Hack to force use of a local jobe host when behat testing. - if ($CFG->prefix == "bht_") { - $this->jobeserver = "localhost"; - } else { - $this->jobeserver = get_config('qtype_coderunner', 'jobe_host'); + $this->jobeserver = get_config('qtype_coderunner', 'jobe_host'); + if ($this->jobeserver === 'jobe2.cosc.canterbury.ac.nz' && $CFG->prefix === $CFG->behat_prefix) { + throw new Exception("Please don't use the Canterbury jobe server for test runs"); } - $this->apikey = get_config('qtype_coderunner', 'jobe_apikey'); $this->languages = null; } diff --git a/classes/sandbox.php b/classes/sandbox.php index 2a2e2985b..922649fd1 100644 --- a/classes/sandbox.php +++ b/classes/sandbox.php @@ -36,6 +36,10 @@ global $CFG; +if ($CFG->prefix == $CFG->behat_prefix) { + require_once($CFG->dirroot .'/question/type/coderunner/tests/fixtures/test-sandbox-config.php'); +} + abstract class qtype_coderunner_sandbox { protected $user; // Username supplied when constructing. protected $password; // Password supplied when constructing. diff --git a/edit_coderunner_form.php b/edit_coderunner_form.php index 79db9919d..e9aba7d0f 100644 --- a/edit_coderunner_form.php +++ b/edit_coderunner_form.php @@ -250,7 +250,7 @@ protected function add_sample_answer_field($mform) { $mform->addHelpButton('sampleanswerattachments', 'sampleanswerattachments', 'qtype_coderunner'); // Unless behat is running, hide the attachments file picker. // behat barfs if it's hidden. - if ($CFG->prefix !== "b_") { + if ($CFG->prefix !== $CFG->behat_prefix) { $method = method_exists($mform, 'hideIf') ? 'hideIf' : 'disabledIf'; $mform->$method('sampleanswerattachments', 'attachments', 'eq', 0); } diff --git a/renderer.php b/renderer.php index 20696a89c..e81d26637 100644 --- a/renderer.php +++ b/renderer.php @@ -411,7 +411,7 @@ protected function build_results_table($outcome, qtype_coderunner_question $ques if (isset($sandboxinfo['jobeserver'])) { $jobeserver = $sandboxinfo['jobeserver']; $apikey = $sandboxinfo['jobeapikey']; - if ($jobeserver == constants::JOBE_HOST_DEFAULT && $CFG->prefix !== 'b_') { + if ($jobeserver == constants::JOBE_HOST_DEFAULT && $CFG->prefix !== $CFG->behat_prefix) { if ($apikey == constants::JOBE_HOST_DEFAULT_API_KEY) { $fb .= get_string('jobe_warning_html', 'qtype_coderunner'); } else { diff --git a/tests/behat/ace_scratchpad_compatibility.feature b/tests/behat/ace_scratchpad_compatibility.feature index d29805534..86a3bda2d 100644 --- a/tests/behat/ace_scratchpad_compatibility.feature +++ b/tests/behat/ace_scratchpad_compatibility.feature @@ -20,7 +20,7 @@ Feature: Ace UI convert to Scratchpad UI questions with one click And the following "questions" exist: | questioncategory | qtype | name | | Test questions | coderunner | Square function | - And the CodeRunner sandbox is enabled + And the CodeRunner webservice is enabled When I am on the "Square function" "core_question > edit" page logged in as teacher1 And I set the following fields to these values: diff --git a/tests/behat/attachmentimportexport.feature b/tests/behat/attachmentimportexport.feature index 10e88dcec..00e6ae707 100644 --- a/tests/behat/attachmentimportexport.feature +++ b/tests/behat/attachmentimportexport.feature @@ -20,7 +20,7 @@ Feature: Test importing and exporting of question with attachments And the following "questions" exist: | questioncategory | qtype | name | | Test questions | coderunner | Square function | - And the CodeRunner sandbox is enabled + And the CodeRunner webservice is enabled And I am on the "Square function" "core_question > edit" page logged in as teacher And I click on "a[aria-controls='id_attachmentoptionscontainer']" "css_element" And I set the field "Answer" to "from sqrmodule import sqr" diff --git a/tests/behat/behat_coderunner.php b/tests/behat/behat_coderunner.php index 2ecaa8c20..82c6fa091 100644 --- a/tests/behat/behat_coderunner.php +++ b/tests/behat/behat_coderunner.php @@ -30,12 +30,10 @@ class behat_coderunner extends behat_base { /** * Sets the webserver sandbox to enabled for testing purposes. * - * @Given /^the CodeRunner sandbox is enabled/ + * @Given /^the CodeRunner webservice is enabled/ */ - public function the_coderunner_sandbox_is_enabled() { + public function the_coderunner_webservice_is_enabled() { set_config('wsenabled', 1, 'qtype_coderunner'); - set_config('jobesandbox_enabled', 1, 'qtype_coderunner'); - set_config('jobe_host', '172.17.0.1:4000', 'qtype_coderunner'); } /** diff --git a/tests/behat/scratchpad_ui.feature b/tests/behat/scratchpad_ui.feature index 9397521a5..762c0a259 100644 --- a/tests/behat/scratchpad_ui.feature +++ b/tests/behat/scratchpad_ui.feature @@ -20,7 +20,7 @@ Feature: Test the Scratchpad UI And the following "questions" exist: | questioncategory | qtype | name | template | | Test questions | coderunner | Print answer | printans | - And the CodeRunner sandbox is enabled + And the CodeRunner webservice is enabled Scenario: Edit a CodeRunner question into a Scratchpad UI question When I am on the "Print answer" "core_question > edit" page logged in as teacher1 diff --git a/tests/behat/scratchpad_ui_params.feature b/tests/behat/scratchpad_ui_params.feature index 2dd3d8111..eddd52bf7 100644 --- a/tests/behat/scratchpad_ui_params.feature +++ b/tests/behat/scratchpad_ui_params.feature @@ -20,7 +20,7 @@ Feature: Test the Scratchpad UI, UI Params And the following "questions" exist: | questioncategory | qtype | name | template | | Test questions | coderunner | Print answer | printans | - And the CodeRunner sandbox is enabled + And the CodeRunner webservice is enabled And I am on the "Print answer" "core_question > edit" page logged in as teacher1 And I set the field "id_validateonsave" to "" diff --git a/version.php b/version.php index 7a353e708..cfed02a65 100644 --- a/version.php +++ b/version.php @@ -22,12 +22,12 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024022800; +$plugin->version = 2024031500; $plugin->requires = 2022041900; $plugin->cron = 0; $plugin->component = 'qtype_coderunner'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = '5.3.0'; +$plugin->release = '5.3.1'; $plugin->dependencies = [ 'qbehaviour_adaptive_adapted_for_coderunner' => 2021112300,