diff --git a/evap/contributor/tests/test_forms.py b/evap/contributor/tests/test_forms.py index 281fe6e1ad..0fd672a9d9 100644 --- a/evap/contributor/tests/test_forms.py +++ b/evap/contributor/tests/test_forms.py @@ -1,10 +1,9 @@ from django.forms.models import inlineformset_factory -from django.test import TestCase from model_bakery import baker from evap.contributor.forms import EditorContributionForm, EvaluationForm from evap.evaluation.models import Contribution, Evaluation, Program, Questionnaire, UserProfile -from evap.evaluation.tests.tools import WebTest, get_form_data_from_instance +from evap.evaluation.tests.tools import TestCase, WebTest, get_form_data_from_instance from evap.staff.forms import ContributionFormset diff --git a/evap/contributor/tests/test_views.py b/evap/contributor/tests/test_views.py index a5c2c51b6c..3659ce91e3 100644 --- a/evap/contributor/tests/test_views.py +++ b/evap/contributor/tests/test_views.py @@ -1,7 +1,7 @@ import xlrd from django.core import mail from django.urls import reverse -from django_webtest import WebTest +from evap.evaluation.tests.tools import WebTest from model_bakery import baker from evap.evaluation.models import Contribution, Course, Evaluation, Questionnaire, UserProfile diff --git a/evap/development/tests/test_commands.py b/evap/development/tests/test_commands.py index 0e8c7c058a..476bf88beb 100644 --- a/evap/development/tests/test_commands.py +++ b/evap/development/tests/test_commands.py @@ -4,7 +4,8 @@ from django.conf import settings from django.core import management -from django.test import TestCase + +from evap.evaluation.tests.tools import TestCase class TestDumpTestDataCommand(TestCase): diff --git a/evap/evaluation/tests/test_commands.py b/evap/evaluation/tests/test_commands.py index 53e57448c8..fc378f2885 100644 --- a/evap/evaluation/tests/test_commands.py +++ b/evap/evaluation/tests/test_commands.py @@ -11,7 +11,6 @@ from django.core import mail, management from django.core.management import CommandError from django.db.models import Sum -from django.test import TestCase from django.test.utils import override_settings from model_bakery import baker @@ -29,7 +28,7 @@ TextAnswer, UserProfile, ) -from evap.evaluation.tests.tools import make_manager, make_rating_answer_counters +from evap.evaluation.tests.tools import TestCase, make_manager, make_rating_answer_counters from evap.tools import MonthAndDay diff --git a/evap/evaluation/tests/test_forms.py b/evap/evaluation/tests/test_forms.py index d45ee02d72..371d275c33 100644 --- a/evap/evaluation/tests/test_forms.py +++ b/evap/evaluation/tests/test_forms.py @@ -1,9 +1,8 @@ -from django.test import TestCase from model_bakery import baker from evap.evaluation.forms import NewKeyForm, ProfileForm from evap.evaluation.models import UserProfile -from evap.evaluation.tests.tools import get_form_data_from_instance +from evap.evaluation.tests.tools import TestCase, get_form_data_from_instance class TestNewKeyForm(TestCase): diff --git a/evap/evaluation/tests/test_misc.py b/evap/evaluation/tests/test_misc.py index 46fcd87a07..07bef0f4d8 100644 --- a/evap/evaluation/tests/test_misc.py +++ b/evap/evaluation/tests/test_misc.py @@ -3,13 +3,12 @@ from django.conf import settings from django.core.management import call_command -from django.test import TestCase from django.test.utils import override_settings from django.urls import reverse from model_bakery import baker from evap.evaluation.models import CourseType, Program, Semester, UserProfile -from evap.evaluation.tests.tools import make_manager, submit_with_modal +from evap.evaluation.tests.tools import TestCase, make_manager, submit_with_modal from evap.staff.tests.utils import WebTestStaffMode diff --git a/evap/evaluation/tests/test_models.py b/evap/evaluation/tests/test_models.py index 742d0b2e2e..fe3e431c0a 100644 --- a/evap/evaluation/tests/test_models.py +++ b/evap/evaluation/tests/test_models.py @@ -5,8 +5,8 @@ from django.core import mail from django.core.cache import caches from django.core.exceptions import ValidationError -from django.test import TestCase, override_settings -from django_webtest import WebTest +from django.test import override_settings +from evap.evaluation.tests.tools import WebTest from model_bakery import baker from evap.evaluation.models import ( @@ -25,6 +25,7 @@ UserProfile, ) from evap.evaluation.tests.tools import ( + TestCase, let_user_vote_for_evaluation, make_contributor, make_editor, diff --git a/evap/evaluation/tests/test_models_logging.py b/evap/evaluation/tests/test_models_logging.py index ea900dc4fd..a7c5b72fd2 100644 --- a/evap/evaluation/tests/test_models_logging.py +++ b/evap/evaluation/tests/test_models_logging.py @@ -1,11 +1,11 @@ from datetime import date, datetime, timedelta -from django.test import TestCase from django.utils.formats import localize from model_bakery import baker from evap.evaluation.models import Contribution, Course, Evaluation, Questionnaire, UserProfile from evap.evaluation.models_logging import FieldAction, InstanceActionType +from evap.evaluation.tests.tools import TestCase class TestLoggedModel(TestCase): diff --git a/evap/evaluation/tests/test_tools.py b/evap/evaluation/tests/test_tools.py index ce8a9e5c7e..84efbdda4d 100644 --- a/evap/evaluation/tests/test_tools.py +++ b/evap/evaluation/tests/test_tools.py @@ -5,12 +5,11 @@ from django.core.exceptions import SuspiciousOperation from django.db.models import Model, prefetch_related_objects from django.http import Http404 -from django.test.testcases import TestCase from django.utils import translation from model_bakery import baker from evap.evaluation.models import Contribution, Course, Evaluation, TextAnswer, UserProfile -from evap.evaluation.tests.tools import WebTest +from evap.evaluation.tests.tools import TestCase, WebTest from evap.evaluation.tools import ( discard_cached_related_objects, get_object_from_dict_pk_entry_or_logged_40x, @@ -37,8 +36,6 @@ def test_respects_stored_language(self): self.assertEqual(user.language, "de") self.assertEqual(translation.get_language(), "de") - translation.activate("en") # for following tests - class SaboteurError(Exception): """An exception class used for making sure that our mock is raising the exception and not some other unrelated code""" diff --git a/evap/evaluation/tests/test_views.py b/evap/evaluation/tests/test_views.py index 2cfe17bacd..8def56e3cc 100644 --- a/evap/evaluation/tests/test_views.py +++ b/evap/evaluation/tests/test_views.py @@ -4,7 +4,7 @@ from django.test import override_settings from django.urls import reverse from django.utils import translation -from django_webtest import WebTest +from evap.evaluation.tests.tools import WebTest from model_bakery import baker from evap.evaluation.models import Evaluation, Question, QuestionType, Semester, UserProfile @@ -160,8 +160,6 @@ def test_changes_language(self): user.refresh_from_db() self.assertEqual(user.language, "en") - translation.activate("en") # for following tests - class TestProfileView(WebTest): url = reverse("evaluation:profile_edit") diff --git a/evap/evaluation/tests/tools.py b/evap/evaluation/tests/tools.py index 85e776b098..bc40b71d43 100644 --- a/evap/evaluation/tests/tools.py +++ b/evap/evaluation/tests/tools.py @@ -4,14 +4,15 @@ from contextlib import contextmanager from datetime import timedelta +import django.test import webtest from django.conf import settings from django.contrib.auth.models import Group from django.db import DEFAULT_DB_ALIAS, connections from django.http.request import QueryDict from django.test.utils import CaptureQueriesContext -from django.utils import timezone -from django_webtest import WebTest +from django.utils import timezone, translation +import django_webtest from model_bakery import baker from evap.evaluation.models import ( @@ -28,6 +29,20 @@ ) +class ResetLanguageOnTearDownMixin(): + def tearDown(self): + super().tearDown() + translation.activate("en") # Django by default does not "reset" this, causing test interdependency + + +class TestCase(django.test.TestCase, ResetLanguageOnTearDownMixin): + pass + + +class WebTest(django_webtest.WebTest, ResetLanguageOnTearDownMixin): + pass + + def to_querydict(dictionary): querydict = QueryDict(mutable=True) for key, value in dictionary.items(): diff --git a/evap/grades/tests.py b/evap/grades/tests.py index 1e945a95e7..b420f92564 100644 --- a/evap/grades/tests.py +++ b/evap/grades/tests.py @@ -3,7 +3,7 @@ from django.contrib.auth.models import Group from django.core import mail from django.urls import reverse -from django_webtest import WebTest +from evap.evaluation.tests.tools import WebTest from model_bakery import baker from evap.evaluation.models import Contribution, Course, Evaluation, Questionnaire, Semester, UserProfile diff --git a/evap/results/tests/test_exporters.py b/evap/results/tests/test_exporters.py index 7d60d33660..99bccb477b 100644 --- a/evap/results/tests/test_exporters.py +++ b/evap/results/tests/test_exporters.py @@ -1,7 +1,6 @@ from io import BytesIO import xlrd -from django.test import TestCase from django.utils import translation from model_bakery import baker @@ -19,7 +18,7 @@ TextAnswer, UserProfile, ) -from evap.evaluation.tests.tools import make_rating_answer_counters +from evap.evaluation.tests.tools import TestCase, make_rating_answer_counters from evap.results.exporters import ResultsExporter, TextAnswerExporter from evap.results.tools import cache_results, get_results from evap.results.views import filter_text_answers diff --git a/evap/results/tests/test_tools.py b/evap/results/tests/test_tools.py index 2cf5a57402..0891d85c1f 100644 --- a/evap/results/tests/test_tools.py +++ b/evap/results/tests/test_tools.py @@ -3,7 +3,6 @@ from django.conf import settings from django.core.cache import caches from django.test import override_settings -from django.test.testcases import TestCase from model_bakery import baker from evap.evaluation.models import ( @@ -17,7 +16,7 @@ TextAnswer, UserProfile, ) -from evap.evaluation.tests.tools import make_rating_answer_counters +from evap.evaluation.tests.tools import TestCase, make_rating_answer_counters from evap.results.tools import ( cache_results, calculate_average_course_distribution, diff --git a/evap/results/tests/test_views.py b/evap/results/tests/test_views.py index 4ba9a97cfd..119e851bbc 100644 --- a/evap/results/tests/test_views.py +++ b/evap/results/tests/test_views.py @@ -6,9 +6,8 @@ from django.core.management import call_command from django.db import connection from django.test import override_settings -from django.test.testcases import TestCase from django.test.utils import CaptureQueriesContext -from django_webtest import WebTest +from evap.evaluation.tests.tools import WebTest from model_bakery import baker from evap.evaluation.models import ( @@ -25,6 +24,7 @@ UserProfile, ) from evap.evaluation.tests.tools import ( + TestCase, let_user_vote_for_evaluation, make_manager, make_rating_answer_counters, diff --git a/evap/rewards/tests/test_tools.py b/evap/rewards/tests/test_tools.py index aef456b729..d3769de8c0 100644 --- a/evap/rewards/tests/test_tools.py +++ b/evap/rewards/tests/test_tools.py @@ -1,9 +1,9 @@ -from django.test import TestCase, override_settings +from django.test import override_settings from django.urls import reverse from model_bakery import baker from evap.evaluation.models import NO_ANSWER, Course, Evaluation, Question, Questionnaire, QuestionType, UserProfile -from evap.evaluation.tests.tools import WebTest +from evap.evaluation.tests.tools import TestCase, WebTest from evap.rewards.models import RewardPointGranting, SemesterActivation from evap.rewards.tools import reward_points_of_user diff --git a/evap/rewards/tests/test_views.py b/evap/rewards/tests/test_views.py index b329117eed..d7befd0e60 100644 --- a/evap/rewards/tests/test_views.py +++ b/evap/rewards/tests/test_views.py @@ -2,7 +2,7 @@ from django.test import override_settings from django.urls import reverse -from django_webtest import WebTest +from evap.evaluation.tests.tools import WebTest from model_bakery import baker from evap.evaluation.models import Course, Evaluation, Semester, UserProfile diff --git a/evap/staff/tests/test_forms.py b/evap/staff/tests/test_forms.py index c5ea45b7b8..b796817426 100644 --- a/evap/staff/tests/test_forms.py +++ b/evap/staff/tests/test_forms.py @@ -1,7 +1,7 @@ from unittest.mock import patch from django.forms.models import inlineformset_factory -from django.test import TestCase, override_settings +from django.test import override_settings from model_bakery import baker from evap.contributor.forms import EvaluationForm as ContributorEvaluationForm @@ -21,6 +21,7 @@ UserProfile, ) from evap.evaluation.tests.tools import ( + TestCase, create_evaluation_with_responsible_and_editor, get_form_data_from_instance, to_querydict, diff --git a/evap/staff/tests/test_importers.py b/evap/staff/tests/test_importers.py index a89af3883e..110eb1569d 100644 --- a/evap/staff/tests/test_importers.py +++ b/evap/staff/tests/test_importers.py @@ -6,12 +6,12 @@ from django.conf import settings from django.core.exceptions import ValidationError from django.forms.models import model_to_dict -from django.test import TestCase, override_settings +from django.test import override_settings from model_bakery import baker import evap.staff.fixtures.excel_files_test_data as excel_data from evap.evaluation.models import Contribution, Course, CourseType, Evaluation, Program, Semester, UserProfile -from evap.evaluation.tests.tools import assert_no_database_modifications +from evap.evaluation.tests.tools import TestCase, assert_no_database_modifications from evap.staff.importers import ( ImporterLog, ImporterLogEntry, diff --git a/evap/staff/tests/test_tools.py b/evap/staff/tests/test_tools.py index cab664fd59..da0cd7f0d6 100644 --- a/evap/staff/tests/test_tools.py +++ b/evap/staff/tests/test_tools.py @@ -3,14 +3,13 @@ from unittest.mock import MagicMock, patch from django.contrib.auth.models import Group -from django.test import TestCase from django.utils.html import escape -from django_webtest import WebTest +from evap.evaluation.tests.tools import WebTest from model_bakery import baker from openpyxl import load_workbook from evap.evaluation.models import Contribution, Course, Evaluation, UserProfile -from evap.evaluation.tests.tools import assert_no_database_modifications +from evap.evaluation.tests.tools import TestCase, assert_no_database_modifications from evap.rewards.models import RewardPointGranting, RewardPointRedemption from evap.staff.fixtures.excel_files_test_data import ( create_memory_csv_file, diff --git a/evap/staff/tests/test_views.py b/evap/staff/tests/test_views.py index 85de849802..ea679b8639 100644 --- a/evap/staff/tests/test_views.py +++ b/evap/staff/tests/test_views.py @@ -14,10 +14,9 @@ from django.db.models import Model from django.http import HttpResponse from django.test import override_settings -from django.test.testcases import TestCase from django.urls import reverse from django.utils import translation -from django_webtest import WebTest +from evap.evaluation.tests.tools import WebTest from model_bakery import baker import evap.staff.fixtures.excel_files_test_data as excel_data @@ -41,6 +40,7 @@ ) from evap.evaluation.tests.tools import ( FuzzyInt, + TestCase, assert_no_database_modifications, create_evaluation_with_responsible_and_editor, let_user_vote_for_evaluation, diff --git a/evap/staff/tests/utils.py b/evap/staff/tests/utils.py index 3d38dfdf4a..82daac87c8 100644 --- a/evap/staff/tests/utils.py +++ b/evap/staff/tests/utils.py @@ -2,7 +2,7 @@ import time from contextlib import contextmanager -from django_webtest import WebTest +from evap.evaluation.tests.tools import WebTest from evap.evaluation.tests.tools import WebTestWith200Check from evap.staff.tools import ImportType, generate_import_filename diff --git a/evap/student/tests/test_views.py b/evap/student/tests/test_views.py index c9e495de45..a8f5227314 100644 --- a/evap/student/tests/test_views.py +++ b/evap/student/tests/test_views.py @@ -3,7 +3,7 @@ from functools import partial from django.test.utils import override_settings -from django_webtest import WebTest +from evap.evaluation.tests.tools import WebTest from model_bakery import baker from evap.evaluation.models import (