Exemple #1
0
    def test_change_staff_roles(self):
        # Register a supervisor
        create_new_user("Yeesha", "Woozles", user_type=SUPERVISOR)

        # Login as the supervisor
        token = log_in(self.client, "Yeesha", "Woozles")

        staff_response = self.client.post(
            "/api/auth/staff_roles/",
            json.dumps({'new_user_roles': {
                'Heffalumps': SUPERVISOR
            }}),
            HTTP_AUTHORIZATION='JWT {}'.format(token),
            content_type="application/json")

        self.assertEquals(staff_response.status_code, 400)

        # Login as the admin
        token = log_in(self.client, "Heffalumps", "Woozles")

        staff_response = self.client.post(
            "/api/auth/staff_roles/",
            json.dumps({'new_user_roles': {
                'Yeesha': ADMIN
            }}),
            HTTP_AUTHORIZATION='JWT {}'.format(token),
            content_type="application/json")

        self.assertEquals(staff_response.status_code, 200)
    def test_download_csv(self):
        # Log in as the admin
        token = log_in(self.client, "Heffalumps", "Woozles")

        # Register two supervisors
        create_new_user("Atrus1", "Woozles", user_type=SUPERVISOR)
        create_new_user("Atrus2", "Woozles", user_type=SUPERVISOR)

        # New application
        create_new_application(
            token,
            create_application_details(self.academic_year.id,
                                       registry_ref="01",
                                       supervisors=['Atrus1', 'Atrus2']),
            self.client)

        application = Application.objects.filter(registry_ref="01").first()
        download_response = self.client.get(
            "/api/phd/csv_download/", {
                "token": token,
                "application_ids": [application.id],
                "sort_field": "registry_ref",
                "sort_by": "DESC",
                "selected_fields": ["registry_ref", "forename"]
            })
        self.assertEquals(download_response.get('Content-Type'), 'text/csv')
    def test_get_recommended_supervisors(self):
        # Register supervisor
        create_new_user("Yeesha", "Woozles", user_type=SUPERVISOR)
        create_new_user("Pluto", "Woozles", user_type=SUPERVISOR)

        # Login as the admin
        token = log_in(self.client, "Heffalumps", "Woozles")

        create_new_application(token, create_application_details(registry_ref="015243",
                                                                 academic_year_id=self.academic_year.id,
                                                                 supervisors=['Yeesha'],
                                                                 tags=['Porsche']), self.client)

        create_new_application(token, create_application_details(registry_ref="767575",
                                                                 academic_year_id=self.academic_year.id,
                                                                 supervisors=['Yeesha', 'Pluto'],
                                                                 tags=['Porsche', 'Ferrari']), self.client)

        recommended_supervisors_response = self.client.get(path="/api/phd/recommended_supervisors/",
                                                           data={'tags': ['Porsche', 'Ferrari']},
                                                           HTTP_AUTHORIZATION='JWT {}'.format(token))

        self.assertEqual(recommended_supervisors_response.status_code, 200)
        response_content = json.loads(recommended_supervisors_response.content.decode('utf-8'))
        self.assertEqual(len(response_content), 2)
        self.assertEqual(response_content[0]['total'], 2)
        self.assertEqual(response_content[0]['username'], 'Yeesha')
    def setUp(self):

        # New admin user
        create_new_user("Heffalumps", "Woozles")

        # New academic year
        self.academic_year = AcademicYear.objects.create(name="17/18", start_date=timezone.now(),
                                                         end_date=timezone.now(), default=True)
    def test_download_zip(self):
        # Log in as the admin
        token = log_in(self.client, "Heffalumps", "Woozles")

        # Register two supervisors
        create_new_user("Atrus1", "Woozles", user_type=SUPERVISOR)
        create_new_user("Atrus2", "Woozles", user_type=SUPERVISOR)

        # New application
        create_new_application(
            token,
            create_application_details(self.academic_year.id,
                                       registry_ref="01",
                                       supervisors=['Atrus1', 'Atrus2']),
            self.client)

        # Log in as Atrus1
        token = log_in(self.client, "Atrus1", "Woozles")

        # POST new file
        application = Application.objects.filter(registry_ref="01").first()
        supervision = application.supervisions.filter(
            supervisor__username="******").first()
        request_details = json.dumps({
            "supervision_id": supervision.id,
            "file_descriptions": {
                'APPLICATION_FORM_1': 'This is my description.'
            }
        })

        with open('phdadmissions/tests/test_file.pdf') as fp:
            self.client.post(
                '/api/phd/file/',
                {
                    'details': request_details,
                    'APPLICATION_FORM_1': fp
                },
                HTTP_AUTHORIZATION='JWT {}'.format(token),
            )

        download_response = self.client.get(
            "/api/phd/zip_download/", {
                "token": token,
                "application_ids": [application.id],
                "sort_field": "registry_ref",
                "sort_by": "DESC",
                "selected_fields": ["registry_ref", "forename"]
            })
        self.assertEquals(download_response.get('Content-Type'),
                          'application/x-zip-compressed')
