Skip to content

Commit

Permalink
Merge branch 'release/0.4.23' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Mar 25, 2024
2 parents f18c2dd + e0e9a9d commit 393eef5
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 92 deletions.
89 changes: 89 additions & 0 deletions edc_appointment/tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import sys
from datetime import datetime
from pathlib import Path
from zoneinfo import ZoneInfo

from edc_test_settings.default_test_settings import DefaultTestSettings

utc = ZoneInfo("UTC")

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

project_settings = DefaultTestSettings(
calling_file=__file__,
DEBUG=True,
BASE_DIR=base_dir,
APP_NAME=app_name,
ETC_DIR=base_dir / "etc",
DJANGO_CRYPTO_FIELDS_KEY_PATH=base_dir / "etc",
GIT_DIR=base_dir.parent.parent,
HOLIDAY_FILE=base_dir / "holidays.csv",
EDC_RANDOMIZATION_LIST_PATH=base_dir / "etc",
SILENCED_SYSTEM_CHECKS=[
"sites.E101",
"edc_sites.E001",
"edc_navbar.E002",
"edc_navbar.E003",
],
EDC_PROTOCOL_STUDY_OPEN_DATETIME=datetime(2016, 10, 2, 0, 0, 0, tzinfo=utc),
EDC_PROTOCOL_STUDY_CLOSE_DATETIME=datetime(2023, 10, 2, 0, 0, 0, tzinfo=utc),
EDC_AUTH_SKIP_SITE_AUTHS=True,
EDC_AUTH_SKIP_AUTH_UPDATER=True,
SUBJECT_SCREENING_MODEL="edc_appointment_app.subjectscreening",
SUBJECT_CONSENT_MODEL="edc_appointment_app.subjectconsent",
SUBJECT_VISIT_MODEL="edc_appointment_app.subjectvisit",
SUBJECT_VISIT_MISSED_MODEL="edc_appointment_app.subjectvisitmissed",
SUBJECT_REQUISITION_MODEL="edc_appointment_app.subjectrequisition",
SUBJECT_APP_LABEL="edc_appointment_app",
INSTALLED_APPS=[
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
"django_crypto_fields.apps.AppConfig",
"django_revision.apps.AppConfig",
"multisite",
"edc_sites.apps.AppConfig",
"edc_auth.apps.AppConfig",
"edc_action_item.apps.AppConfig",
"edc_adverse_event.apps.AppConfig",
"adverse_event_app.apps.AppConfig",
"edc_offstudy.apps.AppConfig",
"edc_consent.apps.AppConfig",
"edc_crf.apps.AppConfig",
"edc_dashboard.apps.AppConfig",
"edc_data_manager.apps.AppConfig",
"edc_lab.apps.AppConfig",
"edc_subject_dashboard.apps.AppConfig",
"edc_device.apps.AppConfig",
"edc_facility.apps.AppConfig",
"edc_form_runners.apps.AppConfig",
"edc_identifier.apps.AppConfig",
"edc_list_data.apps.AppConfig",
"edc_listboard.apps.AppConfig",
"edc_locator.apps.AppConfig",
"edc_metadata.apps.AppConfig",
"edc_model_admin.apps.AppConfig",
"edc_navbar.apps.AppConfig",
"edc_protocol.apps.AppConfig",
"edc_randomization.apps.AppConfig",
"edc_registration.apps.AppConfig",
"edc_notification.apps.AppConfig",
"edc_review_dashboard.apps.AppConfig",
"edc_timepoint.apps.AppConfig",
"edc_visit_schedule.apps.AppConfig",
"edc_visit_tracking.apps.AppConfig",
"edc_appointment.apps.AppConfig",
"edc_appointment_app.apps.AppConfig",
"edc_appconfig.apps.AppConfig",
],
add_dashboard_middleware=True,
use_test_urls=True,
).settings

