def test_update_project_error_validate_required(self): test_project_id = template_project_id.format(str(1)) test_organization_id = template_organization_id.format(str(1)) test_user_id = affiliation_template_user_id.format(str(1)) # handler path_parameters = { "project_id": test_project_id, "organization_id": test_organization_id } event_mock = event_create.get_event_object( path_parameters=path_parameters, trace_id=test_user_id, body=json.dumps(project_update_empty)) response = projects.update_project_handler(event_mock, {}) # Check data response_body = json.loads(response['body']) self.assertEqual(response_body['code'], MsgConst.ERR_REQUEST_201['code']) self.assertEqual(response_body['message'], MsgConst.ERR_REQUEST_201['message']) self.assertEqual(response['statusCode'], HTTPStatus.UNPROCESSABLE_ENTITY.value) response_error = response_body['errors'] # 組織名 self.assertEqual(response_error[0]['code'], MsgConst.ERR_VAL_101['code']) self.assertEqual(response_error[0]['field'], "name") self.assertEqual(response_error[0]['value'], "") self.assertEqual(response_error[0]['message'], MsgConst.ERR_VAL_101['message'])
def test_update_project_error_parse_json(self): test_project_id = template_project_id.format(str(1)) test_organization_id = template_organization_id.format(str(1)) test_user_id = affiliation_template_user_id.format(str(1)) # handler path_parameters = { "project_id": test_project_id, "organization_id": test_organization_id } event_mock = event_create.get_event_object( path_parameters=path_parameters, trace_id=test_user_id, body=project_update) response = projects.update_project_handler(event_mock, {}) # Check data response_body = json.loads(response['body']) self.assertEqual(response_body['code'], MsgConst.ERR_REQUEST_202['code']) self.assertEqual(response_body['message'], MsgConst.ERR_REQUEST_202['message']) self.assertEqual(response_body['description'], MsgConst.ERR_REQUEST_202['description']) self.assertEqual(response['statusCode'], HTTPStatus.BAD_REQUEST.value)
def test_update_project_success(self): test_organization_id = template_organization_id.format(str(1)) test_project_id = template_project_id.format(str(1)) test_user_id = affiliation_template_user_id.format(str(1)) date_now = common_utils.get_current_date() # handler path_parameters = { "project_id": test_project_id, "organization_id": test_organization_id } event_mock = event_create.get_event_object( path_parameters=path_parameters, trace_id=test_user_id, body=json.dumps(project_update)) response = projects.update_project_handler(event_mock, {}) # Get data response response_body = json.loads(response['body']) id = response_body['id'] name = response_body['name'] description = response_body['description'] createdAt = response_body['createdAt'] updatedAt = response_body['updatedAt'] status_code = response['statusCode'] # Get data in database projects_database = pm_projects.get_projects( trace_id, test_project_id) # Check data self.assertEqual(id, test_project_id) self.assertEqual(name, projects_database[0]["ProjectName"]) self.assertEqual(description, projects_database[0]['Description']) self.assertEqual(createdAt, projects_database[0]['CreatedAt']) self.assertEqual(updatedAt, projects_database[0]['UpdatedAt']) self.assertGreaterEqual(projects_database[0]['UpdatedAt'], date_now) self.assertEqual(status_code, HTTPStatus.OK.value)
def test_update_project_error_record_zero(self): test_organization_id = template_organization_id.format(str(1)) test_user_id = affiliation_template_user_id.format(str(1)) test_project_id = "not_exists" # handler path_parameters = { "project_id": test_project_id, "organization_id": test_organization_id } event_mock = event_create.get_event_object( path_parameters=path_parameters, trace_id=test_user_id, body=json.dumps(project_update)) response = projects.update_project_handler(event_mock, {}) # Check data response_body = json.loads(response['body']) self.assertEqual(response_body['code'], MsgConst.ERR_301['code']) self.assertEqual(response_body['message'], MsgConst.ERR_301['message']) self.assertEqual(response['statusCode'], HTTPStatus.NOT_FOUND.value)
def test_update_project_error_access_authority(self): test_project_id = template_project_id.format(str(1)) test_organization_id = template_organization_id.format(str(1)) test_user_id = affiliation_template_user_id.format(str(0)) # handler path_parameters = { "project_id": test_project_id, "organization_id": test_organization_id } event_mock = event_create.get_event_object( path_parameters=path_parameters, trace_id=test_user_id, body=json.dumps(project_update)) response = projects.update_project_handler(event_mock, {}) # Check data message_101 = MsgConst.ERR_101 response_body = json.loads(response['body']) self.assertEqual(response_body['code'], message_101['code']) self.assertEqual(response_body['message'], message_101['message']) self.assertEqual(response['statusCode'], HTTPStatus.FORBIDDEN.value)