def test_case_update_correctly_saved(self): learning_unit_to_update = LearningUnitFactory(learning_container=self.learning_container, start_year=self.current_academic_year.year) self.form = LearningUnitModelForm(self.post_data, instance=learning_unit_to_update) self.assertTrue(self.form.is_valid(), self.form.errors) lu = self.form.save(**self.save_kwargs) self.assertEqual(lu.faculty_remark, self.quote_1) self.assertEqual(lu.other_remark, self.quote_2)
class TestLearningUnitModelFormSave(TestCase): """Tests LearningUnitModelForm.save()""" quote_1 = """Many that live deserve death. And some that die deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement.""" quote_2 = """And then her heart changed, or at least she understood it; and the winter passed, and the sun shone upon her.""" post_data = {'faculty_remark': quote_1, 'other_remark': quote_2} @classmethod def setUpTestData(cls): cls.current_academic_year = create_current_academic_year() cls.learning_container = LearningContainerFactory() cls.form = LearningUnitModelForm(cls.post_data) cls.save_kwargs = { 'learning_container': cls.learning_container, 'start_year': cls.current_academic_year } def test_case_missing_learning_container_kwarg(self): with self.assertRaises(KeyError): self.form.save(academic_year=self.current_academic_year) def test_case_missing_academic_year_kwarg(self): with self.assertRaises(KeyError): self.form.save(learning_container=self.learning_container) def test_case_creation_correctly_saved(self): self.assertTrue(self.form.is_valid(), self.form.errors) lu = self.form.save(**self.save_kwargs) self.assertEqual(lu.faculty_remark, self.quote_1) self.assertEqual(lu.other_remark, self.quote_2) def test_case_update_correctly_saved(self): learning_unit_to_update = LearningUnitFactory( learning_container=self.learning_container, start_year=self.current_academic_year) self.form = LearningUnitModelForm(self.post_data, instance=learning_unit_to_update) self.assertTrue(self.form.is_valid(), self.form.errors) lu = self.form.save(**self.save_kwargs) self.assertEqual(lu.faculty_remark, self.quote_1) self.assertEqual(lu.other_remark, self.quote_2)
def setUpTestData(cls): cls.current_academic_year = create_current_academic_year() cls.learning_container = LearningContainerFactory() cls.form = LearningUnitModelForm(cls.post_data) cls.save_kwargs = { 'learning_container': cls.learning_container, 'start_year': cls.current_academic_year }
def test_partim_periodicity_biannual_with_parent_annual(self): a_new_learning_unit_partim = LearningUnitYearFactory( academic_year=self.current_academic_year, acronym=FULL_ACRONYM + 'W', subtype=learning_unit_year_subtypes.PARTIM, credits=0, learning_container_year=self.learning_unit_year_full. learning_container_year, ) a_new_learning_unit_partim.learning_unit.learning_container = \ self.learning_unit_year_full.learning_unit.learning_container a_new_learning_unit_partim.learning_unit.save() self.learning_unit_year_full.learning_unit.periodicity = ANNUAL self.learning_unit_year_full.learning_unit.save() post_data = get_valid_form_data(a_new_learning_unit_partim) post_data['periodicity'] = BIENNIAL_EVEN form = LearningUnitModelForm( data=post_data, instance=a_new_learning_unit_partim.learning_unit) # The form should be valid self.assertTrue(form.is_valid(), form.errors)
def setUpTestData(cls): cls.form = LearningUnitModelForm()
def setUp(self): self.current_academic_year = create_current_academic_year() self.learning_container = LearningContainerFactory() self.form = LearningUnitModelForm(self.post_data) self.save_kwargs = {'learning_container': self.learning_container, 'start_year': self.current_academic_year.year}
def setUp(self): self.form = LearningUnitModelForm()