コード例 #1
0
    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')
コード例 #2
0
    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')
コード例 #3
0
    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')
コード例 #4
0
    def test_staff_statistics(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),
            self.client)

        statistics_response = self.client.get(
            path="/api/phd/statistics/staff/",
            data={},
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        self.assertEqual(statistics_response.status_code, 200)
コード例 #5
0
    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)
コード例 #6
0
    def test_basic_statistics(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),
            self.client)

        statistics_response = self.client.get(
            path="/api/phd/statistics/",
            data={},
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        self.assertEqual(statistics_response.status_code, 200)

        statistics_response_content = json.loads(
            statistics_response.content.decode('utf-8'))
        self.assertEqual(statistics_response_content["number_of_applications"],
                         1)
コード例 #7
0
    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)
コード例 #8
0
    def test_get_post_delete_tags_of_application(self):
        # Log in as the admin
        token = log_in(self.client, "Heffalumps", "Woozles")

        # New applications
        create_new_application(token, create_application_details(self.academic_year.id, registry_ref="01",
                                                                 tags=['Ferrari', 'Porsche']),
                               self.client)
        create_new_application(token, create_application_details(self.academic_year.id, registry_ref="02",
                                                                 tags=['Lamborghini', 'Audi']),
                               self.client)
        create_new_application(token, create_application_details(self.academic_year.id, registry_ref="03",
                                                                 tags=['Ferrari', 'Audi']),
                               self.client)

        self.client.post("/api/phd/admin/tags/", {
            "name": "Tag with no application"
        }, HTTP_AUTHORIZATION='JWT {}'.format(token))

        tags_response = self.client.get("/api/phd/application/tags/",
                                        HTTP_AUTHORIZATION='JWT {}'.format(token))

        self.assertEqual(tags_response.status_code, 200)
        response_content = json.loads(tags_response.content.decode('utf-8'))
        self.assertEqual(len(response_content), 5)

        self.assertEqual(response_content['Ferrari']['count'], 2)
        self.assertEqual(response_content['Porsche']['count'], 1)
        self.assertEqual(response_content['Tag with no application']['count'], 0)

        # POST new tags
        existing_application = Application.objects.filter(registry_ref="01").first()
        self.client.post("/api/phd/application/tags/", {
            "application_id": existing_application.id,
            "name": "Toyota"
        }, HTTP_AUTHORIZATION='JWT {}'.format(token))

        tags_response = self.client.get("/api/phd/application/tags/",
                                        HTTP_AUTHORIZATION='JWT {}'.format(token))

        response_content = json.loads(tags_response.content.decode('utf-8'))
        self.assertEqual(len(response_content), 6)

        self.assertEqual(response_content['Toyota']['count'], 1)

        # DELETE tag
        toyota_tag = Tag.objects.filter(name="Toyota").first()
        delete_tag_response = self.client.delete(path="/api/phd/application/tags/",
                                                 data=json.dumps({"tag_id": toyota_tag.id,
                                                                  "application_id": existing_application.id}),
                                                 HTTP_AUTHORIZATION='JWT {}'.format(token),
                                                 content_type='application/json')

        self.assertEqual(delete_tag_response.status_code, 204)

        tags_response = self.client.get("/api/phd/application/tags/",
                                        HTTP_AUTHORIZATION='JWT {}'.format(token))

        response_content = json.loads(tags_response.content.decode('utf-8'))
        self.assertEqual(len(response_content), 6)

        self.assertEqual(response_content['Toyota']['count'], 0)
