コード例 #1
0
    def test_get_interview_questions_randomised_ok(self):
        self.clear_interview_tasks_table()
        test_it = InterviewTask(
            **test_interview_tasks.interview_task_random_questions)
        test_it.ddb_dump()
        path_parameters = {
            "id":
            test_interview_tasks.
            interview_task_random_questions["live_survey_id"]
        }
        expected_status = HTTPStatus.OK
        result_1 = test_utils.test_get(
            ep.get_interview_questions_api,
            self.interview_questions_endpoint,
            path_parameters=path_parameters,
        )
        result_1_status = result_1["statusCode"]
        result_1_body = json.loads(result_1["body"])
        self.assertEqual(expected_status, result_1_status)

        result_2 = test_utils.test_get(
            ep.get_interview_questions_api,
            self.interview_questions_endpoint,
            path_parameters=path_parameters,
        )
        result_2_status = result_2["statusCode"]
        result_2_body = json.loads(result_2["body"])
        self.assertEqual(expected_status, result_2_status)

        self.assertNotEqual(result_1_body, result_2_body)
        self.assertCountEqual(result_1_body, result_2_body)
コード例 #2
0
    def test_user_a_project_status_project_order_include_non_visible(self):
        user_id = "d1070e81-557e-40eb-a7ba-b951ddb7ebdc"  # [email protected]

        expected_project_order = [
            "PSFU-02-pub-tst-ngrp",
            "PSFU-03-pub-tst-grp",
            "PSFU-04-prv-tst-grp",
            "CTG Monitoring",
            "PSFU-05-pub-act",
            "PSFU-06-prv-act",
            "PSFU-07-pub-comp",
            "PSFU-08-prv-comp",
        ]

        response = test_get(
            get_project_status_for_user_api,
            f"v1/{ENTITY_BASE_URL}",
            None,
            {
                "user_id": user_id,
                "include_non_visible_data": "true",
            },
            None,
        )
        result_json = json.loads(response["body"])
        returned_project_order = [p["name"] for p in result_json]
        self.assertEqual(expected_project_order, returned_project_order)
コード例 #3
0
    def test_get_task_response_api_thisinstitute_account_ok(self):
        query_parameters = {
            "survey_id":
            "SV_ezK42q9nZRtRCxU",
            "response_id":
            "R_2pVHAWjO0XFfULI",
            "account":
            "thisinstitute",
            "anon_project_specific_user_id":
            "29aca87c-e0f9-44c2-b97e-22cbe842a908",
        }

        expected_status = HTTPStatus.OK

        result = test_tools.test_get(
            resp.get_task_response,
            self.entity_base_url,
            querystring_parameters=query_parameters,
        )
        result_status = result["statusCode"]
        result_json = json.loads(result["body"])

        # test results returned from api call
        self.assertEqual(expected_status, result_status)
        self.assertDictEqual(
            {
                "age": "2",
                "food": "[1, 3]",
                "job": "Quality Assurance Engineer"
            },
            result_json,
        )
コード例 #4
0
    def test_1_list_projects_api(self):
        expected_status = HTTPStatus.OK
        expected_body = [
            json.loads(x) for x in [
                PROJECT_01_JSON,
                PROJECT_02_JSON,
                PROJECT_03_JSON,
                PROJECT_10_JSON,
                PROJECT_11_JSON,
                PROJECT_12_JSON,
                PROJECT_08_JSON,
                PROJECT_04_JSON,
                PROJECT_05_JSON,
                PROJECT_13_JSON,
                PROJECT_14_JSON,
                PROJECT_17_JSON,
                PROJECT_06_JSON,
                PROJECT_07_JSON,
                PROJECT_15_JSON,
                PROJECT_16_JSON,
            ]
        ]
        result = test_get(p.list_projects_api, f"v1/{ENTITY_BASE_URL}", None,
                          None, None)
        result_status = result["statusCode"]
        result_json = json.loads(result["body"])

        self.assertEqual(expected_status, result_status)
        self.assertEqual(len(expected_body), len(result_json))
        for (result, expected) in zip(result_json, expected_body):
            self.assertDictEqual(expected, result)
