forked from botswana-harvard/edc-visit-schedule
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add various checks around conflicting visit CRFs
Checks include creating errors for the following conditions: - visit CRF required + same model in PRNs - proxy CRF required + same proxy in PRNs - proxy root model appears in visit, includes: - proxy root CRF required in single visit (i.e. proxy_root, plus its child proxy as CRF/PRN) - required proxy CRF + proxy root PRN Following allowed: - concrete CRF not required + in PRNs (e.g. Chest Xray) - proxy CRF not required + proxy in PRNs (e.g. Chest Xray) Following allowed if explicitly flagged with `shares_proxy_root=True`: - different proxys pointing to proxy root (parent) model in collection (e.g. proxies for screening Part 1, 2 and 3 - all pointing to same proxy root) Also: - add (and use throughout) get_duplicates() function - standardise form/crf/requisition collection error messaged
- Loading branch information
1 parent
f07589e
commit 2820508
Showing
14 changed files
with
1,578 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from django.test import TestCase | ||
|
||
from edc_visit_schedule.visit import Crf | ||
from edc_visit_schedule.visit.crf import CrfModelNotProxyModelError | ||
|
||
|
||
class TestCrfCollection(TestCase): | ||
def test_crf_ok(self): | ||
try: | ||
Crf(show_order=1, model="visit_schedule_app.CrfOne") | ||
except Exception as e: | ||
self.fail(f"Exception unexpectedly raised. Got {e}") | ||
|
||
try: | ||
Crf(show_order=1, model="visit_schedule_app.CrfOneProxyOne") | ||
except Exception as e: | ||
self.fail(f"Exception unexpectedly raised. Got {e}") | ||
|
||
try: | ||
Crf(show_order=1, model="visit_schedule_app.CrfTwo") | ||
except Exception as e: | ||
self.fail(f"Exception unexpectedly raised. Got {e}") | ||
|
||
try: | ||
Crf(show_order=1, model="visit_schedule_app.CrfThree") | ||
except Exception as e: | ||
self.fail(f"Exception unexpectedly raised. Got {e}") | ||
|
||
def test_proxy_child_crf_with_allow_proxy_parent_clash_ok(self): | ||
try: | ||
Crf( | ||
show_order=1, | ||
model="visit_schedule_app.CrfOneProxyOne", | ||
shares_proxy_root=True, | ||
) | ||
except Exception as e: | ||
self.fail(f"Exception unexpectedly raised. Got {e}") | ||
|
||
def test_proxy_root_crf_with_allow_proxy_parent_clash_raises(self): | ||
with self.assertRaises(CrfModelNotProxyModelError) as cm: | ||
Crf(show_order=1, model="visit_schedule_app.CrfOne", shares_proxy_root=True) | ||
self.assertIn( | ||
"Invalid use of `shares_proxy_root=True`. CRF model is not a proxy model.", | ||
str(cm.exception), | ||
) | ||
self.assertIn("visit_schedule_app.crfone", str(cm.exception)) | ||
|
||
def test_non_proxy_crf_with_allow_proxy_parent_clash_raises(self): | ||
with self.assertRaises(CrfModelNotProxyModelError) as cm: | ||
Crf( | ||
show_order=1, | ||
model="visit_schedule_app.CrfThree", | ||
shares_proxy_root=True, | ||
) | ||
self.assertIn( | ||
"Invalid use of `shares_proxy_root=True`. CRF model is not a proxy model.", | ||
str(cm.exception), | ||
) | ||
self.assertIn("visit_schedule_app.crfthree", str(cm.exception)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.test import TestCase | ||
|
||
from edc_visit_schedule.visit import Crf, CrfCollection, FormsCollectionError | ||
|
||
|
||
class TestCrfCollection(TestCase): | ||
def test_crf_collection_ok(self): | ||
crfs = [ | ||
Crf(show_order=100, model="x.one"), | ||
Crf(show_order=200, model="x.two"), | ||
Crf(show_order=300, model="x.three"), | ||
] | ||
try: | ||
CrfCollection(*crfs) | ||
except FormsCollectionError: | ||
self.fail("FormsCollectionError unexpectedly raised") | ||
|
||
def test_crf_collection_with_duplicate_ordering_raises(self): | ||
crfs = [ | ||
Crf(show_order=100, model="x.one"), | ||
Crf(show_order=200, model="x.two"), | ||
Crf(show_order=100, model="x.three"), | ||
] | ||
with self.assertRaises(FormsCollectionError) as cm: | ||
CrfCollection(*crfs) | ||
self.assertIn( | ||
'CrfCollection "show order" must be a unique sequence.', | ||
str(cm.exception), | ||
) | ||
self.assertIn("Duplicates [100].", str(cm.exception)) | ||
|
||
def test_crf_collection_with_duplicate_models_raises(self): | ||
crfs = [ | ||
Crf(show_order=100, model="x.one"), | ||
Crf(show_order=200, model="x.two"), | ||
Crf(show_order=300, model="x.one"), | ||
] | ||
with self.assertRaises(FormsCollectionError) as cm: | ||
CrfCollection(*crfs) | ||
self.assertIn("Expected to be a unique sequence of crf/models.", str(cm.exception)), | ||
self.assertIn(" Duplicates ['x.one'].", str(cm.exception)) |
Oops, something went wrong.