def test_save_qualifications_duplicate(self): """ It should not save a duplicate qualification. """ saqas = [ ModelFactories.get_saqa_qualification_test_object(), SAQAQualification.objects.create( name='Hello World', nqf_level='42', saqa_id=42, sub_field_of_study=( ModelFactories.get_sub_field_of_study_test_object( new_id=42)), ) ] # build form data form_data = {'saqa_ids': '{}'.format(saqas[0].id)} # save two times with same saqa_ids self.campus.save_qualifications(form_data, self.user) self.campus.save_qualifications(form_data, self.user) self.assertEqual(len(self.campus.qualifications), 1) form_data = {'saqa_ids': '{} {}'.format(saqas[0].id, saqas[1].id)} # save with a new saqa_id self.campus.save_qualifications(form_data, self.user) self.assertEqual(len(self.campus.qualifications), 2)
def test_save_qualifications(self): # create two SAQA Qualifications saqas = [ ModelFactories.get_saqa_qualification_test_object(), SAQAQualification.objects.create( name='Hello World', nqf_level='42', saqa_id=42, sub_field_of_study=( ModelFactories.get_sub_field_of_study_test_object( new_id=42)), ) ] # build form data form_data = {'saqa_ids': '{} {}'.format(saqas[0].id, saqas[1].id)} # campus should not have qualifications yet. self.assertQuerysetEqual(self.campus.qualifications, []) # save qualifications self.campus.save_qualifications(form_data, self.user) # campus should have 2 qualifications. self.assertEqual(len(self.campus.qualifications), 2)
def test_delete_qualifications(self): saqas = [ ModelFactories.get_saqa_qualification_test_object(), SAQAQualification.objects.create( name='Hello World', nqf_level='42', saqa_id=42, sub_field_of_study=( ModelFactories.get_sub_field_of_study_test_object( new_id=42)), ) ] # build form data form_data = {'saqa_ids': '{} {}'.format(saqas[0].id, saqas[1].id)} self.campus.save_qualifications(form_data, self.user) self.assertEqual(len(self.campus.qualifications), 2) # add those two qualifications to another campus self.other_campus = ModelFactories.get_campus_test_object(new_id=421) self.other_campus.save_qualifications(form_data, self.user) form_data = {'saqa_ids': '{}'.format(saqas[1].id)} # it should remove the first saqa for the first campus. self.campus.delete_qualifications(form_data) self.assertEqual(len(self.campus.qualifications), 1) self.assertEqual( self.campus.qualifications[0]['saqa_qualification__saqa_id'], 42) # it should not remove qualifications for the second campus. self.assertEqual(len(self.other_campus.qualifications), 2)
def test_form_qualifications(self): """ It should list already selected qualifications. """ saqa = ModelFactories.get_saqa_qualification_test_object() form_data = { 'saqa_ids': f'{saqa.id}' } self.campus.save_qualifications(form_data) # go to step 4 self.driver.get(self.campus_form_url) next_step_button = self.driver.find_element_by_id('my-next-button') next_step_button.click() next_step_button = self.driver.find_element_by_id('my-next-button') next_step_button.click() next_step_button = self.driver.find_element_by_id('my-next-button') next_step_button.click() qualif_list_ul = self.driver.find_element_by_id( 'campus-qualifications-list') qualif_li = qualif_list_ul.find_elements(By.CLASS_NAME, 'qualif-li') self.assertEqual(len(qualif_li), 1) saqa_ids_elem = self.driver.find_element_by_id( 'id_campus-qualifications-saqa_ids') saqa_ids_value = saqa_ids_elem.get_attribute('value') self.assertEqual(saqa_ids_value, str(saqa.id))
def setUp(self): self.saqa = ModelFactories.get_saqa_qualification_test_object()
def test_saqa_qualification_description(self): new_saqa_qualification = ( ModelFactories.get_saqa_qualification_test_object()) self.assertEqual( new_saqa_qualification.__str__(), 'SAQAQualification name')