コード例 #5
0
    def test_get_interview_questions_randomised_config_conflict_raises_error(
            self):
        self.clear_interview_tasks_table()
        test_it = InterviewTask(
            **test_interview_tasks.interview_task_random_questions)
        test_it.ddb_dump()

        test_it_config_conflict = InterviewTask(
            **test_interview_tasks.
            interview_task_random_questions_config_conflict)
        test_it_config_conflict.ddb_dump()

        path_parameters = {
            "id":
            test_interview_tasks.
            interview_task_random_questions["live_survey_id"]
        }
        expected_status = HTTPStatus.INTERNAL_SERVER_ERROR
        result = test_utils.test_get(
            ep.get_interview_questions_api,
            self.interview_questions_endpoint,
            path_parameters=path_parameters,
        )
        result_status = result["statusCode"]
        result_body = result["body"]
        self.assertEqual(expected_status, result_status)
        self.assertIn("Conflicting interview task configuration(s)",
                      result_body)
コード例 #6
0
 def test_user_specific_task_url_ok(self):
     result = test_get(
         get_project_status_for_user_api,
         f"v1/{ENTITY_BASE_URL}",
         querystring_parameters={"user_id": self.user_id},
     )
     expected_status = HTTPStatus.OK
     result_status = result["statusCode"]
     self.assertEqual(expected_status, result_status)
     result_json = json.loads(result["body"])
     expected_task_results = {
         "4ee70544-6797-4e21-8cec-5653c8d5b234": {
             "url": f"www.specific-user-task.co.uk"
             f"?anon_project_specific_user_id=e132c198-06d3-4200-a6c0-cc3bc7991828"
             f"&anon_user_task_id=47e98896-33b4-4401-b667-da95db9122a2"
             f"&project_task_id=4ee70544-6797-4e21-8cec-5653c8d5b234"
             f"&external_task_id=5678"
             f"&env={TEST_ENV}",
         }
     }
     for project in result_json:
         for task in project["tasks"]:
             expected_fields = expected_task_results.get(task["id"])
             if expected_fields:
                 for k, v in expected_fields.items():
                     self.assertEqual(v, task[k])
コード例 #7
0
    def test_21_users_demo_flag_ok(self):
        # todo: add new user(s) to test_data with distinct combinations of these flags
        expected_results = [
            {
                "user_id": "851f7b34-f76c-49de-a382-7e4089b744e2",  # [email protected]
                "has_demo_project": True,
                "has_live_project": True,
            },
            {
                "user_id": "8518c7ed-1df4-45e9-8dc4-d49b57ae0663",  # [email protected]
                "has_demo_project": True,
                "has_live_project": True,
            },
        ]
        for expected_result in expected_results:
            path_parameters = {"id": expected_result["user_id"]}

            expected_status = HTTPStatus.OK

            result = test_get(
                get_user_by_id_api, ENTITY_BASE_URL, path_parameters=path_parameters
            )
            result_status = result["statusCode"]
            result_json = json.loads(result["body"])

            # test results returned from api call
            self.assertEqual(expected_status, result_status)
            for flag in ["has_demo_project", "has_live_project"]:
                self.assertEqual(expected_result[flag], result_json[flag])
コード例 #8
0
 def test_10_list_users_by_project_ok(self):
     project_id = "183c23a1-76a7-46c3-8277-501f0740939d"  # PSFU 7
     expected_users = [
         {
             "anon_project_specific_user_id": "1406c523-6d12-4510-a745-271ddd9ad3e2",
             "email": "*****@*****.**",
             "first_name": "Eddie",
             "last_name": "Eagleton",
             "project_id": "183c23a1-76a7-46c3-8277-501f0740939d",
             "user_id": "1cbe9aad-b29f-46b5-920e-b4c496d42515",
         },
         {
             "anon_project_specific_user_id": "2c8bba57-58a9-4ac7-98e8-beb34f0692c1",
             "email": "*****@*****.**",
             "first_name": "Altha",
             "last_name": "Alcorn",
             "project_id": "183c23a1-76a7-46c3-8277-501f0740939d",
             "user_id": "d1070e81-557e-40eb-a7ba-b951ddb7ebdc",
         },
         {
             "anon_project_specific_user_id": "82ca200e-66d6-455d-95bc-617f974bcb26",
             "email": "*****@*****.**",
             "first_name": "Clive",
             "last_name": "Cresswell",
             "project_id": "183c23a1-76a7-46c3-8277-501f0740939d",
             "user_id": "8518c7ed-1df4-45e9-8dc4-d49b57ae0663",
         },
     ]
     result = test_get(
         local_method=u.list_users_by_project_api,
         aws_url="v1/list-project-users",
         querystring_parameters={"project_id": project_id},
     )
     users = json.loads(result["body"])
     self.assertCountEqual(expected_users, users)
