Skip to content

Exercises unittests module

Yam Mesicka edited this page Jun 22, 2020 · 5 revisions

Run tests for old solutions

Step 1: Get the solutions for which you want to run the tests

  1. Go to the docker's terminal: docker exec -it lms_http_1 bash
  2. Open ipython (or any other Python terminal)
  3. Run the following script. Change exercise_ids to match the exercise_ids in the database.
from lms.lmsdb import models
exercise_ids = (118, 119)
solutions = tuple(models.Solution.select(models.Solution.id).join(models.Exercise).filter((models.Exercise.id << exercise_ids) & (models.Solution.state << ['CREATED', 'DONE'])))

Step 2: Load the tests into the database

  1. Move ipython to the background using CTRL + Z
  2. Run python lmstests/public/unittests/import_tests.py /app_dir/notebooks-tests/

Step 3: Run the tests

  1. Move ipython back to the foreground using fg %1 (or whatever job id ipython got).
  2. Run:
from lms.lmstests.public.unittests import tasks
for pk in solutions:
    tasks.run_tests_for_solution.apply_async(args=(pk.id,))

Check how many test results there returned for each exercise

SELECT COUNT(*)
FROM exercisetestname, exercisetest, solutionexercisetestexecution
WHERE exercisetestname.exercise_test_id = exercisetest.id
      AND solutionexercisetestexecution.exercise_test_name_id = exercisetestname.id
      AND exercisetest.exercise_id IN (118);

Remove test results of specific exercise:

DELETE FROM solutionexercisetestexecution
USING exercisetestname, exercisetest
WHERE exercisetestname.exercise_test_id = exercisetest.id
      AND solutionexercisetestexecution.exercise_test_name_id = exercisetestname.id
      AND exercisetest.exercise_id IN (118);