示例#1
0
def ajax_addtests(request, testplan_id):
    current_edit = []
    testplan = TestPlan.objects.get(id=testplan_id)
    add_array = request.GET['add']
    add_list = add_array.split(",")
    received_count = len(add_list)

    try:
        testplan = TestPlan.objects.get(id=testplan_id)
        initial_count = testplan.testcases.count()
        expected_count = initial_count + received_count

        for testcase_id in add_list:
            testplan_testcase_link = TestplanTestcaseLink(testplan=testplan,
                                                          testcase=TestCase.objects.get(pk=testcase_id))
            testplan_testcase_link.save()

        actual_count = testplan.testcases.count()
        if actual_count == expected_count:
            number = testplan.testcases.count() - initial_count
            alert_type = "alert-success"
            message = "Added %d tests to %s." % (received_count, testplan.name)
        elif actual_count == initial_count:
            alert_type = "alert-info"
            message = "No changes made to %s." % (testplan.name)
        else:
            alert_type = "alert-info"
            net_count = actual_count - initial_count
            present_count = received_count - net_count
            message = "Added %d tests to <em>%s<em>.\n%d tests already present." % (
                net_count, testplan.name, present_count)
        return HttpResponse(
            json.dumps({
                'currentEdit': current_edit,
                "alertType": alert_type,
                "alertflag": True,
                'message': message
            })
        )
    except ValueError, ex:
        return HttpResponse(
            json.dumps({
                "currentEdit": current_edit,
                "alertType": "alert-error",
                "alertflag": True,
                "message": "Please select the tests to add"
            })
        )
示例#2
0
def ajax_addtests(request, testplan_id):
    current_edit = []
    testplan = TestPlan.objects.get(id=testplan_id)
    add_array = request.GET['add']
    add_list = add_array.split(",")
    received_count = len(add_list)

    try:
        testplan = TestPlan.objects.get(id=testplan_id)
        initial_count = testplan.testcases.count()
        expected_count = initial_count + received_count

        for testcase_id in add_list:
            testplan_testcase_link = TestplanTestcaseLink(
                testplan=testplan,
                testcase=TestCase.objects.get(pk=testcase_id))
            testplan_testcase_link.save()

        actual_count = testplan.testcases.count()
        if actual_count == expected_count:
            number = testplan.testcases.count() - initial_count
            alert_type = "alert-success"
            message = "Added %d tests to %s." % (received_count, testplan.name)
        elif actual_count == initial_count:
            alert_type = "alert-info"
            message = "No changes made to %s." % (testplan.name)
        else:
            alert_type = "alert-info"
            net_count = actual_count - initial_count
            present_count = received_count - net_count
            message = "Added %d tests to <em>%s<em>.\n%d tests already present." % (
                net_count, testplan.name, present_count)
        return HttpResponse(
            json.dumps({
                'currentEdit': current_edit,
                "alertType": alert_type,
                "alertflag": True,
                'message': message
            }))
    except ValueError, ex:
        return HttpResponse(
            json.dumps({
                "currentEdit": current_edit,
                "alertType": "alert-error",
                "alertflag": True,
                "message": "Please select the tests to add"
            }))
示例#3
0
def clone_test_plan_view(request, test_plan_id):

    if request.method == 'GET':
        plan = TestPlan.objects.get(id=test_plan_id)
        previous_name = plan.name
        previous_id = plan.id
        plan.name = "CLONE OF " + plan.name
        plan.id = None
        author = request.user.username
        plan.creator = request.user
        form = TestPlanForm(instance=plan)

        return render_to_response(
            'test_plan_form.html', {
            'form': form,
            'type': 'Clone Test Plan',
            'plan': plan,
            'name': plan.name,
            'previous_id': previous_id,
            'previous_name': previous_name,
            'author': author,
            'clone': True
            }, context_instance=RequestContext(request))
    else:

        form = TestPlanForm(request.POST)
        prevous_testplan = TestPlan.objects.get(id=request.POST['previous_plan_id'])
        try:
            testplan = form.save()
            message = "Edited the plan successfully"
        except:
            message = "it failed"
            return render_to_response('test_plan_form.html', {'form': form, 'type': 'Clone Test Plan', 'plan': prevous_testplan, 'name': prevous_testplan.name}, context_instance=RequestContext(request))

        tests = prevous_testplan.testcases.all()

        for test in tests:
            testplan_testcase_link = TestplanTestcaseLink(testplan=testplan, testcase=test)
            testplan_testcase_link.save()

        message = message + " and added " + str(tests.count()) + " tests"
        messages.add_message(request, messages.SUCCESS, message)
        return render_to_response(
            'test_plan_add_testcases.html',
            {"testplan": testplan
             }, context_instance=RequestContext(request))
def clone_test_plan_view(request, test_plan_id):

    if request.method == 'GET':
        plan = TestPlan.objects.get(id=test_plan_id)
        previous_name = plan.name
        previous_id = plan.id
        plan.name = "CLONE OF " + plan.name
        plan.id = None
        author = request.user.username
        plan.creator = request.user
        form = TestPlanForm(instance=plan)

        return render_to_response(
            'test_plan_form.html', {
            'form': form,
            'type': 'Clone Test Plan',
            'plan': plan,
            'name': plan.name,
            'previous_id': previous_id,
            'previous_name': previous_name,
            'author': author,
            'clone': True
            }, context_instance=RequestContext(request))
    else:

        form = TestPlanForm(request.POST)
        prevous_testplan = TestPlan.objects.get(id=request.POST['previous_plan_id'])

        testplan = form.save()
        message = "Edited the plan successfully"

        tests = prevous_testplan.testcases.all()

        for test in tests:
            testplan_testcase_link = TestplanTestcaseLink(testplan=testplan, testcase=test)
            testplan_testcase_link.save()

        message = message + " and added " + str(tests.count()) + " tests"
        messages.add_message(request, messages.SUCCESS, message)
        return render_to_response(
            'test_plan_add_testcases.html',
            {"testplan": testplan
             }, context_instance=RequestContext(request))