예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    def setUp(self):
        self.provider = ModelFactories.get_provider_test_object(
            new_id=42)
        self.campus = ModelFactories.get_campus_test_object(
            new_id=420)

        campus_form_url = reverse(
            'edit-campus', args=(
                self.provider.id,
                self.campus.id))

        self.campus_form_url = f'{self.live_server_url}{campus_form_url}'
        # logged in first to access any other urls
        self.user = User.objects.create_user(
            'bobby2', '*****@*****.**', 'bob')
        self.client.login(username="******", password="******")
        # logged in, set session so the browser knows it has logged in
        cookie = self.client.cookies['sessionid']
        # selenium will set cookie domain based on current page domain
        self.driver.get(self.live_server_url + '/admin/')
        self.driver.add_cookie({
            'name': 'sessionid',
            'value': cookie.value,
            'secure': False,
            'path': '/'})
        # need to update page for logged in user
        self.driver.refresh()
        self.driver.get(self.live_server_url + '/admin/')
예제 #5
0
 def setUp(self):
     self.provider = ModelFactories.get_provider_test_object()
     self.fos = ModelFactories.get_field_of_study_test_object()
     self.data = {
         'name': 'Non-official Bachelor of Arts',
         'provider_id': self.provider.id,
         'fos_id': self.fos.id
     }
예제 #6
0
 def setUp(self):
     self.qualification = ModelFactories.get_qualification_test_object()
     self.empty_qualification = Qualification()
     self.requirement = ModelFactories.get_requirement_test_object()
     self.requirement.qualification = self.qualification
     self.requirement.save()
     self.qa = QualificationAudit(self.qualification)
     self.empty_qa = QualificationAudit(self.empty_qualification)
예제 #7
0
    def setUp(self):
        self.provider = ModelFactories.get_provider_test_object(new_id=42)
        self.campus = ModelFactories.get_campus_test_object(new_id=420)
        self.qualification = ModelFactories.get_qualification_test_object()
        self.qualification.campus = self.campus
        qualification_form_url = reverse('edit-qualification',
                                         args=(self.provider.id,
                                               self.campus.id,
                                               self.qualification.id))

        self.qualification_form_url = (
            f'{self.live_server_url}{qualification_form_url}')
예제 #8
0
    def setUp(self):
        self.url = reverse('create-saqa-qualification')
        self.provider = ModelFactories.get_provider_test_object()
        self.fos = ModelFactories.get_field_of_study_test_object()
        self.saqa_qualification_name = 'Master Degree in Wine and Champagne'

        self.data = {
            'saqa_qualification': {
                'saqa_qualification_name': self.saqa_qualification_name,
                'provider_id': self.provider.id,
                'fos_id': self.fos.id
            }
        }
예제 #9
0
    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))
예제 #10
0
    def setUp(self):
        self.campus = ModelFactories.get_campus_test_object()

        provider_url = reverse(
            'show-provider',
            args=[str(self.campus.provider.id)])

        self.driver.get(f'{self.live_server_url}{provider_url}')
예제 #11
0
 def test_audit_required_subjects(self):
     self.assertFalse(self.qa.audit_required_subjects())
     self.requirement.require_certain_subjects = True
     self.requirement.save()
     self.subject1 = (
         ModelFactories.get_qualification_entrance_requirement_to())
     self.subject1.qualification = self.qualification
     self.subject1.save()
     self.assertTrue(self.qa.audit_required_subjects())
예제 #12
0
 def setUp(self):
     self.campus = ModelFactories.get_campus_test_object()
     self.url = reverse('create-or-update-event',
                        args=[str(self.campus.id), 'campus'])
     self.data = {
         'name': 'TestName',
         'date_start': '2999-10-14',
         'date_end': '2999-10-15',
         'http_link': ''
     }
예제 #13
0
 def setUp(self):
     self.qualification = ModelFactories.get_qualification_test_object()
     self.url = reverse('create-or-update-event',
                        args=[str(self.qualification.id), 'qualification'])
     self.data = {
         'name': 'TestName',
         'date_start': '2999-10-14',
         'date_end': '2999-10-15',
         'http_link': ''
     }
예제 #14
0
    def test_is_new_provider(self):
        self.assertTrue(self.new_provider.is_new_provider)

        campus = ModelFactories.get_campus_test_object()
        campus.provider_id = self.new_provider.id
        campus.save()

        self.assertEqual(self.new_provider.id, campus.provider_id)

        self.assertFalse(self.new_provider.is_new_provider)
예제 #15
0
 def test_soft_delete_campus(self):
     self.qualification1 = ModelFactories.get_qualification_test_object()
     self.qualification1.campus = self.campus
     self.assertFalse(self.campus.deleted)
     self.assertFalse(self.qualification1.deleted)
     self.qualification1.save()
     self.campus.soft_delete()
     self.qualification1 = self.campus.qualification_set.first()
     self.assertTrue(self.campus.deleted)
     self.assertTrue(self.qualification1.deleted)
