Ejemplo n.º 1
0
def change(testplan_name, testsuite_name, order):
    """ Change the order of the testsuite.

    Order is just that the location of the testplan in the list of
    testplans. The order effects the location the testplan appears on web
    pages.  When complete testplan order number is sequential with no gaps.
    @param testsuite_name The testsuite name for the testplan
    @param testplan_name Testplan context organizes testplans in a logical
                         group. Testplans with the same context are in the
                         same group. The order indicates the order of the
                         testplan.
    @param order the location of testsuite in the testplan. To change the
                 order of an existing testplan pass in a different number.
    """
    from testdb.models import Testplan
    from testdb.models import TestplanOrder
    from testdb.models import TestsuiteName

    try:
        testplan_name = Testplan.context_get(testplan_name)
        testplan = Testplan.objects.get(context=testplan_name)
        name = TestsuiteName.objects.get(name=testsuite_name)
    except Testplan.DoesNotExist:
        raise TestplanOrder.DoesNotExist(
            "TestplanOrder: %s %s does not exist".testplan_name,
            testsuite_name)
    (planorder, testsuite) = TestplanOrder.get(testplan, name)

    if order == ORDER_NEXT:
        find = testplan.testplanorder_set.all()
        try:
            ##
            # find the last item.
            order = find.order_by("-order")[0].order + 1
        except IndexError:
            order = ORDER_FIRST
        logging.info("using order %d", order)

    ##
    # Assert order is not -1.
    # Order is specified so now we have to move something.
    planorders = testplan.testplanorder_set.filter(order__gte=order)
    new_order = order
    for item in planorders.order_by("order"):
        if new_order == item.order:
            item.order += 1
            item.save()
            new_order += 1

    planorder.order = order
    planorder.save()
    return (testplan, testsuite)
Ejemplo n.º 2
0
def change(testplan_name, testsuite_name, order):
    """ Change the order of the testsuite.

    Order is just that the location of the testplan in the list of
    testplans. The order effects the location the testplan appears on web
    pages.  When complete testplan order number is sequential with no gaps.
    @param testsuite_name The testsuite name for the testplan
    @param testplan_name Testplan context organizes testplans in a logical
                         group. Testplans with the same context are in the
                         same group. The order indicates the order of the
                         testplan.
    @param order the location of testsuite in the testplan. To change the
                 order of an existing testplan pass in a different number.
    """
    from testdb.models import Testplan
    from testdb.models import TestplanOrder
    from testdb.models import TestsuiteName

    try:
        testplan_name = Testplan.context_get(testplan_name)
        testplan = Testplan.objects.get(context=testplan_name)
        name = TestsuiteName.objects.get(name=testsuite_name)
    except Testplan.DoesNotExist:
        raise TestplanOrder.DoesNotExist("TestplanOrder: %s %s does not exist".
                                         testplan_name, testsuite_name)
    (planorder, testsuite) = TestplanOrder.get(testplan, name)

    if order == ORDER_NEXT:
        find = testplan.testplanorder_set.all()
        try:
            ##
            # find the last item.
            order = find.order_by("-order")[0].order + 1
        except IndexError:
            order = ORDER_FIRST
        logging.info("using order %d", order)

    ##
    # Assert order is not -1.
    # Order is specified so now we have to move something.
    planorders = testplan.testplanorder_set.filter(order__gte=order)
    new_order = order
    for item in planorders.order_by("order"):
        if new_order == item.order:
            item.order += 1
            item.save()
            new_order += 1

    planorder.order = order
    planorder.save()
    return (testplan, testsuite)