Yeah, I just had fun with the title, primer just sounds fancy
The Python Discord Forms app has support for testing code that is being submitted in an automated way.
If you are curious, python-discord/forms-backend#63 added support for that feature.
Testing is done using python-discord/snekbox. When testing locally, the environment variable SNEKBOX_URL has to be set to http://snekbox:8060/eval if using the provided docker-compose file, or to some compatible evaluation endpoint.
If you aren’t familiar with the structure of a form, here is a quick rundown:
A form is created with a POST request to the /forms endpoint, and a JSON body similar to this one:
{
"id": "code-jam-qualifier",
"features": [
"DISCOVERABLE",
"OPEN"
],
"questions": [
{
"id": "description-header",
"name": "Fill up this form to sign up for the competition.",
"type": "section",
"data": {
"text": "You can find more details about it on <https://pythondiscord.com/events/code-jams/8/.">
},
"required": true
},
{
"id": "github-profile",
"name": "What is your GitHub username? (Optional)",
"type": "short_text",
"data": {},
"required": false
},
{
"id": "age-range",
"name": "What is your age range?",
"type": "radio",
"data": {
"options": [
"13-17 years old",
"18-24 years old",
"25-34 years old",
"35-44 years old",
"45+ years old"
]
},
"required": false
},
{
"id": "qualifier",
"name": "Your solution to the qualifier:",
"type": "code",
"data": {
"language": "python",
"unittests": {},
"allow_failure": false
}
},
"required": true
}
],
"name": "Summer Code Jam 2021!",
"description": "The 8th Python Discord Code Jam",
"webhook": {
"url": "[redacted]",
"message": "{user} signed up for the code jam! (Response #{response_id})"
},
"submitted_text": "Congratulations! Your solution to the qualifier has been submitted."
}
The format should be fairly self explanatory. Not all of those fields are mandatory. For more details, please see the SCHEMA.md file.
code dataThe data dictionary of a code block can hold three parameters:
language: the prismjs language used for syntax highlighting.allow_failure: (default to false) whenever the submission should be recorded even if the tests do not pass. This will make the result be saved with a failed state. The accepted attribute of the whole form will be also set to false.unittests: mapping of unit names to their bodyThe name of the unit will be communicated to the frontend when failing. It is also possible to make the name of the unit start with an # to make the test completely hidden, for instance #001_hidden_test.
Only characters that can be used inside a Python function name (disregarding the leading #, if present) can be used.