def setUp(self): self.education_group_year = EducationGroupYearFactory() self.academic_responsible_1 = EducationGroupPublicationContactFactory( type=PublicationContactType.ACADEMIC_RESPONSIBLE.name, education_group_year=self.education_group_year, order=0) self.academic_responsible_2 = EducationGroupPublicationContactFactory( type=PublicationContactType.ACADEMIC_RESPONSIBLE.name, education_group_year=self.education_group_year, order=1)
def test_clean_case_role_not_specified_when_mandatory(self): publication_contact = EducationGroupPublicationContactFactory.build( type=PublicationContactType.JURY_MEMBER.name, role_fr='', role_en='') with self.assertRaises(ValidationError): publication_contact.clean()
def test_clean_case_role_specified_when_not_mandatory(self): publication_contact = EducationGroupPublicationContactFactory.build( type=PublicationContactType.ACADEMIC_RESPONSIBLE.name, role_fr='dummy role in french', role_en='dummy role in english') publication_contact.clean() self.assertEqual(publication_contact.role_fr, '') self.assertEqual(publication_contact.role_en, '')
def setUpTestData(cls): cls.data_to_serialize = {'id': 'ID', 'dummy': 'DUMMY'} cls.language = 'en' cls.egy = EducationGroupYearFactory() EducationGroupPublicationContactFactory(education_group_year=cls.egy) cls.serializer = ContactsSectionSerializer(cls.data_to_serialize, context={ 'egy': cls.egy, 'lang': cls.language })
def setUpTestData(cls): # Common offer must exist cls.academic_year = create_current_academic_year() EducationGroupYearCommonFactory(academic_year=cls.academic_year) cls.training = EducationGroupYearMasterFactory( academic_year=cls.academic_year, ) cls.publication_contact = EducationGroupPublicationContactFactory( education_group_year=cls.training, type=PublicationContactType.ACADEMIC_RESPONSIBLE.name ) # Create a central manager and linked it to entity of training cls.person = CentralManagerFactory("change_educationgroup", "can_access_education_group") PersonEntityFactory(person=cls.person, entity=cls.training.management_entity)
def setUpTestData(cls): cls.language = 'en' cls.egy = EducationGroupYearFactory() cls.contact = EducationGroupPublicationContactFactory( education_group_year=cls.egy) cls.annoted_contact = cls.egy.educationgrouppublicationcontact_set.all( ).annotate( description_or_none=Case(When(description__exact='', then=None), default=F('description'), output_field=CharField()), translated_role=Case(When(role_fr__exact='', then=None), default=F('role_fr'), output_field=CharField()), ).first() cls.serializer = ContactSerializer(cls.annoted_contact, context={'lang': cls.language})
def setUp(self): # Common offer must exist self.academic_year = create_current_academic_year() EducationGroupYearCommonFactory(academic_year=self.academic_year) self.training = TrainingFactory(academic_year=self.academic_year) self.publication_contact = EducationGroupPublicationContactFactory( education_group_year=self.training, type=PublicationContactType.ACADEMIC_RESPONSIBLE.name) # Create a central manager and linked it to entity of training self.person = CentralManagerFactory("change_educationgroup", "can_access_education_group") PersonEntityFactory(person=self.person, entity=self.training.management_entity) self.client.force_login(self.person.user)
class GetContactsGroupByTypesTestCase(TestCase): def setUp(self): self.education_group_year = EducationGroupYearFactory() self.academic_responsible_1 = EducationGroupPublicationContactFactory( type=PublicationContactType.ACADEMIC_RESPONSIBLE.name, education_group_year=self.education_group_year, order=0 ) self.academic_responsible_2 = EducationGroupPublicationContactFactory( type=PublicationContactType.ACADEMIC_RESPONSIBLE.name, education_group_year=self.education_group_year, order=1 ) def test_get_contacts_group_by_types_no_data(self): education_group_year = EducationGroupYearFactory() self.assertDictEqual( business.get_contacts_group_by_types(education_group_year, settings.LANGUAGE_CODE_FR), {} ) def test_get_contacts_group_by_types_assert_order(self): results = business.get_contacts_group_by_types(self.education_group_year, settings.LANGUAGE_CODE_FR) self.assertIsInstance(results, dict) self.assertTrue(results['academic_responsibles']) academic_responsibles = results['academic_responsibles'] self.assertIsInstance(academic_responsibles, list) self.assertEqual(len(academic_responsibles), 2) self.assertEqual(academic_responsibles[0]['email'], self.academic_responsible_1.email) self.assertEqual(academic_responsibles[1]['email'], self.academic_responsible_2.email) # Swap result... self.academic_responsible_2.up() results = business.get_contacts_group_by_types(self.education_group_year, settings.LANGUAGE_CODE_FR) academic_responsibles = results['academic_responsibles'] self.assertEqual(academic_responsibles[0]['email'], self.academic_responsible_2.email) self.assertEqual(academic_responsibles[1]['email'], self.academic_responsible_1.email) def test_get_contacts_group_by_types_assert_french_returned(self): results = business.get_contacts_group_by_types(self.education_group_year, settings.LANGUAGE_CODE_FR) academic_responsibles = results['academic_responsibles'] self.assertEqual(academic_responsibles[0]['role'], self.academic_responsible_1.role_fr) self.assertEqual(academic_responsibles[1]['role'], self.academic_responsible_2.role_fr) def test_get_contacts_group_by_types_assert_english_returned(self): results = business.get_contacts_group_by_types(self.education_group_year, settings.LANGUAGE_CODE_EN) academic_responsibles = results['academic_responsibles'] self.assertEqual(academic_responsibles[0]['role'], self.academic_responsible_1.role_en) self.assertEqual(academic_responsibles[1]['role'], self.academic_responsible_2.role_en) def test_get_contacts_group_by_types_assert_empty_str_as_null(self): self.academic_responsible_1.role_fr = '' self.academic_responsible_1.description = '' self.academic_responsible_1.save() results = business.get_contacts_group_by_types(self.education_group_year, settings.LANGUAGE_CODE_FR) academic_responsibles = results['academic_responsibles'] self.assertIsNone(academic_responsibles[0]['role']) self.assertIsNone(academic_responsibles[0]['description'])
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")