def environment_properties(request, template_name = 'environment/property.html'): """ Edit environemnt properties and values belong to """ # Initial the ajax response ajax_response = { 'response': 'ok' } message = '' # Actions of create properties if request.REQUEST.get('action') == 'add': if not request.user.has_perm('management.add_tcmsenvproperty'): ajax_response['response'] = 'Permission denied' return HttpResponse(json_dumps(ajax_response)) if not request.REQUEST.get('name'): response = { 'response': 'Property name is required' } return HttpResponse(json_dumps(ajax_response)) try: new_property = TCMSEnvProperty.objects.create( name = request.REQUEST['name'] ) ajax_response['id'] = new_property.id ajax_response['name'] = new_property.name except IntegrityError, error: if error[1].startswith('Duplicate'): ajax_response['response'] = 'Environment proprerty named \'%s\' already exists, please select another name.' % request.REQUEST['name'] else: ajax_response['response'] = error[1] return HttpResponse(json_dumps(ajax_response)) return HttpResponse(json_dumps(ajax_response))
def delete_cases(self): if not request.REQUEST.get('case'): ajax_response['rc'] = 1 ajax_response['reponse'] = 'At least one case is required to delete.' return HttpResponse(json_dumps(ajax_response)) tcs = TestCase.objects.filter(case_id__in=request.REQUEST.getlist('case')) # Log Action tp_log = TCMSLog(model=tp) for tc in tcs: tp_log.make( who = request.user, action = 'Remove case %s from plan %s' % (tc.case_id, tp.plan_id) ) tc.log_action( who = request.user, action = 'Remove from plan %s' % tp.plan_id ) tp.delete_case(case = tc) return HttpResponse(json_dumps(ajax_response))
def environment_groups(request, template_name='environment/groups.html'): """ Environements list """ env_groups = TCMSEnvGroup.objects # Initial the response to browser ajax_response = {'rc': 0, 'response': 'ok'} has_perm = request.user.has_perm user_action = request.REQUEST.get('action') # Add action if user_action == 'add': if not has_perm('management.add_tcmsenvgroup'): ajax_response['response'] = 'Permission denied.' ajax_response['rc'] = 1 return HttpResponse(json_dumps(ajax_response)) group_name = request.REQUEST.get('name') # Get the group name of envrionment from javascript if not group_name: ajax_response['response'] = 'Environment group name is required.' ajax_response['rc'] = 1 return HttpResponse(json_dumps(ajax_response)) try: env = env_groups.create(name=group_name, manager_id=request.user.id, modified_by_id=None) env.log_action(who=request.user, action='Initial env group %s' % env.name) ajax_response['id'] = env.id return HttpResponse(json_dumps(ajax_response)) except IntegrityError, error: if error[1].startswith('Duplicate'): response_msg = 'Environment group named \'%s\' already ' \ 'exists, please select another name.' % group_name ajax_response['response'] = response_msg else: ajax_response['response'] = error[1] ajax_response['rc'] = 1 return HttpResponse(json_dumps(ajax_response)) except:
def environment_groups(request, template_name="environment/groups.html"): """ Environements list """ env_groups = TCMSEnvGroup.objects # Initial the response to browser ajax_response = {"rc": 0, "response": "ok"} has_perm = request.user.has_perm user_action = request.REQUEST.get("action") # Add action if user_action == "add": if not has_perm("management.add_tcmsenvgroup"): ajax_response["response"] = "Permission denied." ajax_response["rc"] = 1 return HttpResponse(json_dumps(ajax_response)) group_name = request.REQUEST.get("name") # Get the group name of envrionment from javascript if not group_name: ajax_response["response"] = "Environment group name is required." ajax_response["rc"] = 1 return HttpResponse(json_dumps(ajax_response)) try: env = env_groups.create(name=group_name, manager_id=request.user.id, modified_by_id=None) env.log_action(who=request.user, action="Initial env group %s" % env.name) ajax_response["id"] = env.id return HttpResponse(json_dumps(ajax_response)) except IntegrityError, error: if error[1].startswith("Duplicate"): response_msg = ( "Environment group named '%s' already " "exists, please select another name." % group_name ) ajax_response["response"] = response_msg else: ajax_response["response"] = error[1] ajax_response["rc"] = 1 return HttpResponse(json_dumps(ajax_response)) except:
def environment_properties(request, template_name="environment/property.html"): """ Edit environemnt properties and values belong to """ # Initial the ajax response ajax_response = {"rc": 0, "response": "ok"} message = "" has_perm = request.user.has_perm user_action = request.REQUEST.get("action") # Actions of create properties if user_action == "add": if not has_perm("management.add_tcmsenvproperty"): ajax_response["response"] = "Permission denied" ajax_response["rc"] = 1 return HttpResponse(json_dumps(ajax_response)) property_name = request.REQUEST.get("name") if not property_name: ajax_response["response"] = "Property name is required" ajax_response["rc"] = 1 return HttpResponse(json_dumps(ajax_response)) try: new_property = TCMSEnvProperty.objects.create(name=property_name) ajax_response["id"] = new_property.id ajax_response["name"] = new_property.name except IntegrityError, error: if error[1].startswith("Duplicate"): resp_msg = ( "Environment proprerty named '%s' already " "exists, please select another name." % property_name ) else: resp_msg = error[1] ajax_response["rc"] = 1 ajax_response["response"] = resp_msg return HttpResponse(json_dumps(ajax_response)) return HttpResponse(json_dumps(ajax_response))
def environment_properties(request, template_name='environment/property.html'): """ Edit environemnt properties and values belong to """ # Initial the ajax response ajax_response = {'rc': 0, 'response': 'ok'} message = '' has_perm = request.user.has_perm user_action = request.REQUEST.get('action') # Actions of create properties if user_action == 'add': if not has_perm('management.add_tcmsenvproperty'): ajax_response['response'] = 'Permission denied' ajax_response['rc'] = 1 return HttpResponse(json_dumps(ajax_response)) property_name = request.REQUEST.get('name') if not property_name: ajax_response['response'] = 'Property name is required' ajax_response['rc'] = 1 return HttpResponse(json_dumps(ajax_response)) try: new_property = TCMSEnvProperty.objects.create(name=property_name) ajax_response['id'] = new_property.id ajax_response['name'] = new_property.name except IntegrityError, error: if error[1].startswith('Duplicate'): resp_msg = 'Environment proprerty named \'%s\' already ' \ 'exists, please select another name.' % property_name else: resp_msg = error[1] ajax_response['rc'] = 1 ajax_response['response'] = resp_msg return HttpResponse(json_dumps(ajax_response)) return HttpResponse(json_dumps(ajax_response))
def order_cases(self): """ Resort case with new order """ # Current we should rewrite all of cases belong to the plan. # Because the cases sortkey in database is chaos, # Most of them are None. if not request.REQUEST.get('case'): ajax_response['rc'] = 1 ajax_response['reponse'] = 'At least one case is required to re-order.' return HttpResponse(json_dumps(ajax_response)) tc_pks = request.REQUEST.getlist('case') tcs = TestCase.objects.filter(pk__in = tc_pks) for tc in tcs: new_sort_key = (tc_pks.index(str(tc.pk)) + 1) * 10 TestCasePlan.objects.filter(plan = tp, case = tc).update(sortkey = new_sort_key) return HttpResponse(json_dumps(ajax_response))
def environment_groups(request, template_name = 'environment/groups.html'): """ Environements list """ env_groups = TCMSEnvGroup.objects # Initial the response to browser ajax_response = { 'response': 'ok' } # Add action if request.REQUEST.get('action') == 'add': if not request.user.has_perm('management.add_tcmsenvgroup'): ajax_response['response'] = 'Permission denied.' return HttpResponse(json_dumps(ajax_response)) # Get the group name of envrionment from javascript if not request.REQUEST.get('name'): ajax_response['response'] = 'Environment group name is required.' return HttpResponse(json_dumps(ajax_response)) try: env = env_groups.create( name = request.REQUEST['name'], manager_id = request.user.id, modified_by_id = None, ) env.log_action( who = request.user, action = 'Initial env group %s' % env.name ) ajax_response['id'] = env.id return HttpResponse(json_dumps(ajax_response)) except IntegrityError, error: if error[1].startswith('Duplicate'): ajax_response['response'] = 'Environment group named \'%s\' already exists, please select another name.' % request.REQUEST['name'] else: ajax_response['response'] = error[1] return HttpResponse(json_dumps(ajax_response)) except:
def add(self): if not self.request.user.has_perm('testplans.add_testplancomponent'): if self.is_ajax(): return HttpResponse(json_dumps(self.__msgs__['permission_denied'])) return self.render(message=self.__msgs__['permission_denied']['response']) for tp in self.tps: for c in cs: try: tp.add_component(c) except: raise return self.render()
def render(self, message=None): if request.REQUEST.get('multiple'): return HttpResponse(json_dumps(ajax_response)) if request.REQUEST.get('type'): from django.core import serializers obj = TestPlanComponent.objects.filter( plan__in=self.tps, ) return HttpResponse( serializers.serialize(request.REQUEST['type'], obj) ) return direct_to_template(request, template_name, { 'test_plan': self.tps[0], })
env.log_action( who = request.user, action = 'Initial env group %s' % env.name ) ajax_response['id'] = env.id return HttpResponse(json_dumps(ajax_response)) except IntegrityError, error: if error[1].startswith('Duplicate'): ajax_response['response'] = 'Environment group named \'%s\' already exists, please select another name.' % request.REQUEST['name'] else: ajax_response['response'] = error[1] return HttpResponse(json_dumps(ajax_response)) except: ajax_response['response'] = 'Unknown error.' return HttpResponse(json_dumps(ajax_response)) # Del action if request.REQUEST.get('action') == 'del': if request.REQUEST.get('id'): try: env = env_groups.get(id = request.REQUEST['id']) manager_id = env.manager_id if (request.user.id != manager_id): if not request.user.has_perm('management.delete_tcmsenvgroup'): ajax_response['response']='Permission denied.' return HttpResponse(json_dumps(ajax_response)) env.delete() ajax_response['response']='ok' except TCMSEnvGroup.DoesNotExist, error:
ajax_response['id'] = env.id return HttpResponse(json_dumps(ajax_response)) except IntegrityError, error: if error[1].startswith('Duplicate'): response_msg = 'Environment group named \'%s\' already ' \ 'exists, please select another name.' % group_name ajax_response['response'] = response_msg else: ajax_response['response'] = error[1] ajax_response['rc'] = 1 return HttpResponse(json_dumps(ajax_response)) except: ajax_response['response'] = 'Unknown error.' return HttpResponse(json_dumps(ajax_response)) # Del action if user_action == 'del': if request.REQUEST.get('id'): try: env = env_groups.get(id=request.REQUEST['id']) manager_id = env.manager_id if request.user.id != manager_id: if not has_perm('management.delete_tcmsenvgroup'): ajax_response['response'] = 'Permission denied.' return HttpResponse(json_dumps(ajax_response)) env.delete() ajax_response['response'] = 'ok' except TCMSEnvGroup.DoesNotExist, error:
def cases(request, plan_id): """Process the xml with import""" ajax_response = {'rc': 0, 'response': 'ok'} tp = get_object_or_404(TestPlan, plan_id=plan_id) class CaseActions(object): def __init__(self, request, tp): self.__all__ = ['link_cases', 'delete_cases', 'order_cases', 'import_cases'] self.request = request self.tp = tp def link_cases(self, template_name='plan/search_case.html'): """ Handle to form to add case to plans. """ SUB_MODULE_NAME = 'plans' tcs = None if request.REQUEST.get('action') == 'add_to_plan': if request.user.has_perm('testcases.add_testcaseplan'): tcs = TestCase.objects.filter(case_id__in=request.REQUEST.getlist('case')) for tc in tcs: tp.add_case(tc) else: return HttpResponse("Permission Denied") return HttpResponseRedirect( reverse('tcms.apps.testplans.views.get', args = [plan_id, ]) ) if request.REQUEST.get('action') == 'search': form = SearchCaseForm(request.REQUEST) form.populate(product_id = request.REQUEST.get('product')) if form.is_valid(): tcs = TestCase.list(form.cleaned_data) tcs = tcs.select_related( 'author', 'default_tester', 'case_status', 'priority', 'category', 'tag__name' ) tcs = tcs.exclude(case_id__in = tp.case.values_list( 'case_id', flat = True )) else: form = SearchCaseForm(initial={ 'product': tp.product_id, 'product_version': tp.get_version_id(), 'case_status_id': TestCaseStatus.get_CONFIRMED() }) return direct_to_template(request, template_name, { 'module': MODULE_NAME, 'sub_module': SUB_MODULE_NAME, 'test_plan': tp, 'test_cases': tcs, 'search_form': form, }) def delete_cases(self): if not request.REQUEST.get('case'): ajax_response['rc'] = 1 ajax_response['reponse'] = 'At least one case is required to delete.' return HttpResponse(json_dumps(ajax_response)) tcs = TestCase.objects.filter(case_id__in=request.REQUEST.getlist('case')) # Log Action tp_log = TCMSLog(model=tp) for tc in tcs: tp_log.make( who = request.user, action = 'Remove case %s from plan %s' % (tc.case_id, tp.plan_id) ) tc.log_action( who = request.user, action = 'Remove from plan %s' % tp.plan_id ) tp.delete_case(case = tc) return HttpResponse(json_dumps(ajax_response)) def order_cases(self): """ Resort case with new order """ # Current we should rewrite all of cases belong to the plan. # Because the cases sortkey in database is chaos, # Most of them are None. if not request.REQUEST.get('case'): ajax_response['rc'] = 1 ajax_response['reponse'] = 'At least one case is required to re-order.' return HttpResponse(json_dumps(ajax_response)) tc_pks = request.REQUEST.getlist('case') tcs = TestCase.objects.filter(pk__in = tc_pks) for tc in tcs: new_sort_key = (tc_pks.index(str(tc.pk)) + 1) * 10 TestCasePlan.objects.filter(plan = tp, case = tc).update(sortkey = new_sort_key) return HttpResponse(json_dumps(ajax_response)) def import_cases(self): if request.method == 'POST': # Process import case from XML action if not request.user.has_perm('testcases.add_testcaseplan'): return HttpResponse(Prompt.render( request = request, info_type = Prompt.Alert, info = 'Permission denied', next = reverse('tcms.apps.testplans.views.get', args = [plan_id, ]), )) xml_form = ImportCasesViaXMLForm(request.REQUEST, request.FILES) if xml_form.is_valid(): i = 0 for case in xml_form.cleaned_data['xml_file']: i += 1 # Get the case category from the case and related to the product of the plan try: category = TestCaseCategory.objects.get( product = tp.product, name = case['category_name'] ) except TestCaseCategory.DoesNotExist: category = TestCaseCategory.objects.create( product = tp.product, name = case['category_name'] ) # Start to create the objects tc = TestCase.objects.create( is_automated=case['is_automated'], script=None, arguments=None, summary=case['summary'], requirement=None, alias=None, estimated_time='0:0:0', case_status_id=case['case_status_id'], category_id=category.id, priority_id=case['priority_id'], author_id=case['author_id'], default_tester_id=case['default_tester_id'], notes=case['notes'], ) TestCasePlan.objects.create(plan=tp, case=tc, sortkey=i*10) tc.add_text(case_text_version=1, author=case['author'], action=case['action'], effect=case['effect'], setup=case['setup'], breakdown=case['breakdown'],) #handle tags if case['tags']: for tag in case['tags']: tc.add_tag(tag=tag) tc.add_to_plan(plan=tp) return HttpResponseRedirect(reverse('tcms.apps.testplans.views.get', args=[plan_id, ]) + '#testcases') else: return HttpResponse(Prompt.render( request=request, info_type=Prompt.Alert, info=xml_form.errors, next=reverse('tcms.apps.testplans.views.get', args = [plan_id, ]) + '#testcases' )) else: return HttpResponseRedirect(reverse('tcms.apps.testplans.views.get', args=[plan_id, ]) + '#testcases') tp = get_object_or_404(TestPlan, plan_id=plan_id) cas = CaseActions(request, tp) actions = request.REQUEST.get('a') if not actions in cas.__all__: if request.REQUEST.get('format') == 'json': ajax_response['rc'] = 1 ajax_response['response'] = 'Unrecognizable actions' return HttpResponse(json_dumps(ajax_response)) return HttpResponse(Prompt.render( request=request, info_type=Prompt.Alert, info=message, next=reverse('tcms.apps.testplans.views.get', args = [plan_id, ]), )) func = getattr(cas, actions) return func()