コード例 #9
0
    def test_get_task_response_api_ok(self):
        query_parameters = {
            "survey_id":
            "SV_aWDwvBuOqAsxrkq",
            "response_id":
            "R_2VptOho22NGPmoe",
            "account":
            "cambridge",
            "anon_project_specific_user_id":
            "29aca87c-e0f9-44c2-b97e-22cbe842a908",
        }

        expected_status = HTTPStatus.OK

        result = test_tools.test_get(
            resp.get_task_response,
            self.entity_base_url,
            querystring_parameters=query_parameters,
        )
        result_status = result["statusCode"]
        result_json = json.loads(result["body"])

        # test results returned from api call
        self.assertEqual(expected_status, result_status)
        self.assertDictEqual(
            {
                "age": "2",
                "food": "[1, 3]",
                "job": "Quality Assurance Engineer"
            },
            result_json,
        )
コード例 #10
0
 def test_ep_01_retrieve_response_api_ok(self):
     params = {
         "survey_id": self.test_survey_id,
         "response_id": self.test_response_id,
         "question_ids": json.dumps(self.test_question_ids),
     }
     result = test_utils.test_get(
         local_method=ep.retrieve_responses_api,
         aws_url=self.retrieve_responses_endpoint,
         querystring_parameters=params,
     )
     self.assertEqual(HTTPStatus.OK, result["statusCode"])
     expected_result_body = {
         "Q12_1": 1,
         "Q12_2": 1,
         "Q12_3": 1,
         "Q12_4": 1,
         "Q12_5": 1,
         "Q12_6": 1,
         "Q12_7": 1,
         "Q12_8": 1,
         "Q1": 1,
         "Q1COM": "Good job.",
         "Q12_8_TEXT": "Smoke signals",
         "Q4": None,
         "Q4COM": None,
     }
     pprint(json.loads(result["body"]))
     self.assertCountEqual(expected_result_body, json.loads(result["body"]))
コード例 #11
0
    def test_get_interview_questions_randomised_missing_config_interpreted_as_not_random(
        self, ):
        """
        Interview Tasks without randomisation config are treated as specifying randomisation=False
        This also ensure backwards compatibility with existing InterviewTask objects.
        """
        self.clear_interview_tasks_table()
        test_it = InterviewTask(**test_interview_tasks.interview_task_2)
        # use put_item instead of InterviewTask.ddb_dump to ensure item does not have random config
        self.ddb_client.put_item(
            table_name=const.INTERVIEW_TASKS_TABLE["name"],
            key=str(test_it._project_task_id),
            item_type="interview_task",
            item_details=None,
            item=test_interview_tasks.interview_task_2,
            key_name=const.INTERVIEW_TASKS_TABLE["partition_key"],
            sort_key={
                const.INTERVIEW_TASKS_TABLE["sort_key"]:
                test_it._interview_task_id
            },
        )
        path_parameters = {
            "id": test_interview_tasks.interview_task_2["live_survey_id"]
        }
        expected_status = HTTPStatus.OK
        result_1 = test_utils.test_get(
            ep.get_interview_questions_api,
            self.interview_questions_endpoint,
            path_parameters=path_parameters,
        )
        result_1_status = result_1["statusCode"]
        result_1_body = json.loads(result_1["body"])
        self.assertEqual(expected_status, result_1_status)

        result_2 = test_utils.test_get(
            ep.get_interview_questions_api,
            self.interview_questions_endpoint,
            path_parameters=path_parameters,
        )
        result_2_status = result_2["statusCode"]
        result_2_body = json.loads(result_2["body"])
        self.assertEqual(expected_status, result_2_status)

        self.assertEqual(result_1_body, result_2_body)
コード例 #12
0
 def test_get_interview_task_not_found(self):
     path_parameters = {"id": td.ARBITRARY_UUID}
     expected_status = HTTPStatus.NOT_FOUND
     result = test_utils.test_get(
         ep.get_interview_task_api,
         self.entity_base_url,
         path_parameters=path_parameters,
     )
     result_status = result["statusCode"]
     self.assertEqual(expected_status, result_status)