for k, v in project_settings.items():
setattr(sys.modules[__name__], k, v)
7 changes: 2 additions & 5 deletions edc_appointment/tests/tests/test_appointment_creator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import os
from datetime import datetime
from unittest import skip
from zoneinfo import ZoneInfo
Expand Down Expand Up @@ -258,9 +257,7 @@ def test_raise_on_naive_datetime(self):
@time_machine.travel(datetime(1900, 1, 11, 0, 00, tzinfo=utc_tz))
class TestAppointmentCreator2(AppointmentCreatorTestCase):
@override_settings(
HOLIDAY_FILE=os.path.join(
settings.BASE_DIR, settings.APP_NAME, "tests", "no_holidays.csv"
),
HOLIDAY_FILE=settings.BASE_DIR / "no_holidays.csv",
EDC_PROTOCOL_STUDY_OPEN_DATETIME=datetime(1900, 1, 1, 0, 0, 0, tzinfo=utc_tz),
EDC_PROTOCOL_STUDY_CLOSE_DATETIME=datetime(1901, 10, 2, 0, 0, 0, tzinfo=utc_tz),
)
Expand All @@ -270,7 +267,7 @@ def test_create_no_holidays(self):
appt_datetime = datetime(1900, 1, 1, tzinfo=ZoneInfo("UTC"))
site_consents.registry = {}
consent_definition = ConsentDefinition(
"edc_appointment_app.subjectconsent",
"edc_appointment_app.subjectconsentv1",
version="1",
start=datetime(1900, 1, 1, 0, 0, 0, tzinfo=utc_tz),
end=datetime(1901, 10, 2, 0, 0, 0, tzinfo=utc_tz),
Expand Down
7 changes: 2 additions & 5 deletions edc_appointment/tests/tests/test_appointment_creator2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from datetime import datetime
from zoneinfo import ZoneInfo

Expand All @@ -22,9 +21,7 @@
@time_machine.travel(datetime(1900, 1, 11, 0, 00, tzinfo=utc_tz))
class TestAppointmentCreator2(AppointmentCreatorTestCase):
@override_settings(
HOLIDAY_FILE=os.path.join(
settings.BASE_DIR, settings.APP_NAME, "tests", "no_holidays.csv"
),
HOLIDAY_FILE=settings.BASE_DIR / "no_holidays.csv",
EDC_PROTOCOL_STUDY_OPEN_DATETIME=datetime(1900, 1, 1, 0, 0, 0, tzinfo=utc_tz),
EDC_PROTOCOL_STUDY_CLOSE_DATETIME=datetime(1901, 10, 2, 0, 0, 0, tzinfo=utc_tz),
)
Expand All @@ -34,7 +31,7 @@ def test_create_no_holidays(self):
appt_datetime = datetime(1900, 1, 1, tzinfo=ZoneInfo("UTC"))
site_consents.registry = {}
consent_definition = ConsentDefinition(
"edc_appointment_app.subjectconsent",
"edc_appointment_app.subjectconsentv1",
version="1",
start=datetime(1900, 1, 1, 0, 0, 0, tzinfo=utc_tz),
end=datetime(1901, 10, 2, 0, 0, 0, tzinfo=utc_tz),
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions edc_appointment_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.db import models
from django.db.models.deletion import PROTECT
from edc_consent.managers import ConsentObjectsByCdefManager, CurrentSiteByCdefManager
from edc_consent.model_mixins import RequiresConsentFieldsModelMixin
from edc_crf.model_mixins import CrfModelMixin
from edc_identifier.managers import SubjectIdentifierManager
Expand Down Expand Up @@ -123,6 +124,10 @@ class SubjectConsent(


class SubjectConsentV1(SubjectConsent):

objects = ConsentObjectsByCdefManager()
on_site = CurrentSiteByCdefManager()

class Meta:
proxy = True

Expand Down
96 changes: 14 additions & 82 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -1,86 +1,18 @@
#!/usr/bin/env python
import logging
from datetime import datetime
from pathlib import Path
from zoneinfo import ZoneInfo

from edc_test_utils import DefaultTestSettings, func_main

utc = ZoneInfo("UTC")

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

project_settings = DefaultTestSettings(
calling_file=__file__,
BASE_DIR=base_dir,
APP_NAME=app_name,
ETC_DIR=str(base_dir / app_name / "tests" / "etc"),
SILENCED_SYSTEM_CHECKS=["sites.E101", "edc_navbar.E002", "edc_navbar.E003"],
EDC_PROTOCOL_STUDY_OPEN_DATETIME=datetime(2016, 10, 2, 0, 0, 0, tzinfo=utc),
EDC_PROTOCOL_STUDY_CLOSE_DATETIME=datetime(2023, 10, 2, 0, 0, 0, tzinfo=utc),
EDC_AUTH_SKIP_SITE_AUTHS=True,
EDC_AUTH_SKIP_AUTH_UPDATER=True,
SUBJECT_SCREENING_MODEL="edc_appointment_app.subjectscreening",
SUBJECT_CONSENT_MODEL="edc_appointment_app.subjectconsent",
SUBJECT_VISIT_MODEL="edc_appointment_app.subjectvisit",
SUBJECT_VISIT_MISSED_MODEL="edc_appointment_app.subjectvisitmissed",
SUBJECT_REQUISITION_MODEL="edc_appointment_app.subjectrequisition",
SUBJECT_APP_LABEL="edc_appointment_app",
INSTALLED_APPS=[
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
"django_crypto_fields.apps.AppConfig",
"django_revision.apps.AppConfig",
"multisite",
"edc_sites.apps.AppConfig",
"edc_auth.apps.AppConfig",
"edc_action_item.apps.AppConfig",
"edc_adverse_event.apps.AppConfig",
"adverse_event_app.apps.AppConfig",
"edc_offstudy.apps.AppConfig",
"edc_consent.apps.AppConfig",
"edc_crf.apps.AppConfig",
"edc_dashboard.apps.AppConfig",
"edc_data_manager.apps.AppConfig",
"edc_lab.apps.AppConfig",
"edc_subject_dashboard.apps.AppConfig",
"edc_device.apps.AppConfig",
"edc_facility.apps.AppConfig",
"edc_form_runners.apps.AppConfig",
"edc_identifier.apps.AppConfig",
"edc_list_data.apps.AppConfig",
"edc_listboard.apps.AppConfig",
"edc_locator.apps.AppConfig",
"edc_metadata.apps.AppConfig",
"edc_model_admin.apps.AppConfig",
"edc_navbar.apps.AppConfig",
"edc_protocol.apps.AppConfig",
"edc_randomization.apps.AppConfig",
"edc_registration.apps.AppConfig",
"edc_notification.apps.AppConfig",
"edc_review_dashboard.apps.AppConfig",
"edc_timepoint.apps.AppConfig",
"edc_visit_schedule.apps.AppConfig",
"edc_visit_tracking.apps.AppConfig",
"edc_appointment.apps.AppConfig",
"edc_appointment_app.apps.AppConfig",
"edc_appconfig.apps.AppConfig",
],
add_dashboard_middleware=True,
use_test_urls=True,
).settings


def main():
func_main(project_settings, f"{app_name}.tests")
# -*- coding: utf-8 -*-
import os
import sys

import django

if __name__ == "__main__":
logging.basicConfig()
main()
os.environ["DJANGO_SETTINGS_MODULE"] = "edc_appointment.tests.test_settings"
django.setup()
from django.test.runner import DiscoverRunner

tags = [t.split("=")[1] for t in sys.argv if t.startswith("--tag")]
failfast = any([True for t in sys.argv if t.startswith("--failfast")])
keepdb = any([True for t in sys.argv if t.startswith("--keepdb")])
opts = dict(failfast=failfast, tags=tags, keepdb=keepdb)
failures = DiscoverRunner(**opts).run_tests(["edc_appointment.tests"], **opts)
sys.exit(failures)

0 comments on commit 393eef5

Please sign in to comment.