Skip to content

Commit

Permalink
Merge branch 'release/0.3.35' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Dec 13, 2023
2 parents d022a22 + 1c545af commit ff3da5b
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 35 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.11']
django-version: ['4.2', 'dev']
python-version: ['3.11', '3.12']
django-version: ['4.2', '5.0', 'dev']

exclude:
- python-version: '3.12'
django-version: '4.2'
- python-version: '3.11'
django-version: 'dev'
services:
mysql:
image: mysql:latest
Expand Down
4 changes: 2 additions & 2 deletions edc_registration/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib import admin
from django_audit_fields.admin import audit_fieldset_tuple
from edc_data_manager.modeladmin_mixins import DataManagerSiteModelAdminMixin
from edc_model_admin.history import SimpleHistoryAdmin
from edc_sites.admin import SiteModelAdminMixin

from .admin_site import edc_registration_admin
from .modeladmin_mixins import RegisteredSubjectModelAdminMixin
Expand All @@ -10,7 +10,7 @@

@admin.register(get_registered_subject_model_cls(), site=edc_registration_admin)
class RegisteredSubjectAdmin(
DataManagerSiteModelAdminMixin, RegisteredSubjectModelAdminMixin, SimpleHistoryAdmin
SiteModelAdminMixin, RegisteredSubjectModelAdminMixin, SimpleHistoryAdmin
):
ordering = ("subject_identifier",)

Expand Down
4 changes: 3 additions & 1 deletion edc_registration/auths.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.apps import apps as django_apps
from edc_auth.auth_objects import PII, PII_VIEW
from edc_auth.site_auths import site_auths
from edc_export.auth_objects import EXPORT

site_auths.update_group("edc_registration.export_registeredsubject", name=EXPORT)
if django_apps.is_installed("edc_export"):
site_auths.update_group("edc_registration.export_registeredsubject", name=EXPORT)
site_auths.update_group(
"edc_registration.display_dob",
"edc_registration.display_firstname",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by Django 4.2.1 on 2023-07-07 19:32

import edc_sites.models
from django.db import migrations

import edc_registration.models.managers
import edc_sites.model_mixins


class Migration(migrations.Migration):
Expand All @@ -18,7 +19,7 @@ class Migration(migrations.Migration):
"objects",
edc_registration.models.managers.RegisteredSubjectManager(),
),
("on_site", edc_sites.model_mixins.CurrentSiteManager()),
("on_site", edc_sites.models.CurrentSiteManager()),
],
),
]
6 changes: 3 additions & 3 deletions edc_registration/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from django.core.exceptions import ObjectDoesNotExist
from django.test import TestCase
from django.test.utils import override_settings
from edc_sites import add_or_update_django_sites
from edc_sites.tests import SiteTestCaseMixin
from edc_sites.utils import add_or_update_django_sites
from edc_utils import get_utcnow
from multisite import SiteID

Expand Down Expand Up @@ -112,7 +112,7 @@ def test_cannot_change_subject_identifier(self):