コード例 #13
0
 def test_get_interview_questions_not_found(self):
     path_parameters = {"id": "SV_NonExistent1234"}
     expected_status = HTTPStatus.NOT_FOUND
     result = test_utils.test_get(
         ep.get_interview_questions_api,
         self.interview_questions_endpoint,
         path_parameters=path_parameters,
     )
     result_status = result["statusCode"]
     self.assertEqual(expected_status, result_status)
コード例 #14
0
    def test_patch_user_api_with_spaces_in_name_ok(self):
        user_id = "851f7b34-f76c-49de-a382-7e4089b744e2"

        expected_status = HTTPStatus.NO_CONTENT
        user_jsonpatch = [
            {"op": "replace", "path": "/title", "value": "Sir"},
            {"op": "replace", "path": "/first_name", "value": " Antônio"},
            {"op": "replace", "path": "/last_name", "value": "Jobim "},
            {"op": "replace", "path": "/email", "value": "*****@*****.**"},
            {"op": "replace", "path": "/auth0_id", "value": "new-auth0-id"},
            {"op": "replace", "path": "/status", "value": "singing"},
            {"op": "replace", "path": "/country_code", "value": "BR"},
        ]
        body = json.dumps(user_jsonpatch)
        path_parameters = {"id": user_id}

        result = test_patch(
            patch_user_api,
            ENTITY_BASE_URL,
            path_parameters=path_parameters,
            request_body=body,
        )
        result_status = result["statusCode"]

        self.assertEqual(expected_status, result_status)
        # now check database values...
        path_parameters = {"id": user_id}

        expected_body = {
            "id": user_id,
            "email": "*****@*****.**",
            "title": "Sir",
            "first_name": "Antônio",
            "last_name": "Jobim",
            "auth0_id": "new-auth0-id",
            "country_code": "BR",
            "country_name": "Brazil",
            "crm_id": None,
            "avatar_string": "AJ",
            "status": "singing",
        }

        result = test_get(
            u.get_user_by_id_api, ENTITY_BASE_URL, path_parameters=path_parameters
        )
        result_json = json.loads(result["body"])
        for ignored_attribute in [
            "created",
            "modified",
            "has_demo_project",
            "has_live_project",
        ]:
            result_json.pop(ignored_attribute, None)
            expected_body.pop(ignored_attribute, None)
        self.assertEqual(expected_body, result_json)
コード例 #15
0
 def test_project_status_invalid_user_id(self):
     user_id = "d1070e81-557e-40eb-a7ba-b951ddb7ebd"
     querystring_parameters = {"user_id": user_id}
     result = test_get(
         get_project_status_for_user_api,
         f"v1/{ENTITY_BASE_URL}",
         None,
         querystring_parameters,
         None,
     )
     expected_status = HTTPStatus.BAD_REQUEST
     self.assertEqual(expected_status, result["statusCode"])
コード例 #16
0
 def test_project_status_nonexistent_user(self):
     user_id = "35224bd5-f8a8-41f6-8502-f96e12d6dddf"
     querystring_parameters = {"user_id": user_id}
     result = test_get(
         get_project_status_for_user_api,
         f"v1/{ENTITY_BASE_URL}",
         None,
         querystring_parameters,
         None,
     )
     expected_status = HTTPStatus.NOT_FOUND
     self.assertEqual(expected_status, result["statusCode"])
コード例 #17
0
    def test_01_get_appointment_by_type_api_ok(self):
        body = json.dumps(
            {"type_ids": [str(td["dev_appointment_no_link_type_id"])]})

        result = test_utils.test_get(
            local_method=abt.get_appointments_by_type_api,
            aws_url=self.endpoint_url,
            request_body=body,
        )
        self.assertEqual(HTTPStatus.OK, result["statusCode"])
        appointments = json.loads(result["body"])["appointments"]
        self.assertEqual(3, len(appointments))
コード例 #18
0
 def test_get_personal_link_api_missing_mandatory_data(self):
     params = {
         "survey_id": self.default_survey_id,
         "account": self.default_account,
     }
     expected_status = HTTPStatus.BAD_REQUEST
     result = test_utils.test_get(
         pl.get_personal_link_api,
         self.entity_base_url,
         querystring_parameters=params,
     )
     self.assertEqual(expected_status, result["statusCode"])
