def test_models_course_run_copy_translations_one_language(self): """ The "copy_translations" method called for a specific language should only port parler's translations for this language from one course run to the other. """ course_run = CourseRunFactory(title="my title") CourseRunTranslation.objects.create(master=course_run, language_code="fr", title="mon titre") old_course_run = CourseRun.objects.get(pk=course_run.pk) self.assertEqual(CourseRunTranslation.objects.count(), 2) with switch_language(old_course_run, "fr"): self.assertEqual(old_course_run.title, "mon titre") course_run.pk = None course_run.save() self.assertEqual(CourseRunTranslation.objects.count(), 2) course_run.copy_translations(old_course_run, language="fr") self.assertEqual(CourseRun.objects.count(), 2) self.assertEqual(CourseRunTranslation.objects.count(), 3) self.assertEqual( CourseRunTranslation.objects.filter(master=course_run).count(), 1) course_run.refresh_from_db() self.assertEqual(course_run.title, "mon titre") # Fallback to french with switch_language(course_run, "fr"): self.assertEqual(course_run.title, "mon titre")
def test_models_course_run_copy_translations_all_languages(self): """ The "copy_translations" method should port parler's translations for all languages from one course run to the other. """ course_run = CourseRunFactory(title="my title") CourseRunTranslation.objects.create(master=course_run, language_code="fr", title="mon titre") old_course_run = CourseRun.objects.get(pk=course_run.pk) self.assertEqual(CourseRunTranslation.objects.count(), 2) with switch_language(old_course_run, "fr"): self.assertEqual(old_course_run.title, "mon titre") course_run.pk = None course_run.save() self.assertEqual(CourseRunTranslation.objects.count(), 2) course_run.copy_translations(old_course_run) self.assertEqual(CourseRun.objects.count(), 2) self.assertEqual(CourseRunTranslation.objects.count(), 4) self.assertEqual( CourseRunTranslation.objects.filter(master=course_run).count(), 2) course_run.refresh_from_db() self.assertEqual(course_run.title, "my title") with switch_language(course_run, "fr"): self.assertEqual(course_run.title, "mon titre")