예제 #16
0
 def test_save_qualification_runs_audit(self):
     self.assertFalse(self.qualification.ready_to_publish)
     self.requirement.require_certain_subjects = True
     self.requirement.save()
     self.subject1 = (
         ModelFactories.get_qualification_entrance_requirement_to())
     self.subject1.qualification = self.qualification
     self.subject1.save()
     self.qualification.short_description = "Something"
     self.qualification.save()
     self.assertTrue(self.qualification.ready_to_publish)
예제 #17
0
    def setUp(self):

        self.campus_event = ModelFactories.get_campus_event_test_object()
        self.campus: Campus = self.campus_event.campus
        self.url = reverse('delete-event', args=['campus'])
        self.data = {
            'id': self.campus_event.id,
            'name': 'TestName',
            'date_start': '2999-04-14',
            'date_end': '2999-04-15',
            'http_link': ''
        }
예제 #18
0
    def test_create_duplicate_campus(self):
        provider = ModelFactories.get_provider_test_object()

        campus = Campus(name='My Campus', provider=provider)
        campus.save()

        with self.assertRaisesMessage(ValidationError,
                                      'Name is already taken'):
            campus_2 = Campus(name='My Campus', provider=provider)
            campus_2.save()

        provider_2 = ModelFactories.get_provider_test_object()
        campus_3 = Campus(name='My Campus', provider=provider_2)
        campus_3.save()

        self.assertEqual(campus.name, 'My Campus')
        self.assertEqual(campus_3.name, 'My Campus')

        with self.assertRaisesMessage(ValidationError,
                                      'Name is already taken'):
            campus_4 = Campus(name='my campus', provider=provider)
            campus_4.save()
예제 #19
0
 def setUp(self):
     self.qualification = ModelFactories.get_qualification_test_object()
     self.wizard_url = reverse(
         'edit-qualification',
         args=(
             self.qualification.campus.provider.id,
             self.qualification.campus.id,
             self.qualification.id))
     self.user = User.objects.get(pk=3)
     self.user.set_password(self.user.password)
     self.qualification_data_process = QualificationFormWizardDataProcess(
         qualification=self.qualification,
         edited_by=self.user
     )
예제 #20
0
    def setUp(self):

        self.qualification_event = (
            ModelFactories.get_qualification_event_test_object())
        self.qualification: Qualification = (
            self.qualification_event.qualification)
        self.url = reverse('delete-event', args=['qualification'])
        self.data = {
            'id': self.qualification_event.id,
            'name': 'TestName',
            'date_start': '2999-04-14',
            'date_end': '2999-04-15',
            'http_link': ''
        }
예제 #21
0
    def test_create_non_accredited_saqa_qualification_with_subfield(self):
        self.assertEqual(len(SAQAQualification.objects.all()), 0)

        sfos = ModelFactories.get_sub_field_of_study_test_object()
        self.data['fos_id'] = sfos.field_of_study.id
        self.data['sfos_id'] = sfos.id
        saqa_qualif = SAQAQualification.create_non_accredited(self.data)

        self.assertFalse(saqa_qualif.accredited)
        self.assertEqual(saqa_qualif.creator_provider_id, self.provider.id)

        self.assertEqual(saqa_qualif.field_of_study_id, sfos.field_of_study.id)
        self.assertEqual(saqa_qualif.sub_field_of_study_id, sfos.id)

        self.assertEqual(len(SAQAQualification.objects.all()), 1)
예제 #22
0
    def setUp(self):
        self.campus = ModelFactories.get_campus_test_object()
        self.provider = self.campus.provider

        self.requirement_subject = ModelFactories.get_qualification_entrance_requirement_to(
        )  # noqa
        self.qualification = self.requirement_subject.qualification

        self.qualification.campus = self.campus
        self.qualification.provider = self.provider
        self.qualification.save()

        output_data = providerView.excel_dump(self.provider.id)
        named_tempfile = NamedTemporaryFile(suffix='.xlsx')

        with open(named_tempfile.name, 'wb') as file:
            file.write(output_data)

        excel = SmartExcel(
            definition=OPENEDU_EXCEL_DEFINITION,
            data=OpenEduSmartExcelData(provider_id=self.provider.id),
            path=named_tempfile.name)
        # provider.dump(None, provider.id)
        self.data = excel.parse()
예제 #23
0
    def setUp(self):
        self.client = Client()
        self.user = User.objects.create_user(
            '*****@*****.**', 'password', is_provider=True, is_active=True)
        self.user.groups.add(Group.objects.get(name='PROVIDER-ADMINS'))
        self.user.user_permissions.add(
            Permission.objects.get(codename='add_campus'))

        self.provider = ModelFactories.get_provider_test_object()
        self.provider.created_by = self.user
        self.provider.save()
        self.url = reverse('create-campus', args=[str(self.provider.id)])

        self.data = {
            'campus_name': 'My Campus'
        }
        self.client.login(
            email=self.user.email,
            password='******')