コード例 #19
0
 def test_get_user_interview_task_does_not_exist(self):
     path_parameters = {
         "id": td.TEST_USER_INTERVIEW_TASK["response_id"].replace("2", "3")
     }
     expected_status = HTTPStatus.NOT_FOUND
     result = test_utils.test_get(
         ep.get_user_interview_task_api,
         self.entity_base_url,
         path_parameters=path_parameters,
     )
     result_status = result["statusCode"]
     self.assertEqual(expected_status, result_status)
コード例 #20
0
    def test_01b_list_user_tasks_api_ok_interview_task(self):
        expected_status = HTTPStatus.OK
        expected_body = USER_TASK_03_EXPECTED_BODY
        querystring_parameters = {
            "user_id": "e067ed7b-bc98-454f-9c5e-573e2da5705c"
        }

        result = test_get(list_user_tasks_api, ENTITY_BASE_URL, None,
                          querystring_parameters, None)
        result_status = result["statusCode"]
        result_json = json.loads(result["body"])
        self.assertEqual(expected_status, result_status)
        self.assertDictEqual(expected_body, result_json)
コード例 #21
0
    def test_03_list_user_projects_api_no_results(self):
        expected_status = HTTPStatus.OK
        expected_body = []
        querystring_parameters = {"user_id": "dceac123-03a7-4e29-ab5a-739e347b374d"}

        result = test_get(
            list_user_projects_api, ENTITY_BASE_URL, None, querystring_parameters, None
        )
        result_status = result["statusCode"]
        result_json = json.loads(result["body"])

        self.assertEqual(expected_status, result_status)
        self.assertEqual(expected_body, result_json)
コード例 #22
0
    def test_04_get_user_by_email_api_takes_one_and_only_one_querystring_parameter(
        self,
    ):
        expected_status = HTTPStatus.BAD_REQUEST
        result = test_get(
            u.get_user_by_email_api, ENTITY_BASE_URL, querystring_parameters={}
        )
        result_status = result["statusCode"]
        result_json = json.loads(result["body"])
        self.assertEqual(expected_status, result_status)
        self.assertTrue("correlation_id" in result_json)
        self.assertTrue(
            ("message" in result_json)
            and (
                "This endpoint requires one query parameter (email or anon_project_specific_user_id); none were found"
                in result_json["message"]
            )
        )

        query_parameters = {
            "anon_project_specific_user_id": "2c8bba57-58a9-4ac7-98e8-beb34f0692c1",
            "email": "*****@*****.**",
        }
        result = test_get(
            u.get_user_by_email_api,
            ENTITY_BASE_URL,
            querystring_parameters=query_parameters,
        )
        result_status = result["statusCode"]
        result_json = json.loads(result["body"])
        self.assertEqual(expected_status, result_status)
        self.assertTrue("correlation_id" in result_json)
        self.assertTrue(
            ("message" in result_json)
            and (
                "Please query by either email or anon_project_specific_user_id, but not both"
                in result_json["message"]
            )
        )
コード例 #23
0
    def test_01_list_user_projects_api_ok(self):
        expected_status = HTTPStatus.OK
        expected_body = [USER_PROJECT_01_EXPECTED_BODY, USER_PROJECT_02_EXPECTED_BODY]
        querystring_parameters = {"user_id": "851f7b34-f76c-49de-a382-7e4089b744e2"}

        result = test_get(
            list_user_projects_api, ENTITY_BASE_URL, None, querystring_parameters, None
        )
        result_status = result["statusCode"]
        result_json = json.loads(result["body"])

        self.assertEqual(expected_status, result_status)
        self.assertDictEqual(expected_body[0], result_json[0])
コード例 #24
0
 def test_get_interview_task_ok(self):
     path_parameters = {"id": td.TEST_INTERVIEW_TASK["interview_task_id"]}
     expected_status = HTTPStatus.OK
     result = test_utils.test_get(
         ep.get_interview_task_api,
         self.entity_base_url,
         path_parameters=path_parameters,
     )
     result_status = result["statusCode"]
     result_body = json.loads(result["body"])
     del result_body["modified"]
     self.assertEqual(expected_status, result_status)
     self.assertEqual(td.TEST_INTERVIEW_TASK, result_body)
