def put(self, request, project, pk): serializer = TestexecutionSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: name = serializer.validated_data['name'] runner = serializer.validated_data['runner'] except KeyError: return Response({'detail': unicode("The lack of required parameters.")}, status=status.HTTP_400_BAD_REQUEST) if not check_name_by_id(TestExecution, name, project, pk): return Response({'detail': unicode("Found same name testexecution_name, " "please check your testexecution_name name.")}, status=status.HTTP_409_CONFLICT) execution_obj = get_object(TestExecution, project, pk) if not check_owner_runner(execution_obj.runner, runner): return Response({'detail': unicode("The runner can not be changed.")}, status=status.HTTP_400_BAD_REQUEST) execution_obj.name = name execution_obj.runner = runner execution_obj.save() new_serializer = TestexecutionSerializer(execution_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): serializer = TestPlanSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: plan_name = serializer.validated_data['name'] plan_category = serializer.validated_data['category'] plan_owner = serializer.validated_data['owner'] plan_description = serializer.validated_data['description'] start_time = serializer.validated_data['start_time'] end_time = serializer.validated_data['end_time'] except KeyError: return Response( {'detail': unicode("The lack of required parameters.")}, status=status.HTTP_400_BAD_REQUEST) perf = serializer.validated_data.get('performance', False) app = serializer.validated_data.get('app', None) if not check_name_by_id( TestPlan, plan_name, project, pk, check_flag=True): return Response( { 'detail': unicode("Found same name testplan, " "please check your testplan name.") }, status=status.HTTP_409_CONFLICT) plan_obj = get_object(TestPlan, project, pk) if plan_obj.performance != perf or plan_obj.app != app: return Response( { 'detail': unicode("Not allow change performance and app attribute.") }, status=status.HTTP_400_BAD_REQUEST) if not check_owner_runner(plan_obj.owner, plan_owner): return Response( {'detail': unicode("The owner can not be changed.")}, status=status.HTTP_400_BAD_REQUEST) plan_obj.name = plan_name plan_obj.owner = plan_owner plan_obj.category = plan_category plan_obj.start_time = start_time plan_obj.end_time = end_time plan_obj.description = plan_description plan_obj.save() new_serializer = TestPlanSerializer(plan_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): serializer = TestsuiteSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: suite_name = serializer.validated_data['name'] suite_subsystem = serializer.validated_data['subsystem'] suite_description = serializer.validated_data['description'] plan_list = serializer.validated_data['testplan'] except KeyError: return Response({'detail': unicode("The lack of required parameters.")}, status=status.HTTP_400_BAD_REQUEST) perf = serializer.validated_data.get('performance', False) app = serializer.validated_data.get('app', None) if perf and not app: return Response({'detail': unicode("parameter app must provide when performance=True")}, status=status.HTTP_400_BAD_REQUEST) if not perf and app: return Response({'detail': unicode("parameter app can not be set when performance=False")}, status=status.HTTP_400_BAD_REQUEST) if not check_name_by_id(TestSuite, suite_name, project, pk, check_flag=True): return Response({'detail': unicode("Found same name testsuite_name, " "please check your testsuite_name name.")}, status=status.HTTP_409_CONFLICT) suite_obj = get_object(TestSuite, project, pk) if suite_obj.performance != perf or suite_obj.app != app: return Response({'detail': unicode("Not allow change performance and app attribute.")}, status=status.HTTP_400_BAD_REQUEST) suite_obj.name = suite_name suite_obj.subsystem = suite_subsystem suite_obj.description = suite_description validated_plan_list = [] for plan in plan_list: if plan.performance != perf or plan.app != app: return Response({'detail': unicode("plan:{0} not match test suite of " "performance type".format(plan.id))}, status=status.HTTP_409_CONFLICT) validated_plan_list.append(plan) suite_obj.save() suite_obj.testplan.clear() for plan in validated_plan_list: suite_obj.testplan.add(plan) new_serializer = TestsuiteSerializer(suite_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): serializer = TestexecutionOsSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) os_name = serializer.data['name'] if not check_name_by_id(OS, os_name, project, pk): return Response({'detail': unicode("Found same name os, please check your os name.")}, status=status.HTTP_409_CONFLICT) os_obj = get_object(OS, project, pk) os_obj.name = serializer.data['name'] os_obj.save() new_serializer = TestexecutionOsSerializer(os_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): serializer = TestsuiteSubsystemSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) subsystem_name = serializer.data['name'] if not check_name_by_id(Subsystem, subsystem_name, project, pk): return Response({'detail': unicode("Found same name subsystem, " "please check your subsystem name.")}, status=status.HTTP_409_CONFLICT) subsystem_obj = get_object(Subsystem, project, pk) subsystem_obj.name = subsystem_name subsystem_obj.save() new_serializer = TestsuiteSubsystemSerializer(subsystem_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): serializer = TestcaseTypeSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) type_name = serializer.data['name'] if not check_name_by_id(TestCaseType, type_name, project, pk): return Response({'detail': unicode("Found same name type, " "please check your type name.")}, status=status.HTTP_409_CONFLICT) type_obj = get_object(TestCaseType, project, pk) type_obj.name = type_name type_obj.save() new_serializer = TestcaseTypeSerializer(type_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): auth_status, message = check_auth(request.user, project, 'writer') if not auth_status: return Response(message, status=status.HTTP_401_UNAUTHORIZED) serializer = FeatureComponentSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) component_name = serializer.data['name'] if not check_name_by_id(Component, component_name, project, pk): return Response({'detail': unicode("Found same name component, " "please check your component name.")}, status=status.HTTP_409_CONFLICT) component_obj = get_object(Component, project, pk) component_obj.name = component_name component_obj.save() new_serializer = FeatureComponentSerializer(component_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): serializer = AppSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) app_name = serializer.data['name'] if not check_name_by_id(App, app_name, project, pk): return Response( { 'detail': unicode("Found same name app, please check your app name.") }, status=status.HTTP_409_CONFLICT) app_obj = get_object(App, project, pk) app_obj.name = app_name app_obj.save() new_serializer = AppSerializer(app_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): serializer = TestPlanCategorySerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) category_name = serializer.data['name'] if not check_name_by_id(Category, category_name, project, pk): return Response( { 'detail': unicode("Found same name category, " "please check your category name.") }, status=status.HTTP_409_CONFLICT) category_obj = get_object(Category, project, pk) category_obj.name = category_name category_obj.save() new_serializer = TestPlanCategorySerializer(category_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): auth_status, message = check_auth(request.user, project, 'writer') if not auth_status: return Response(message, status=status.HTTP_401_UNAUTHORIZED) serializer = FeatureSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: fea_name = serializer.data['name'] fea_owner = serializer.data['owner'] fea_component = serializer.data['component'] fea_requirement = serializer.data['requirement'] fea_description = serializer.data['description'] except KeyError: return Response({'detail': unicode("The lack of required parameters.")}, status=status.HTTP_400_BAD_REQUEST) if not check_name_by_id(Feature, fea_name, project, pk): return Response({'detail': unicode("Found same name feature, " "please check your feature name.")}, status=status.HTTP_409_CONFLICT) fea_obj = get_object(Feature, project, pk) if not check_owner_runner(fea_obj.owner, fea_owner): return Response({'detail': unicode("The owner can not be changed.")}, status=status.HTTP_400_BAD_REQUEST) fea_obj.name = fea_name fea_obj.owner = fea_owner fea_obj.component_id = fea_component fea_obj.requirement_id = fea_requirement fea_obj.description = fea_description fea_obj.save() new_serializer = FeatureSerializer(fea_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): serializer = TestcaseSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: case_name = serializer.validated_data['name'] case_type = serializer.validated_data['type'] case_description = serializer.validated_data['description'] case_script_path = serializer.validated_data['script_path'] case_config_path = serializer.validated_data['config_path'] case_parameters = serializer.validated_data['parameters'] case_feature = serializer.validated_data['feature'] suite_list = serializer.validated_data['testsuite'] except KeyError: return Response({'detail': unicode("The lack of required parameters.")}, status=status.HTTP_400_BAD_REQUEST) # app must be set if performance equal true perf = serializer.validated_data.get('performance', False) app = serializer.validated_data.get('app', None) if perf and not app: return Response({'detail': unicode("parameter app must provide when performance=True")}, status=status.HTTP_400_BAD_REQUEST) if not perf and app: return Response({'detail': unicode("parameter app can not be set when performance=False")}, status=status.HTTP_400_BAD_REQUEST) if not check_name_by_id(TestCase, case_name, project, pk, check_flag=True): return Response({'detail': unicode("Found same name testcase_name, " "please check your testcase_name name.")}, status=status.HTTP_409_CONFLICT) case_obj = get_object(TestCase, project, pk) if case_obj.performance != perf or case_obj.app != app: return Response({'detail': unicode("Not allow change performance and app attribute.")}, status=status.HTTP_400_BAD_REQUEST) case_obj.name = case_name case_obj.type = case_type case_obj.description = case_description case_obj.script_path = case_script_path case_obj.config_path = case_config_path case_obj.parameters = case_parameters case_obj.feature = case_feature validated_suite_list = [] for suite in suite_list: if suite.performance != perf or suite.app != app: return Response({'detail': unicode("suite:{0} not match test case of " "performance type".format(suite.id))}, status=status.HTTP_409_CONFLICT) validated_suite_list.append(suite) case_obj.save() case_obj.testsuite.clear() for suite in validated_suite_list: case_obj.testsuite.add(suite) new_serializer = TestcaseSerializer(case_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)