Skip to content
Snippets Groups Projects
Commit bb031b59 authored by Martin Juhás's avatar Martin Juhás
Browse files

dev: add test case templates

Closes #233
parent 46262336
No related branches found
No related tags found
No related merge requests found
......@@ -141,3 +141,11 @@ The format of the changelog entries should be:
To determine how to raise the version, read the versioning section [here](../definitions/README.md#versioning).
### Adding tests
Adding new test cases requires a lot of boring boilerplate code to set up.
For this reason, we have a [templates](templates) directory,
which contains templates that contain _most_ of the code necessary to get going.
In most cases, they actually contain too much setup,
which should be removed when unnecessary.
import os
import shutil
from django.conf import settings
from django.test import override_settings
from common_lib.graphql import GraphQLApiTestCase
from common_lib.test_utils import (
internal_upload_definition,
internal_create_exercise,
)
from exercise.models import Exercise
from exercise_definition.models import Definition
from user.models import User
TEST_DATA_STORAGE = "RENAME_ME"
@override_settings(
DATA_STORAGE=TEST_DATA_STORAGE,
FILE_STORAGE=os.path.join(TEST_DATA_STORAGE, "files"),
)
class RENAME_ME(GraphQLApiTestCase):
base_definition: Definition
email_definition: Definition
roles_definition: Definition
base_exercise: Exercise
email_exercise: Exercise
roles_exercise: Exercise
@classmethod
def setUpTestData(cls):
cls.base_definition = internal_upload_definition("base_definition")
cls.email_definition = internal_upload_definition("email_definition")
cls.roles_definition = internal_upload_definition("roles_definition")
cls.base_exercise = internal_create_exercise(cls.base_definition.id, 2)
cls.email_exercise = internal_create_exercise(
cls.email_definition.id, 2
)
cls.roles_exercise = internal_create_exercise(
cls.roles_definition.id, 3
)
cls.instructor = User.objects.create_staffuser(
"instructor@instructor.com", "instructor"
)
cls.user = User.objects.create_user("user@user.com", "user")
cls.instructor.definitions.add(cls.base_definition)
cls.instructor.definitions.add(cls.email_definition)
cls.instructor.definitions.add(cls.roles_definition)
cls.instructor.exercises.add(cls.base_exercise)
cls.instructor.exercises.add(cls.email_exercise)
cls.instructor.exercises.add(cls.roles_exercise)
cls.user.teams.add(cls.base_exercise.teams.first())
cls.user.teams.add(cls.email_exercise.teams.first())
cls.user.teams.add(cls.roles_exercise.teams.first())
@classmethod
def tearDownClass(cls):
shutil.rmtree(settings.DATA_STORAGE)
super().tearDownClass()
import os
import shutil
from django.conf import settings
from django.test import TestCase, override_settings
from common_lib.test_utils import (
internal_upload_definition,
internal_create_exercise,
)
from exercise.models import Exercise
from exercise_definition.models import Definition
TEST_DATA_STORAGE = "RENAME_ME"
@override_settings(
DATA_STORAGE=TEST_DATA_STORAGE,
FILE_STORAGE=os.path.join(TEST_DATA_STORAGE, "files"),
)
class RENAME_ME(TestCase):
base_definition: Definition
email_definition: Definition
roles_definition: Definition
base_exercise: Exercise
email_exercise: Exercise
roles_exercise: Exercise
@classmethod
def setUpTestData(cls):
cls.base_definition = internal_upload_definition("base_definition")
cls.email_definition = internal_upload_definition("email_definition")
cls.roles_definition = internal_upload_definition("roles_definition")
cls.base_exercise = internal_create_exercise(cls.base_definition.id, 2)
cls.email_exercise = internal_create_exercise(
cls.email_definition.id, 2
)
cls.roles_exercise = internal_create_exercise(
cls.roles_definition.id, 3
)
@classmethod
def tearDownClass(cls):
shutil.rmtree(settings.DATA_STORAGE)
super().tearDownClass()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment