def test_with_list_selects_first(self):
     self.populate_list(randomizer_name="default", overwrite_site=True)
     first_obj = RandomizationList.objects.all().first()
     subject_consent = SubjectConsent.objects.create(
         subject_identifier="12345", user_created="erikvw")
     rando = Randomizer(
         subject_identifier=subject_consent.subject_identifier,
         report_datetime=subject_consent.consent_datetime,
         site=subject_consent.site,
         user=subject_consent.user_created,
     )
     self.assertEqual(rando.sid, first_obj.sid)
 def test_str(self):
     self.populate_list(randomizer_name="default", overwrite_site=True)
     site = Site.objects.get_current()
     subject_consent = SubjectConsent.objects.create(
         subject_identifier="12345", site=site, user_created="erikvw")
     Randomizer(
         subject_identifier=subject_consent.subject_identifier,
         report_datetime=subject_consent.consent_datetime,
         site=subject_consent.site,
         user=subject_consent.user_created,
     )
     obj = RandomizationList.objects.all().first()
     self.assertTrue(str(obj))
 def test_error_condition3(self):
     """Assert raises if RandomizationList not updated correctly."""
     self.populate_list(randomizer_name="default", overwrite_site=True)
     site = Site.objects.get_current()
     subject_consent = SubjectConsent.objects.create(
         subject_identifier="12345", site=site, user_created="erikvw")
     Randomizer(
         subject_identifier=subject_consent.subject_identifier,
         report_datetime=subject_consent.consent_datetime,
         site=subject_consent.site,
         user=subject_consent.user_created,
     )
     RandomizationList.objects.update(subject_identifier=None)
     with self.assertRaises(AlreadyRandomized) as cm:
         Randomizer(
             subject_identifier=subject_consent.subject_identifier,
             report_datetime=subject_consent.consent_datetime,
             site=subject_consent.site,
             user=subject_consent.user_created,
         )
     self.assertEqual(cm.exception.code,
                      "edc_registration.registeredsubject")
 def test_error_condition1(self):
     """Assert raises if RegisteredSubject not updated correctly."""
     self.populate_list(randomizer_name="default", overwrite_site=True)
     subject_consent = SubjectConsent.objects.create(
         subject_identifier="12345", user_created="erikvw")
     rando = Randomizer(
         subject_identifier=subject_consent.subject_identifier,
         report_datetime=subject_consent.consent_datetime,
         site=subject_consent.site,
         user=subject_consent.user_created,
     )
     rando.registered_subject.sid = None
     rando.registered_subject.save()
     with self.assertRaises(AlreadyRandomized) as cm:
         Randomizer(
             subject_identifier=subject_consent.subject_identifier,
             report_datetime=subject_consent.consent_datetime,
             site=subject_consent.site,
             user=subject_consent.user_created,
         )
     self.assertEqual(cm.exception.code,
                      "edc_randomization.randomizationlist")
 def test_with_consent(self):
     randomizer = site_randomizers.get("default")
     randomizer.import_list()
     site = Site.objects.get_current()
     subject_consent = SubjectConsent.objects.create(
         subject_identifier="12345", site=site, user_created="erikvw")
     try:
         Randomizer(
             subject_identifier=subject_consent.subject_identifier,
             report_datetime=subject_consent.consent_datetime,
             site=subject_consent.site,
             user=subject_consent.user_created,
         )
     except Exception as e:
         self.fail(f"Exception unexpectedly raised. Got {str(e)}.")
 def test_updates_registered_subject(self):
     self.populate_list(randomizer_name="default", overwrite_site=True)
     subject_consent = SubjectConsent.objects.create(
         subject_identifier="12345", user_created="erikvw")
     Randomizer(
         subject_identifier=subject_consent.subject_identifier,
         report_datetime=subject_consent.consent_datetime,
         site=subject_consent.site,
         user=subject_consent.user_created,
     )
     first_obj = RandomizationList.objects.all().first()
     rs = RegisteredSubject.objects.get(subject_identifier="12345")
     self.assertEqual(rs.subject_identifier, first_obj.subject_identifier)
     self.assertEqual(rs.sid, str(first_obj.sid))
     self.assertEqual(rs.randomization_datetime,
                      first_obj.allocated_datetime)
     self.assertEqual(rs.randomization_list_model,
                      first_obj._meta.label_lower)
 def test_updates_list_obj_as_allocated(self):
     self.populate_list(randomizer_name="default", overwrite_site=True)
     RandomizationList.objects.all().first()
     subject_consent = SubjectConsent.objects.create(
         subject_identifier="12345", user_created="erikvw")
     Randomizer(
         subject_identifier=subject_consent.subject_identifier,
         report_datetime=subject_consent.consent_datetime,
         site=subject_consent.site,
         user=subject_consent.user_created,
     )
     first_obj = RandomizationList.objects.all().first()
     self.assertEqual(first_obj.subject_identifier, "12345")
     self.assertTrue(first_obj.allocated)
     self.assertIsNotNone(first_obj.allocated_user)
     self.assertEqual(first_obj.allocated_user,
                      subject_consent.user_created)
     self.assertEqual(first_obj.allocated_datetime,
                      subject_consent.consent_datetime)
     self.assertGreater(first_obj.modified, subject_consent.created)