Skip to content

Commit

Permalink
Merge branch 'maint/fix-failing-tests' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanWillitts committed Jan 21, 2025
2 parents a325288 + 3b46a3d commit 0e5104c
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 101 deletions.
34 changes: 23 additions & 11 deletions edc_qol/admin/sf12_admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django_audit_fields.admin import audit_fieldset_tuple
from edc_model_admin.dashboard import ModelAdminSubjectDashboardMixin
from edc_model_admin.history import SimpleHistoryAdmin
Expand All @@ -9,13 +10,16 @@
from ..models import Sf12

additional_instructions = format_html(
"<p>"
"This survey asks for your views about your health. This information "
"will help keep track of how you feel and how well you are able to do "
"your usual activities. "
"<b>Answer each question by choosing just one answer</b>. If you are "
"unsure how to answer a question, please give the best answer you can."
"</p>"
"{}",
mark_safe( # nosec B308, B703
"<p>"
"This survey asks for your views about your health. This information "
"will help keep track of how you feel and how well you are able to do "
"your usual activities. "
"<b>Answer each question by choosing just one answer</b>. If you are "
"unsure how to answer a question, please give the best answer you can."
"</p>"
),
)

past_4w = "<u>past 4 weeks</u>"
Expand Down Expand Up @@ -61,7 +65,9 @@ def sf12_fieldsets():
(
"Part 2: Activities limited by health",
{
"description": format_html(part2_description),
"description": format_html(
"{}", mark_safe(part2_description) # nosec B308, B703
),
"fields": (
"moderate_activities_now_limited",
"climbing_stairs_now_limited",
Expand All @@ -71,7 +77,9 @@ def sf12_fieldsets():
(
"Part 3: Physical health problems (last 4 weeks)",
{
"description": format_html(part3_description),
"description": format_html(
"{}", mark_safe(part3_description) # nosec B308, B703
),
"fields": (
"accomplished_less_physical_health",
"work_limited_physical_health",
Expand All @@ -81,7 +89,9 @@ def sf12_fieldsets():
(
"Part 4: Emotional problems (last 4 weeks)",
{
"description": format_html(part4_description),
"description": format_html(
"{}", mark_safe(part4_description) # nosec B308, B703
),
"fields": (
"accomplished_less_emotional",
"work_less_carefully_emotional",
Expand All @@ -95,7 +105,9 @@ def sf12_fieldsets():
(
"Part 6: Feeling (last 4 weeks)",
{
"description": format_html(part6_description),
"description": format_html(
"{}", mark_safe(part6_description) # nosec B308, B703
),
"fields": (
"felt_calm_peaceful",
"felt_lot_energy",
Expand Down
10 changes: 7 additions & 3 deletions edc_qol/model_mixins/eq5d3l_model_mixin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.utils.html import format_html
from django.utils.safestring import mark_safe

from ..choices import (
ANXIETY_DEPRESSION,
Expand Down Expand Up @@ -32,14 +33,17 @@ class Eq5d3lModelMixin(models.Model):
)

health_today_score_slider = models.CharField(
verbose_name=format_html("Visual score for how your health is TODAY"),
verbose_name=format_html("{}", "Visual score for how your health is TODAY"),
max_length=3,
)

health_today_score_confirmed = models.IntegerField(
verbose_name=format_html(
"<B><font color='orange'>Interviewer</font></B>: "
"please confirm the number on the scale indicated from above."
"{}",
mark_safe( # nosec B308, B703
"<B><font color='orange'>Interviewer</font></B>: "
"please confirm the number on the scale indicated from above."
),
),
validators=[MinValueValidator(0), MaxValueValidator(100)],
help_text=(
Expand Down
61 changes: 43 additions & 18 deletions edc_qol/model_mixins/sf12_model_mixin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from edc_constants.choices import YES_NO

Expand All @@ -21,55 +22,76 @@ class Sf12ModelMixin(models.Model):

moderate_activities_now_limited = models.CharField(
verbose_name=format_html(
_(
"<u>Moderate activities</u> such as moving a table, "
"pushing a vacuum cleaner, bowling, or playing golf:"
)
"{}",
mark_safe( # nosec B308, B703
_(
"<u>Moderate activities</u> such as moving a table, "
"pushing a vacuum cleaner, bowling, or playing golf:"
)
),
),
max_length=20,
choices=HEALTH_LIMITED_CHOICES,
)

climbing_stairs_now_limited = models.CharField(
verbose_name=format_html(_("Climbing <u>several</u> flights of stairs:")),
verbose_name=format_html(
"{}",
mark_safe(_("Climbing <u>several</u> flights of stairs:")), # nosec B308, B703
),
max_length=20,
choices=HEALTH_LIMITED_CHOICES,
)

accomplished_less_physical_health = models.CharField(
verbose_name=format_html(_("<u>Accomplished less</u> than you would like:")),
verbose_name=format_html(
"{}",
mark_safe(_("<u>Accomplished less</u> than you would like:")), # nosec B308, B703
),
max_length=15,
choices=YES_NO,
)

work_limited_physical_health = models.CharField(
verbose_name=format_html(
_("Were limited in the <u>kind</u> of work or other activities:")
"{}",
mark_safe( # nosec B308, B703
_("Were limited in the <u>kind</u> of work or other activities:")
),
),
max_length=15,
choices=YES_NO,
)

accomplished_less_emotional = models.CharField(
verbose_name=format_html(_("<u>Accomplished less</u> than you would like:")),
verbose_name=format_html(
"{}",
mark_safe(_("<u>Accomplished less</u> than you would like:")), # nosec B308, B703
),
max_length=15,
choices=YES_NO,
)

work_less_carefully_emotional = models.CharField(
verbose_name=format_html(
_("Did work or activities <u>less carefully than usual</u>:")
"{}",
mark_safe( # nosec B308, B703
_("Did work or activities <u>less carefully than usual</u>:")
),
),
max_length=15,
choices=YES_NO,
)

pain_interfere_work = models.CharField(
verbose_name=format_html(
_(
"During the <u>past 4 weeks</u>, how much <u>did pain interfere</u> "
"with your normal work (including work outside the home and housework)?"
)
"{}",
mark_safe( # nosec B308, B703
_(
"During the <u>past 4 weeks</u>, how much <u>did pain interfere</u> "
"with your normal work (including work outside the home and housework)?"
)
),
),
max_length=15,
choices=WORK_PAIN_INTERFERENCE_CHOICES,
Expand All @@ -95,11 +117,14 @@ class Sf12ModelMixin(models.Model):

social_activities_interfered = models.CharField(
verbose_name=format_html(
_(
"During the <u>past 4 weeks</u>, how much of the time has your physical "
"health or emotional problems interfered with your social "
"activities (like visiting friends, relatives, etc.)?"
)
"{}",
mark_safe( # nosec B308, B703
_(
"During the <u>past 4 weeks</u>, how much of the time has your physical "
"health or emotional problems interfered with your social "
"activities (like visiting friends, relatives, etc.)?"
)
),
),
max_length=25,
choices=INTERFERENCE_DURATION_CHOICES,
Expand Down
5 changes: 4 additions & 1 deletion edc_qol/modeladmin_mixins/eq5d3l_model_admin_mixin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django_audit_fields.admin import audit_fieldset_tuple

eq5d3l_description = """
Expand Down Expand Up @@ -36,7 +37,9 @@ def eq5d3l_fieldsets():
(
"How is your health TODAY?",
{
"description": format_html(eq5d3l_description),
"description": format_html(
"{}", mark_safe(eq5d3l_description) # nosec B308, B703
),
"fields": (
"health_today_score_slider",
"health_today_score_confirmed",
Expand Down
60 changes: 60 additions & 0 deletions edc_qol/tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import sys
from pathlib import Path

from edc_test_settings.default_test_settings import DefaultTestSettings

app_name = "edc_qol"
base_dir = Path(__file__).absolute().parent.parent.parent

project_settings = DefaultTestSettings(
calling_file=__file__,
BASE_DIR=base_dir,
APP_NAME=app_name,
SILENCED_SYSTEM_CHECKS=[
"sites.E101",
"edc_navbar.E003",
"edc_consent.E001",
"edc_sites.E001",
"edc_sites.E002",
],
SUBJECT_VISIT_MODEL="edc_visit_tracking.subjectvisit",
EDC_AUTH_SKIP_SITE_AUTHS=True,
EDC_AUTH_SKIP_AUTH_UPDATER=True,
INSTALLED_APPS=[
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
"multisite",
"django_crypto_fields.apps.AppConfig",
"django_revision.apps.AppConfig",
"edc_action_item.apps.AppConfig",
"edc_appointment.apps.AppConfig",
"edc_auth.apps.AppConfig",
"edc_dashboard.apps.AppConfig",
"edc_data_manager.apps.AppConfig",
"edc_facility.apps.AppConfig",
"edc_form_runners.apps.AppConfig",
"edc_lab.apps.AppConfig",
"edc_list_data.apps.AppConfig",
"edc_listboard.apps.AppConfig",
"edc_metadata.apps.AppConfig",
"edc_navbar.apps.AppConfig",
"edc_notification.apps.AppConfig",
"edc_registration.apps.AppConfig",
"edc_review_dashboard.apps.AppConfig",
"edc_sites.apps.AppConfig",
"edc_subject_dashboard.apps.AppConfig",
"edc_visit_schedule.apps.AppConfig",
"edc_visit_tracking.apps.AppConfig",
"edc_qol.apps.AppConfig",
"edc_appconfig.apps.AppConfig",
],
add_dashboard_middleware=True,
).settings

for k, v in project_settings.items():
setattr(sys.modules[__name__], k, v)
70 changes: 2 additions & 68 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,5 @@
#!/usr/bin/env python
import logging
from pathlib import Path

from edc_test_utils import DefaultTestSettings, func_main

app_name = "edc_qol"

base_dir = Path(__file__).absolute().parent

project_settings = DefaultTestSettings(
calling_file=__file__,
BASE_DIR=base_dir,
APP_NAME=app_name,
SILENCED_SYSTEM_CHECKS=[
"sites.E101",
"edc_navbar.E002",
"edc_navbar.E003",
"edc_consent.E001",
"edc_sites.E001",
"edc_sites.E002",
],
SUBJECT_VISIT_MODEL="edc_visit_tracking.subjectvisit",
ETC_DIR=str(base_dir / app_name / "tests" / "etc"),
EDC_AUTH_SKIP_SITE_AUTHS=True,
EDC_AUTH_SKIP_AUTH_UPDATER=True,
EDC_SITES_REGISTER_DEFAULT=True,
INSTALLED_APPS=[
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
"multisite",
"django_crypto_fields.apps.AppConfig",
"django_revision.apps.AppConfig",
"edc_action_item.apps.AppConfig",
"edc_appointment.apps.AppConfig",
"edc_auth.apps.AppConfig",
"edc_dashboard.apps.AppConfig",
"edc_data_manager.apps.AppConfig",
"edc_facility.apps.AppConfig",
"edc_form_runners.apps.AppConfig",
"edc_lab.apps.AppConfig",
"edc_list_data.apps.AppConfig",
"edc_listboard.apps.AppConfig",
"edc_metadata.apps.AppConfig",
"edc_navbar.apps.AppConfig",
"edc_notification.apps.AppConfig",
"edc_registration.apps.AppConfig",
"edc_review_dashboard.apps.AppConfig",
"edc_sites.apps.AppConfig",
"edc_subject_dashboard.apps.AppConfig",
"edc_visit_schedule.apps.AppConfig",
"edc_visit_tracking.apps.AppConfig",
"edc_qol.apps.AppConfig",
"edc_appconfig.apps.AppConfig",
],
add_dashboard_middleware=True,
).settings


def main():
func_main(project_settings, *[f"{app_name}.tests"])

from edc_test_settings.func_main import func_main2

if __name__ == "__main__":
logging.basicConfig()
main()
func_main2("edc_qol.tests.test_settings", "edc_qol.tests")

0 comments on commit 0e5104c

Please sign in to comment.