예제 #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)
예제 #2
0
def get_or_create(testplan_name, testsuite_name, order=ORDER_NEXT):
    """ Get or create a testplan and set order.

    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

    testplan_name = Testplan.context_get(testplan_name)
    (testplan, _) = Testplan.objects.get_or_create(context=testplan_name)
    (name, _) = TestsuiteName.objects.get_or_create(name=testsuite_name)

    try:
        (_, testsuite) = TestplanOrder.get(testplan, name)
        return (testplan, testsuite, False)
    except TestplanOrder.DoesNotExist:
        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

        (_, testsuite) = TestplanOrder.create(testplan, name, order)
        return (testplan, testsuite, True)
예제 #3
0
def add(context, testsuite_name, order):
    """ Add 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.
    @param testsuite_name The testsuite name for the testplan
    @param context 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 in the
                   context.
    @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

    context = Testplan.context_get(context)
    (testplan, created) = Testplan.objects.get_or_create(context=context)

    if order == ORDER_NEXT:
        find = testplan.testplanorder_set.all()
        try:
            order = find.order_by("-order")[0].order + 1
        except IndexError:
            order = 1
        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)
    current_order = order
    for prevplan in planorders.order_by("order"):
        if prevplan.order == current_order:
            prevplan.order += 1
            prevplan.save()
            current_order = prevplan.order

    (name, _) = TestsuiteName.objects.get_or_create(name=testsuite_name)
    (_, created) = TestplanOrder.create(testplan, name, order)
    return (testplan, created)
예제 #4
0
def add(context, testsuite_name, order):
    """ Add 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.
    @param testsuite_name The testsuite name for the testplan
    @param context 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 in the
                   context.
    @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

    context = Testplan.context_get(context)
    (testplan, created) = Testplan.objects.get_or_create(context=context)

    if order == ORDER_NEXT:
        find = testplan.testplanorder_set.all()
        try:
            order = find.order_by("-order")[0].order + 1
        except IndexError:
            order = 1
        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)
    current_order = order
    for prevplan in planorders.order_by("order"):
        if prevplan.order == current_order:
            prevplan.order += 1
            prevplan.save()
            current_order = prevplan.order

    (name, _) = TestsuiteName.objects.get_or_create(name=testsuite_name)
    (_, created) = TestplanOrder.create(testplan, name, order)
    return (testplan, created)