class ImportContactsEntityTest(TestCase): def setUp(self): self.entity = EntityFactory(organization__type=organization_type.MAIN) today = datetime.date.today() self.entity_version = EntityVersionFactory( start_date=today.replace(year=1900), end_date=None, entity=self.entity, ) self.education_group_year = EducationGroupYearFactory( publication_contact_entity=None) def test_import_contacts_entity_case_acronym_found(self): _import_contact_entity(self.entity_version.acronym, self.education_group_year) self.education_group_year.refresh_from_db() self.assertEqual(self.education_group_year.publication_contact_entity, self.entity) def test_import_contacts_entity_case_acronym_not_found(self): _import_contact_entity('DUMMY-ACRONYM', self.education_group_year) self.education_group_year.refresh_from_db() self.assertIsNone(self.education_group_year.publication_contact_entity) def test_import_contacts_entity_case_muliple_acronym_found(self): # Create a duplicate entity version [same acronym] today = datetime.date.today() EntityVersionFactory( start_date=today.replace(year=1900), end_date=None, entity=EntityFactory(organization__type=organization_type.MAIN), acronym=self.entity_version.acronym) with self.assertRaises(MultipleObjectsReturned): _import_contact_entity(self.entity_version.acronym, self.education_group_year) self.education_group_year.refresh_from_db() self.assertIsNone(self.education_group_year.publication_contact_entity)
class TestReddotEducationGroupAutomaticPostponement(TestCase): @classmethod def setUpTestData(cls): cls.current_year = AcademicYearFactory(year=get_current_year()) cls.previous_year = AcademicYearFactory(year=get_current_year() - 1) def test_postpone(self): self.current_education_group_year = EducationGroupYearFactory( academic_year=self.current_year) publication_contact_entity = EntityFactory() self.previous_education_group_year = EducationGroupYearFactory( academic_year=self.previous_year, education_group=self.current_education_group_year.education_group, publication_contact_entity=publication_contact_entity, ) TranslatedTextFactory( entity=OFFER_YEAR, reference=str(self.previous_education_group_year.pk), text= "It is our choices, Harry, that show what we truly are, far more than our abilities." ) EducationGroupPublicationContactFactory( education_group_year=self.previous_education_group_year) EducationGroupDetailedAchievementFactory( education_group_achievement__education_group_year=self. previous_education_group_year) AdmissionConditionLineFactory( admission_condition__education_group_year=self. previous_education_group_year, section="nothing else matters") # this object will be removed during the copy. AdmissionConditionLineFactory( admission_condition__education_group_year=self. current_education_group_year, section="the world is dying.") postponer = ReddotEducationGroupAutomaticPostponement() postponer.postpone() self.assertEqual(len(postponer.result), 1) self.assertEqual(len(postponer.errors), 0) self.assertEqual( TranslatedText.objects.get( entity=OFFER_YEAR, reference=str(self.current_education_group_year.pk)).text, "It is our choices, Harry, that show what we truly are, far more than our abilities." ) self.assertTrue( EducationGroupPublicationContact.objects.filter( education_group_year=self.current_education_group_year).exists( )) self.current_education_group_year.refresh_from_db() self.assertEqual( self.current_education_group_year.publication_contact_entity, publication_contact_entity) self.assertTrue( EducationGroupDetailedAchievement.objects.filter( education_group_achievement__education_group_year=self. current_education_group_year).exists()) self.assertTrue( AdmissionConditionLine.objects.get( admission_condition__education_group_year=self. current_education_group_year).section, "nothing else matters") def test_no_previous_education_group(self): postponer = ReddotEducationGroupAutomaticPostponement() postponer.postpone() self.assertEqual(len(postponer.result), 0) self.assertEqual(len(postponer.errors), 0)