Show
The goal of this test is to make sure you can create groups and groupings using an ID number that is being used by another group/grouping in a different course.
SETUP
You will need 2 courses (A, B) can be existing, please make note of the course ids.
On course B, click on the cog and then select Moore...
On Course administration, click on Users tab and then click Groups .
Create a group (A) and a grouping (A) and set the ID number to something unique for both and make note of this ID NUMBER .
On your moodle integration instance, run the command: mdk run webservices and make note of the token .
GROUPS
Execute the WS request, replacing hostname, courseid (A), wstoken and id number must be the same id number of the group on the course B :
curl 'http://[YOUR_MOODLE_URL]/integration_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_group_create_groups&groups[0][courseid]=COURSE_A_ID_HERE&groups[0][name]=group1&groups[0][idnumber]=UNIQUE_ID_NUMBER_HERE&groups[0][description]=desc&wstoken=WEB_SERVICE_TOKEN_HERE' | python -m json.tool
It should return something like this:
[
{
"courseid": 1,
"description": "desc",
"descriptionformat": 1,
"enrolmentkey": "",
"id": 14,
"idnumber": "123",
"name": "group1"
}
]
Execute the exact same WS request again and this time, you should get an exception:
{
"debuginfo": "Group with the same name already exists in the course",
"errorcode": "invalidparameter",
"exception": "invalid_parameter_exception",
"message": "Invalid parameter value detected"
}
GROUPINGS
Execute the WS request, replacing hostname, courseid (A), wstoken and id number must be the same id number of the grouping on the course B :
curl 'http://[YOUR_MOODLE_URL]/integration_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_group_create_groupings&groupings[0][courseid]=COURSE_A_ID_HERE&groupings[0][name]=grouping1&groupings[0][description]=groupingdescription&groupings[0][idnumber]=UNIQUE_ID_NUMBER_HERE&wstoken=f945c7cfbb815d1a8dc5440770bb7ba4' | python -m json.tool
#It should return something like this, make note of the id:
[
{
"courseid": 1,
"description": "groupingdescription",
"descriptionformat": 1,
"id": 2,
"idnumber": "123",
"name": "grouping1"
}
]
Run the same WS request again, just changing the name now It should return an exception saying the
{
"errorcode": "idnumbertaken",
"exception": "moodle_exception",
"message": "This ID number is already in use"
}
Now, let's test grouping update. Create another grouping in the course A and try to change its ID number to the already existing one.
curl 'http://[YOUR_MOODLE_URL]/integration_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_group_update_groupings&groupings[0][id]=GROUPING_ID&groupings[0][name]=grouping2&groupings[0][description]=groupingdescription&groupings[0][idnumber]=IDNUMBER&wstoken=f945c7cfbb815d1a8dc5440770bb7ba4' | python -m json.tool
You should see something like:
{
"errorcode": "idnumbertaken",
"exception": "moodle_exception",
"message": "This ID number is already in use"
}