Exemple #6
0
    def test_get_supervisor_staff_members(self):
        # Register supervisors
        create_new_user("Yeesha", "Woozles", user_type=SUPERVISOR)
        create_new_user("Yeesah2", "Woozles", user_type=SUPERVISOR)

        # Login as the admin
        token = log_in(self.client, "Heffalumps", "Woozles")

        staff_response = self.client.get(
            path="/api/auth/supervisor_staff/",
            HTTP_AUTHORIZATION='JWT {}'.format(token))
        staff_response_content = json.loads(
            staff_response.content.decode('utf-8'))

        self.assertEqual(len(staff_response_content), 2,
                         "There should be 2 supervisors in the system.")
    def test_get_email_preview(self):
        # Log in as the admin
        token = log_in(self.client, "Heffalumps", "Woozles")

        # New application
        create_new_application(
            token,
            create_application_details(self.academic_year.id,
                                       supervisors=[],
                                       registry_ref="012345"), self.client)
        latest_application = Application.objects.latest(
            field_name="created_at")

        # Register a supervisor
        create_new_user("Atrus1", "Woozles", user_type=SUPERVISOR)
        supervisor = User.objects.get(username="******")
        supervisor.first_name = "Atrus"
        supervisor.last_name = "Venus"
        supervisor.save()

        # Add supervision
        new_supervision = Supervision.objects.create(
            application=latest_application, supervisor=supervisor)

        # Get the email preview
        email_preview_response = self.client.post(
            "/api/phd/admin/email_preview/", {
                "email_template":
                """"<b>Dear Chanapata</b><hr><p>{{supervisor_first_name}} {{supervisor_last_name}}
                                {{registry_ref}}""",
                "supervision_id": new_supervision.id
            },
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        response_content = email_preview_response
        self.assertContains(response_content, latest_application.registry_ref)
        self.assertContains(response_content, supervisor.first_name)
        self.assertContains(response_content, supervisor.last_name)

        # Get the email preview without a template
        email_preview_response = self.client.post(
            "/api/phd/admin/email_preview/", {"email_template": ""},
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        response_content = email_preview_response
        self.assertEquals(response_content.status_code, 200)
Exemple #8
0
    def test_get_supervisor_usernames(self):
        # Register supervisor
        create_new_user("Yeesha", "Woozles", user_type=SUPERVISOR)

        # Login as the admin
        token = log_in(self.client, "Heffalumps", "Woozles")

        supervisor_response = self.client.get(
            path="/api/auth/supervisor_usernames/",
            data={},
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        self.assertEqual(supervisor_response.status_code, 200)

        statistics_response_content = json.loads(
            supervisor_response.content.decode('utf-8'))
        self.assertEqual(len(statistics_response_content["usernames"]), 1)
        self.assertEqual(statistics_response_content["usernames"][0], "Yeesha")
    def test_send_email(self):
        # Log in as the admin
        token = log_in(self.client, "Heffalumps", "Woozles")

        # New application
        create_new_application(
            token,
            create_application_details(self.academic_year.id,
                                       supervisors=[],
                                       registry_ref="012345"), self.client)
        latest_application = Application.objects.latest(
            field_name="created_at")

        # Register a supervisor
        create_new_user("Atrus1",
                        "Woozles",
                        user_type=SUPERVISOR,
                        email="*****@*****.**")
        supervisor = User.objects.get(username="******")

        # Add supervision
        new_supervision = Supervision.objects.create(
            application=latest_application, supervisor=supervisor)

        # Attempt to send the email with missing arguments
        email_send_response = self.client.post(
            "/api/phd/admin/email_send/",
            {"supervision_id": new_supervision.id},
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        self.assertEquals(email_send_response.status_code, 400)

        # Attempt to send the email with missing arguments
        email_send_response = self.client.post(
            "/api/phd/admin/email_send/", {"email_template": ""},
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        self.assertEquals(email_send_response.status_code, 400)
    def test_new_phd_application(self):
        # Log in as the admin
        token = log_in(self.client, "Heffalumps", "Woozles")

        # Register two supervisors
        create_new_user("Atrus1", "Woozles", user_type=SUPERVISOR)
        create_new_user("Atrus2", "Woozles", user_type=SUPERVISOR)

        # New application
        create_new_application(
            token,
            create_application_details(self.academic_year.id,
                                       registry_ref="01",
                                       supervisors=['Atrus1', 'Atrus2']),
            self.client)

        # Log in as Atrus1
        token = log_in(self.client, "Atrus1", "Woozles")

        # POST new file
        application = Application.objects.filter(registry_ref="01").first()
        supervision = application.supervisions.filter(
            supervisor__username="******").first()
        request_details = json.dumps({
            "supervision_id": supervision.id,
            "file_descriptions": {
                'APPLICATION_FORM_1': 'This is my description.'
            }
        })

        with open('phdadmissions/tests/test_file.pdf') as fp:
            file_response = self.client.post(
                '/api/phd/file/',
                {
                    'details': request_details,
                    'APPLICATION_FORM_1': fp
                },
                HTTP_AUTHORIZATION='JWT {}'.format(token),
            )
            self.assertEqual(file_response.status_code, 201)
            fp.close()

        supervision = application.supervisions.filter(
            supervisor__username="******").first()
        self.assertEqual(supervision.documentations.count(), 1)
        documentation = supervision.documentations.first()
        self.assertEqual(documentation.file_type, APPLICATION_FORM)
        self.assertEqual(documentation.description, 'This is my description.')

        # Download the file
        download_response = self.client.get("/api/phd/download/", {
            "id": documentation.id,
            "token": token
        })
        self.assertEquals(download_response.get('Content-Disposition'),
                          'attachment; filename=' + documentation.file_name)

        # DELETE file
        delete_file_response = self.client.delete(
            path="/api/phd/file/",
            data=json.dumps({"file_id": documentation.id}),
            HTTP_AUTHORIZATION='JWT {}'.format(token),
            content_type='application/json')

        self.assertEqual(delete_file_response.status_code, 204)
        supervision = application.supervisions.filter(
            supervisor__username="******").first()
        self.assertEqual(supervision.documentations.count(), 0)
    def test_add_and_delete_supervision(self):

        # Log in as the admin
        token = log_in(self.client, "Heffalumps", "Woozles")

        # Register a supervisor
        create_new_user("Atrus1", "Woozles", user_type=SUPERVISOR)

        # New application
        create_new_application(
            token,
            create_application_details(self.academic_year.id, supervisors=[]),
            self.client)
        latest_application = Application.objects.latest(
            field_name="created_at")

        # Add supervision
        new_supervision_response = self.client.post(
            "/api/phd/supervision/", {
                "id": latest_application.id,
                "supervisor": "Atrus1"
            },
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        self.assertEqual(new_supervision_response.status_code, 200)

        response_content = json.loads(
            new_supervision_response.content.decode('utf-8'))
        self.assertEqual(response_content["supervisor"]["username"], "Atrus1")

        latest_application = Application.objects.latest(
            field_name="created_at")
        supervisions = latest_application.supervisions.all()
        self.assertEqual(
            len(supervisions), 2,
            "We expect 2 supervisions, because one belongs to the admins.")

        # Allocate supervision
        self.assertEqual(response_content["allocated"], False)
        supervision_id = response_content["id"]
        self.client.post("/api/phd/supervision_allocation/",
                         {"supervision_id": supervision_id},
                         HTTP_AUTHORIZATION='JWT {}'.format(token))

        supervision = Supervision.objects.filter(id=supervision_id).first()
        self.assertEqual(supervision.allocated, True)

        post_data = json.dumps({"supervision_id": supervision_id})
        self.client.delete("/api/phd/supervision_allocation/",
                           data=post_data,
                           HTTP_AUTHORIZATION='JWT {}'.format(token))

        supervision = Supervision.objects.filter(id=supervision_id).first()
        self.assertEqual(supervision.allocated, False)

        # Delete supervision
        post_data = json.dumps({
            "id":
            latest_application.id,
            "supervisor":
            "Atrus1",
            "supervision_id":
            supervisions.filter(type=SUPERVISOR).first().id
        })
        self.client.delete("/api/phd/supervision/",
                           data=post_data,
                           HTTP_AUTHORIZATION='JWT {}'.format(token))

        latest_application = Application.objects.latest(
            field_name="created_at")
        supervisions = latest_application.supervisions.all()
        self.assertEqual(len(supervisions), 1)
    def test_new_phd_application(self):

        # Log in as the admin
        token = log_in(self.client, "Heffalumps", "Woozles")

        # Register two supervisors
        create_new_user("Atrus1", "Woozles", user_type=SUPERVISOR)
        create_new_user("Atrus2", "Woozles", user_type=SUPERVISOR)

        # New application
        new_application_response = create_new_application(
            token, create_application_details(self.academic_year.id),
            self.client)
        self.assertEqual(new_application_response.status_code, 201)

        latest_application = Application.objects.latest(
            field_name="created_at")
        self.assertEqual(latest_application.forename, "Marton")
        self.assertEqual(latest_application.status, PENDING_STATUS)
        self.assertEqual(latest_application.administrator_comment, None)
        self.assertEqual(
            len(latest_application.supervisions.filter(type=SUPERVISOR)), 2)
        self.assertEqual(len(latest_application.tags.all()), 2)

        # Update application
        put_data = json.loads(
            create_application_details(
                self.academic_year.id,
                registry_ref="9874334",
                surname="Szeles",
                forename="Martin",
                possible_funding=["SELF"],
                funding_status="PENDING",
                origin="EU",
                student_type="COMPUTING",
                status="PENDING",
                supervisors=[],
                research_subject=
                "Investigating travelling at the speed of light.",
                administrator_comment="Awesome",
                file_descriptions=[]))

        update_json = json.dumps({
            "id": latest_application.id,
            "application": put_data
        })
        update_application_response = self.client.put(
            path="/api/phd/application/",
            data=update_json,
            HTTP_AUTHORIZATION='JWT {}'.format(token),
            content_type='application/json')

        self.assertEqual(update_application_response.status_code, 200)

        latest_application = Application.objects.latest(
            field_name="created_at")
        self.assertEqual(latest_application.forename, "Martin")
        self.assertEqual(latest_application.administrator_comment, "Awesome")

        # Check if we can read the data through the endpoint
        search_result_response = self.client.get(
            "/api/phd/application/", {"id": latest_application.id},
            HTTP_AUTHORIZATION='JWT {}'.format(token))
        search_result_response_content = json.loads(
            search_result_response.content.decode('utf-8'))
        application = search_result_response_content["application"]
        self.assertEqual(application["forename"], "Martin")
        self.assertEqual(len(application["supervisions"]), 3)

        # Delete
        delete_application_response = self.client.delete(
            path="/api/phd/application/",
            data=json.dumps({"id": application["id"]}),
            HTTP_AUTHORIZATION='JWT {}'.format(token),
            content_type='application/json')

        self.assertEqual(delete_application_response.status_code, 204)