コード例 #25
0
 def test_response_includes_all_expected_attributes(self):
     user_id = "8518c7ed-1df4-45e9-8dc4-d49b57ae0663"
     querystring_parameters = {"user_id": user_id}
     response = test_get(
         get_project_status_for_user_api,
         f"v1/{ENTITY_BASE_URL}",
         None,
         querystring_parameters,
         None,
     )
     result = json.loads(response["body"])
     project = result[0]
     expected_project_attributes = [
         "id",
         "name",
         "short_name",
         "description",
         "project_page_url",
         "project_is_visible",
         "status",
         "visibility",
         "tasks",
     ]
     self.assertCountEqual(expected_project_attributes, project.keys())
     task = project["tasks"][0]
     expected_task_attributes = [
         "anonymise_url",
         "closing_date",
         "closing_date_desc",
         "description",
         "display_method",
         "earliest_start_date",
         "earliest_start_date_desc",
         "external_task_id",
         "id",
         "name",
         "short_name",
         "signup_available",
         "signup_status",
         "status",
         "task_is_visible",
         "task_page_url",
         "task_provider_name",
         "task_type_name",
         "url",
         "user_is_signedup",
         "user_specific_url",
         "user_task_status",
         "visibility",
     ]
     self.assertCountEqual(expected_task_attributes, task.keys())
コード例 #26
0
 def test_get_personal_link_api_invalid_account(self):
     invalid_account = "oxford"
     params = {
         "survey_id": self.default_survey_id,
         "anon_project_specific_user_id": self.default_anon_project_specific_user_id,
         "account": invalid_account,
     }
     expected_status = HTTPStatus.BAD_REQUEST
     result = test_utils.test_get(
         pl.get_personal_link_api,
         self.entity_base_url,
         querystring_parameters=params,
     )
     self.assertEqual(expected_status, result["statusCode"])
コード例 #27
0
    def test_08_get_user_email_is_case_insensitive(self):
        querystring_parameters = {"email": "*****@*****.**"}

        expected_status = HTTPStatus.OK

        result = test_get(
            get_user_by_email_api,
            ENTITY_BASE_URL,
            querystring_parameters=querystring_parameters,
        )
        result_status = result["statusCode"]
        result_json = json.loads(result["body"])

        self.assertEqual(expected_status, result_status)
        self.assertDictEqual(EXPECTED_USER, result_json)
コード例 #28
0
    def test_03_list_user_tasks_api_project_task_not_exists(self):
        expected_status = HTTPStatus.OK
        expected_body = list()
        querystring_parameters = {
            "user_id": "851f7b34-f76c-49de-a382-7e4089b744e2",
            "project_task_id": "aa5092b1-b098-42d7-8c62-21493dfe37f3",
        }

        result = test_get(list_user_tasks_api, ENTITY_BASE_URL, None,
                          querystring_parameters, None)
        result_status = result["statusCode"]
        result_json = json.loads(result["body"])

        self.assertEqual(expected_status, result_status)
        self.assertEqual(expected_body, result_json)
コード例 #29
0
    def test_02_list_user_projects_api_user_not_exists(self):
        expected_status = HTTPStatus.NOT_FOUND
        querystring_parameters = {"user_id": "851f7b34-f76c-49de-a382-7e4089b744e3"}

        result = test_get(
            list_user_projects_api, ENTITY_BASE_URL, None, querystring_parameters, None
        )
        result_status = result["statusCode"]
        result_json = json.loads(result["body"])

        self.assertEqual(expected_status, result_status)
        self.assertTrue("correlation_id" in result_json)
        self.assertTrue(
            ("message" in result_json) and ("does not exist" in result_json["message"])
        )
コード例 #30
0
    def test_user_e_demo_project_status_bad_include_non_visible_data_flag(self):
        user_id = "1cbe9aad-b29f-46b5-920e-b4c496d42515"  # [email protected]

        response = test_get(
            get_project_status_for_user_api,
            f"v1/{ENTITY_BASE_URL}",
            None,
            {
                "user_id": user_id,
                "include_non_visible_data": "False",  # string not lower case
            },
            None,
        )

        self.assertEqual(HTTPStatus.BAD_REQUEST, response["statusCode"])