Accessing Submission Metadata in your tests

Get access to the assignment creation date and other submission metadata to use in your tests.

Often we want our tests to be based on some information contained in each students' submission. Here are some examples for which you may want access to the submission metadata:

  • Deducting marks for late submissions Some instructors choose to grant students the permission to submit after the deadline with the caveat that they will have marks deducted from their submission depending on how long after the deadline they submit their work.

  • Randomizing test cases Some instructors try to mitigate the risk of plagiarism by randomizing test cases according to the user ID of each student.

Accessing submission metadata is easy in AutoTest v2. You can access submission metadata using the environment variable CG_INFO and parsing the information into your test scripts.

Depending on the situation you may receive different information for each student:

  • There is a submission - If the student has made a submission you will get the following information:

    {
        source: "submission";
        student_id: number;
        deadline: datetime;
        lock_date: datetime;
        submitted_at: datetime;
        submission_id: string
    }

  • There is no submission but tests have been run in the editor - If the student has not made a submission but has run the tests in the CodeGrade editor you will get the following information:

    {
        source: "code-editor";
        student_id: number;
        deadline: datetime;
        lock_date: datetime;
    }

How to access submission metadata in AutoTest v2:

  1. Navigate to the Tests portion of the AutoTest settings.

  2. In a test block or in a custom grading script import the CG_INFO environment variable. Here is a code snippet that illustrates how to import the CG_INFO environment variable in Python:

    import os
    
    print(os.getenv('CG_INFO'))

Last updated