def test_learning_achievement_edit(self): learning_achievement = LearningAchievementFactory( learning_unit_year=self.learning_unit_year) self.client.force_login(self.a_superuser) response = self.client.get( reverse('achievement_edit', args=[self.learning_unit_year.id, learning_achievement.id]), data={'achievement_id': learning_achievement.id}) self.assertTemplateUsed(response, 'learning_unit/achievement_edit.html') self.assertIsInstance(response.context['form'], LearningAchievementEditForm)
def test_learning_achievement_save_triggers_cms_save( self, mock_translated_text_update_or_create): learning_achievement = LearningAchievementFactory( learning_unit_year=self.learning_unit_year, language=self.language_fr) learning_achievement_en = LearningAchievementFactory( learning_unit_year=self.learning_unit_year, language=self.language_en) TextLabelFactory(label='themes_discussed') self.client.post(reverse('achievement_edit', kwargs={ 'learning_unit_year_id': self.learning_unit_year.id, 'learning_achievement_id': learning_achievement.id }), data={ 'code_name': 'AA1', 'text_fr': 'Text', 'lua_fr_id': learning_achievement.id, 'lua_en_id': learning_achievement_en.id }) self.assertTrue(mock_translated_text_update_or_create.called)
def test_learning_achievement_create(self): achievement_fr = LearningAchievementFactory(language=self.language_fr, learning_unit_year=self.learning_unit_year) self.client.force_login(self.a_superuser) response = self.client.get(reverse('achievement_create', args=[self.learning_unit_year.id, achievement_fr.id]), data={'language_code': self.language_fr.code}) self.assertTemplateUsed(response, 'learning_unit/achievement_edit.html') context = response.context self.assertIsInstance(context['form'], LearningAchievementEditForm) self.assertEqual(context['learning_unit_year'], self.learning_unit_year) self.assertEqual(context['language_code'], self.language_fr.code) self.assertTrue(context['create'], self.language_fr.code)
def test_find_learning_unit_achievement(self): luy_achievement_fr_1 = LearningAchievementFactory( code_name=A_CODE_NAME, learning_unit_year=self.luy, language=self.language_fr) self.assertEqual( learning_achievement.find_learning_unit_achievement( luy_achievement_fr_1.consistency_id, luy_achievement_fr_1.learning_unit_year, luy_achievement_fr_1.language.code, 0), luy_achievement_fr_1) self.assertIsNone( learning_achievement.find_learning_unit_achievement( luy_achievement_fr_1.consistency_id, luy_achievement_fr_1.learning_unit_year, luy_achievement_fr_1.language.code, 100))
def test_learning_achievement_edit(self, mock_render): learning_achievement = LearningAchievementFactory( learning_unit_year=self.learning_unit_year) request_factory = RequestFactory() request = request_factory.get( reverse('learning_unit', args=[self.learning_unit_year.id]), data={'achievement_id': learning_achievement.id}) request.user = self.a_superuser update(request, self.learning_unit_year.id, learning_achievement.id) self.assertTrue(mock_render.called) request, template, context = mock_render.call_args[0] self.assertEqual(template, 'learning_unit/achievement_edit.html') self.assertIsInstance(context['form'], LearningAchievementEditForm)
def test_learning_achievement_create(self, mock_render): achievement_fr = LearningAchievementFactory( language=self.language_fr, learning_unit_year=self.learning_unit_year) request_factory = RequestFactory() request = request_factory.get( reverse('learning_unit', args=[self.learning_unit_year.id]), data={'language_code': self.language_fr.code}) request.user = self.a_superuser create(request, self.learning_unit_year.id, achievement_fr.id) self.assertTrue(mock_render.called) request, template, context = mock_render.call_args[0] self.assertEqual(template, 'learning_unit/achievement_edit.html') self.assertIsInstance(context['form'], LearningAchievementEditForm) self.assertEqual(context['learning_unit_year'], self.learning_unit_year) self.assertEqual(context['language_code'], self.language_fr.code) self.assertTrue(context['create'], self.language_fr.code)
def setUpTestData(cls): cls.academic_year = AcademicYearFactory(year=2018) cls.learning_unit_year = LearningUnitYearFactory( academic_year=cls.academic_year, learning_container_year__academic_year=cls.academic_year) cls.achievements = [] for index in range(0, 5): cls.achievements.append( LearningAchievementFactory( learning_unit_year=cls.learning_unit_year, language__code=FR_CODE_LANGUAGE, order=index)) cls.person = PersonFactory() url_kwargs = { 'acronym': cls.learning_unit_year.acronym, 'year': cls.learning_unit_year.academic_year.year } cls.url = reverse('learning_unit_api_v1:' + LearningAchievementList.name, kwargs=url_kwargs)
def setUp(self): self.academic_year = create_current_academic_year() self.learning_unit_year = LearningUnitYearFactory( academic_year=self.academic_year, subtype=learning_unit_year_subtypes.FULL ) self.language_fr = LanguageFactory(code="FR") self.user = UserFactory() self.person = PersonFactory(user=self.user) self.person_entity = PersonEntityFactory(person=self.person) EntityContainerYearFactory(learning_container_year=self.learning_unit_year.learning_container_year, entity=self.person_entity.entity, type=entity_container_year_link_type.REQUIREMENT_ENTITY) self.client.force_login(self.user) self.achievement_fr = LearningAchievementFactory(language=self.language_fr, learning_unit_year=self.learning_unit_year, order=0) self.reverse_learning_unit_yr = reverse('learning_unit', args=[self.learning_unit_year.id]) flag, created = Flag.objects.get_or_create(name='learning_achievement_update') flag.users.add(self.user)
def test_learning_achievement_save(self): learning_achievement = LearningAchievementFactory( learning_unit_year=self.learning_unit_year, language=self.language_fr) response = self.client.post(reverse('achievement_edit', kwargs={ 'learning_unit_year_id': self.learning_unit_year.id, 'learning_achievement_id': learning_achievement.id }), data={ 'code_name': 'AA1', 'text': 'Text' }) expected_redirection = reverse( "learning_unit_specifications", kwargs={'learning_unit_year_id': self.learning_unit_year.id }) + "{}{}".format(HTML_ANCHOR, learning_achievement.id) self.assertRedirects(response, expected_redirection, fetch_redirect_response=False)
def test_unique(self): LearningAchievementFactory(code_name=A_CODE_NAME, learning_unit_year=self.luy, language=self.language_fr) with self.assertRaises(IntegrityError): LearningAchievementFactory(code_name=A_CODE_NAME, learning_unit_year=self.luy, language=self.language_fr)
def _create_ordered_achievements(self, ids): for luy, id, lang in itertools.product(self.learning_unit_years, ids, [self.language_fr, self.language_en]): LearningAchievementFactory(consistency_id=id, learning_unit_year=luy, language=lang, order=id-1)
def test_learning_achievement_create_first_existing_learning_achievement_in_future(self): future_achievement = LearningAchievementFactory(learning_unit_year=self.future_luy) response = self.client.get(reverse('achievement_create_first', args=[self.luy.id])) self.assertTemplateUsed(response, 'learning_unit/achievement_edit.html') self.assertIsInstance(response.context['form'], LearningAchievementEditForm) self.assertEqual(response.context['form'].consistency_id, future_achievement.consistency_id+1)