@override_settings(SITE_ID=SiteID(10))
def test_site1(self):
add_or_update_django_sites(sites=self.default_sites, verbose=False)
add_or_update_django_sites(single_sites=self.default_sites, verbose=False)
obj = SubjectModelOne.objects.create(screening_identifier="12345")
rs = RegisteredSubject.objects.get(
registration_identifier=obj.to_string(obj.registration_identifier)
Expand All @@ -121,7 +121,7 @@ def test_site1(self):

@override_settings(SITE_ID=SiteID(20))
def test_site2(self):
add_or_update_django_sites(sites=self.default_sites, verbose=False)
add_or_update_django_sites(single_sites=self.default_sites, verbose=False)
obj = SubjectModelOne.objects.create(screening_identifier="12345")
rs = RegisteredSubject.objects.get(
registration_identifier=obj.to_string(obj.registration_identifier)
Expand Down
19 changes: 15 additions & 4 deletions edc_registration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from edc_registration.models import RegisteredSubject


class RegisteredSubjectDoesNotExist(Exception):
pass


def get_registered_subject_model_name() -> str:
return getattr(
settings,
Expand All @@ -22,11 +26,18 @@ def get_registered_subject_model_cls() -> RegisteredSubject:
return django_apps.get_model(get_registered_subject_model_name())


def get_registered_subject(subject_identifier) -> RegisteredSubject:
def get_registered_subject(
subject_identifier, raise_exception: bool | None = None, **kwargs
) -> RegisteredSubject | None:
opts = dict(subject_identifier=subject_identifier, **kwargs)
try:
registered_subject = get_registered_subject_model_cls().objects.get(
subject_identifier=subject_identifier
)
registered_subject = get_registered_subject_model_cls().objects.get(**opts)
except ObjectDoesNotExist:
registered_subject = None
if raise_exception and not registered_subject:
raise RegisteredSubjectDoesNotExist(
"Unknown subject. "
f"Searched `{get_registered_subject_model_cls()._meta.label_lower}`. "
f"Got {opts}."
)
return registered_subject
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ exclude_lines = [
legacy_tox_ini = """
[tox]
envlist =
py{311}-dj{41,42,dev},
py{311}-dj{42,50},
py{312}-dj{50,dev},
lint
isolated_build = true
[gh-actions]
python =
3.11: py311, lint
3.11: py311
3.12: py312, lint
[gh-actions:env]
DJANGO =
4.2: dj42, lint
dev: djdev
4.2: dj42
5.0: dj50
dev: djdev, lint
[testenv]
deps =
Expand All @@ -56,6 +59,7 @@ deps =
-r https://raw.githubusercontent.com/clinicedc/edc/develop/requirements.tests/edc.txt
-r https://raw.githubusercontent.com/clinicedc/edc/develop/requirements.tests/third_party_dev.txt
dj42: Django>=4.2,<5.0
dj50: Django>=5.0
djdev: https://github.com/django/django/tarball/main
commands =
Expand Down
24 changes: 7 additions & 17 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
#!/usr/bin/env python
import logging
import sys
from os.path import abspath, dirname, join
from pathlib import Path

import django
from django.conf import settings
from django.test.runner import DiscoverRunner
from edc_test_utils import DefaultTestSettings
from edc_test_utils import DefaultTestSettings, func_main

base_dir = dirname(abspath(__file__))
app_name = "edc_registration"
base_dir = Path(__file__).absolute().parent

DEFAULT_SETTINGS = DefaultTestSettings(
project_settings = DefaultTestSettings(
calling_file=__file__,
BASE_DIR=base_dir,
APP_NAME=app_name,
SUBJECT_VISIT_MODEL="edc_visit_tracking.subjectvisit",
ETC_DIR=join(base_dir, app_name, "tests", "etc"),
ETC_DIR=str(base_dir / app_name / "tests" / "etc"),
INSTALLED_APPS=[
"django.contrib.admin",
"django.contrib.auth",
Expand All @@ -40,19 +36,13 @@
"edc_visit_tracking.apps.AppConfig",
"edc_registration.apps.AppConfig",
],
RANDOMIZATION_LIST_PATH=join(base_dir, app_name, "tests", "test_randomization_list.csv"),
RANDOMIZATION_LIST_PATH=str(base_dir / app_name / "tests" / "test_randomization_list.csv"),
add_dashboard_middleware=True,
).settings


def main():
if not settings.configured:
settings.configure(**DEFAULT_SETTINGS)
django.setup()
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")])
failures = DiscoverRunner(failfast=failfast, tags=tags).run_tests([f"{app_name}.tests"])
sys.exit(failures)
func_main(project_settings, *[f"{app_name}.tests"])


if __name__ == "__main__":
Expand Down

0 comments on commit ff3da5b

Please sign in to comment.