コード例 #9
0
    def test_get_post_update_delete_tags(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, tags=['Ferrari', 'Porsche']),
                               self.client)

        # GET tags
        tags_response = self.client.get("/api/phd/admin/tags/", HTTP_AUTHORIZATION='JWT {}'.format(token))

        self.assertEqual(tags_response.status_code, 200)
        response_content = json.loads(tags_response.content.decode('utf-8'))
        self.assertEqual(len(response_content["tags"]), 2)

        # POST duplicate tag
        new_tags_response = self.client.post("/api/phd/admin/tags/", {
            "name": 'Ferrari'
        }, HTTP_AUTHORIZATION='JWT {}'.format(token))

        self.assertEqual(new_tags_response.status_code, 400)

        # POST good tag
        new_tags_response = self.client.post("/api/phd/admin/tags/", {
            "name": 'Lamborghini'
        }, HTTP_AUTHORIZATION='JWT {}'.format(token))

        self.assertEqual(new_tags_response.status_code, 201)

        # UPDATE existing tag
        existing_tag = Tag.objects.filter(name="Lamborghini").first()
        existing_tag.name = "Lamborghini 02"
        tag_serializer = TagSerializer(existing_tag)
        update_tag_response = self.client.put(path="/api/phd/admin/tags/",
                                              data=json.dumps(
                                                  {"id": existing_tag.id, "tag": tag_serializer.data}),
                                              HTTP_AUTHORIZATION='JWT {}'.format(token),
                                              content_type='application/json')

        self.assertEqual(update_tag_response.status_code, 200)

        tags_response = self.client.get("/api/phd/admin/tags/", HTTP_AUTHORIZATION='JWT {}'.format(token))
        response_content = json.loads(tags_response.content.decode('utf-8'))
        existing_tag_names = [tag['name'] for tag in response_content["tags"]]
        self.assertIn("Lamborghini 02", existing_tag_names)

        # UPDATE duplicate tag
        existing_tag.name = "Ferrari"
        tag_serializer = TagSerializer(existing_tag)
        update_tag_response = self.client.put(path="/api/phd/admin/tags/",
                                              data=json.dumps(
                                                  {"id": existing_tag.id, "tag": tag_serializer.data}),
                                              HTTP_AUTHORIZATION='JWT {}'.format(token),
                                              content_type='application/json')

        self.assertEqual(update_tag_response.status_code, 400)

        # DELETE a tag
        delete_tag_response = self.client.delete(path="/api/phd/admin/tags/",
                                                 data=json.dumps({"id": existing_tag.id}),
                                                 HTTP_AUTHORIZATION='JWT {}'.format(token),
                                                 content_type='application/json')

        self.assertEqual(delete_tag_response.status_code, 204)
        existing_tag = Tag.objects.filter(name="Lamborghini 02").first()
        self.assertEqual(existing_tag, None)
コード例 #10
0
    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)
コード例 #11
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)
コード例 #12
0
    def test_application_search(self):

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

        # New applications
        post_data = create_application_details(
            self.academic_year.id,
            registry_ref="012983234",
            surname="Szeles",
            forename="Marton",
            possible_funding=["SELF"],
            funding_status="PENDING",
            origin="EU",
            student_type="COMPUTING",
            supervisors=[],
            research_subject="Investigating travelling at the speed of light.",
            administrator_comment=None,
            file_descriptions=[],
            tags=["Ferrari"])
        create_new_application(token, post_data, self.client)

        post_data = create_application_details(
            self.academic_year.id,
            registry_ref="7374636",
            surname="Atrus",
            forename="Yeesha",
            possible_funding=["SELF"],
            funding_status="PENDING",
            origin="OVERSEAS",
            student_type="COMPUTING_AND_CDT",
            supervisors=[],
            research_subject="Investigating writing linking books.",
            administrator_comment=None,
            file_descriptions=[],
            tags=["Porsche", "Mercedes", "Ferrari"])
        create_new_application(token, post_data, self.client)

        # Search
        search_result_response = self.client.get(
            "/api/phd/search/", {"surname": "Szeles"},
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        search_result_response_content = json.loads(
            search_result_response.content.decode('utf-8'))
        applications = search_result_response_content["applications"]
        self.assertEqual(len(applications), 1)

        # Search
        search_result_response = self.client.get(
            "/api/phd/search/", {"forename": "a"},
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        search_result_response_content = json.loads(
            search_result_response.content.decode('utf-8'))
        applications = search_result_response_content["applications"]
        self.assertEqual(len(applications), 2)

        # Search
        search_result_response = self.client.get(
            "/api/phd/search/", {
                "forename": "a",
                "origin": "EU"
            },
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        search_result_response_content = json.loads(
            search_result_response.content.decode('utf-8'))
        applications = search_result_response_content["applications"]
        self.assertEqual(len(applications), 1)

        # Search
        search_result_response = self.client.get(
            "/api/phd/search/", {"origin": ["EU", "OVERSEAS"]},
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        search_result_response_content = json.loads(
            search_result_response.content.decode('utf-8'))
        applications = search_result_response_content["applications"]
        self.assertEqual(len(applications), 2)

        # Search
        search_result_response = self.client.get(
            "/api/phd/search/", {"tags": ["Porsche", "Mercedes"]},
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        search_result_response_content = json.loads(
            search_result_response.content.decode('utf-8'))
        applications = search_result_response_content["applications"]
        self.assertEqual(len(applications), 1)

        # Search
        search_result_response = self.client.get(
            "/api/phd/search/", {"tags": ["Ferrari"]},
            HTTP_AUTHORIZATION='JWT {}'.format(token))

        search_result_response_content = json.loads(
            search_result_response.content.decode('utf-8'))
        applications = search_result_response_content["applications"]
        self.assertEqual(len(applications), 2)
コード例 #13
0
    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)