예제 #24
0
 def setUp(self):
     self.provider = ModelFactories.get_provider_test_object()
     self.campus1 = ModelFactories.get_campus_test_object()
     self.campus2 = ModelFactories.get_campus_test_object()
     self.qualification1 = ModelFactories.get_qualification_test_object()
     self.qualification2 = ModelFactories.get_qualification_test_object()
     self.qualification3 = ModelFactories.get_qualification_test_object()
     self.campus1.provider = self.provider
     self.campus2.provider = self.provider
     self.qualification1.campus = self.campus1
     self.qualification2.campus = self.campus2
     self.qualification3.campus = self.campus2
     self.campus1.save()
     self.campus2.save()
     self.qualification1.save()
     self.qualification2.save()
     self.qualification3.save()
 def test_secondary_institution_type_name(self):
     new_secondary_institution_type = (
         ModelFactories.get_secondary_institution_type_test_object())
     self.assertEqual(new_secondary_institution_type.__str__(),
                      'Object Test Name')
예제 #26
0
 def setUp(self):
     self.campus = ModelFactories.get_campus_test_object(new_id=420)
예제 #27
0
 def setUp(self):
     self.campus = ModelFactories.get_campus_test_object(new_id=420)
     self.user = User.objects.get(pk=3)
예제 #28
0
    def test_create_campus(self):
        provider = ModelFactories.get_provider_test_object()

        provider.campus_set.create(name='My Campus')

        self.assertEqual(Campus.objects.count(), 1)
예제 #29
0
 def setUp(self):
     self.provider = ModelFactories.get_provider_test_object()
     self.url = reverse('show-providers-api', kwargs={'version': 'v1'})
예제 #30
0
    def test_campus_page_add_events_empty_date(self):
        campus_object = Campus.objects.all().first()
        if len(str(campus_object)) > 0:
            pass
        else:
            campus_object = ModelFactories.get_campus_test_object()
        self.driver.get(self.campus_form_url)

        # User sees the first page's title
        title = self.driver.find_element_by_tag_name('h2').text
        self.assertIn('Campus Details', title)
        # and the footer shows him what page he is on
        self.assert_footer('Page 1 of')
        # User clicks next
        self.get_next_button().click()
        # User sees they are on the 2nd page from the footer
        self.assert_footer('Page 2 of')
        # User clicks next
        self.get_next_button().click()
        # User sees they are on the 3rd page from the footer
        self.assert_footer('Page 3 of')
        # User sees the 4 form fields - 1 of each and there are 2 hidden inputs
        form_content = self.driver.find_element_by_css_selector(
            '.form-group')
        # Get inputs
        form_inputs = form_content.find_elements_by_tag_name('input')
        self.assertEqual(len(form_inputs), 6)  # 4 form fields + 2 hidden
        self.driver.find_element_by_id(
            'add-campus-event').click()
        form_inputs = form_content.find_elements_by_tag_name('input')
        self.assertEqual(len(form_inputs), 10)  # The existing 6 + 4 new
        # There should now be 2 of each input
        name_inputs = form_content.find_elements_by_name(
            'campus-dates-event_name')
        self.assertEqual(len(name_inputs), 2)
        date_start_inputs = form_content.find_elements_by_name(
            'campus-dates-date_start')
        self.assertEqual(len(date_start_inputs), 2)
        date_end_inputs = form_content.find_elements_by_name(
            'campus-dates-date_end')
        self.assertEqual(len(date_end_inputs), 2)
        http_link_inputs = form_content.find_elements_by_name(
            'campus-dates-http_link')
        self.assertEqual(len(http_link_inputs), 2)
        # The user fills in the data for each field
        name1 = 'Sel Test Name 1'
        name2 = 'Sel Test Name 2'
        name_inputs[0].send_keys(name1)
        date_start_inputs[0].send_keys('04/09/2019')
        date_end_inputs[0].send_keys('05/09/2019')
        http_link_inputs[0].send_keys('*****@*****.**')
        name_inputs[1].send_keys(name2)
        date_start_inputs[1].send_keys('07/11/2119')
        date_end_inputs[1].send_keys('')
        http_link_inputs[1].send_keys('*****@*****.**')
        # They click next
        self.get_next_button().click()
        # The form responds with a validation error
        self.assertIn(self.driver.title, 'FORD3')
        validation_message = self.driver.find_elements_by_name(
            'campus-dates-date_end')[1].get_attribute('validationMessage')
        self.assertEqual(validation_message, 'Please fill out this field.')