# GL: - consider placing the following steps 1 and 2 in a dockerfile and create your own image. That way, you can later spin up multiple instances easily if the test load grows.
# remove next comment line
# --- THIS IS THE FIX ---
# We now wait for the Moodle web application itself to be fully responsive.
# We repeatedly curl the login page until we get a 200 OK status code.
...
...
@@ -57,9 +64,11 @@ echo "✅ Moodle web server is responsive."
# --- Step 6: Assign System Roles via API (The Definitive Fix) ---
echo"🛡️ Step 6: Assigning System Roles to Automation User..."
# --- Step 6: Assign System Roles via API ---
echo"🛡️ Step 6: Assigning System Roles to teacher User..."
# We use the main site admin's token for this one-time setup task, as it's guaranteed to have permissions.
ADMIN_SETUP_TOKEN_RESPONSE=$(curl --fail-sS-L-X POST "$MOODLE_URL/login/token.php"--data-urlencode"username=$MOODLE_ADMIN_USER"--data-urlencode"password=$MOODLE_ADMIN_PASS"--data-urlencode"service=moodle_mobile_app")
echo"🔐 Step 3: Obtaining API Token...$AUTOMATION_USER_NAME..$AUTOMATION_USER_PASS"
TOKEN_RESPONSE=$(curl --fail-sS-L-X POST "$MOODLE_URL/login/token.php"\
...
...
@@ -260,7 +271,7 @@ fi
TOKEN=$(echo"$TOKEN_RESPONSE" | jq -r'.token')
echo"✅ Successfully obtained API token. $TOKEN"
# GL: optionally for every test, rather avoid to save test execution time
# --- Step 4: Create a Course ---
echo"📚 Step 4: Creating a new course..."
COURSE_SHORTNAME="DTA-Course-$(date +%s)"
...
...
@@ -287,11 +298,12 @@ if [ -z "$NEW_COURSE_ID" ] || [ "$NEW_COURSE_ID" == "null" ]; then
exit 1
fi
echo"✅ Successfully created course '$COURSE_SHORTNAME' with ID: $NEW_COURSE_ID"
# GL: - remove following comment line
# --- END OF ROBUST ERROR CHECK ---
# --- Step 5: Enroll Admin User into the New Course ---
echo"🧑🏫 Step 5: Enrolling you as a teacher in the new course..."
# First, get the User ID for your admin user
# --- Step 5: Enroll Teacher User into the New Course ---
echo"🧑🏫 Step 5: Enrolling teacher in the new course..."
# First, get the User ID for your teacher user
AUTOMATION_USER_ID=$(docker exec"$DB_CONTAINER_NAME" mysql -u root -p"$DB_ROOT_PASSWORD""$DB_NAME"-se"SELECT id FROM mdl_user WHERE username='$AUTOMATION_USER_NAME';")
# The roleid for a Teacher is typically 3 (editingteacher) or 4 (teacher). We'll use 3.
TEACHER_ROLE_ID=3
...
...
@@ -315,6 +327,7 @@ if echo "$ENROL_RESPONSE" | jq -e 'if type=="object" and .exception then true el
STUDENT_USER_ID=$(docker exec"$DB_CONTAINER_NAME" mysql -u root -p"$DB_ROOT_PASSWORD""$DB_NAME"-se"SELECT id FROM mdl_user WHERE username='$STUDENT_USER_NAME';")