Exemplo n.º 1
0
def get_or_create(productname, branchname, order=-1):
    """ Get or create a testplan in a certain order.

    @param product_name Is the name of the product
    @param order order is the location of the testplan in the list of
                 testplans. The order effects the location the testplan
                 appears on web pages.
    """
    from testdb.models import Product
    from testdb.models import KVP

    logging.info("adding product %s %s", productname, branchname)

    ##
    # Make sure to track branch and product against KVP. This is done
    # incase user decides to make these keys strict.
    KVP.get_or_create("branch", branchname)
    KVP.get_or_create("product", productname)

    if order == -1:
        find = Product.objects.filter(context__name=CONTEXT)
        try:
            order = find.order_by("-order")[0].order
        except IndexError:
            order = 0

        order += 1
        logging.info("using order %d", order)

    ##
    # Order is specified so now we have to move something.
    products = Product.objects.filter(context__name=CONTEXT,
                                      order__gte=order).order_by("order")
    current_order = order
    for product in products:
        if product.order == current_order:
            product.order += 1
            logging.debug("updating order %s to %d", productname,
                          product.order)
            product.save()
            current_order = product.order

    (product, created) = Product.get_or_create(CONTEXT, productname,
                                               branchname)
    product.order = order
    product.save()

    return (product, created)
Exemplo n.º 2
0
def get_or_create(productname, branchname, order=-1):
    """ Get or create a testplan in a certain order.

    @param product_name Is the name of the product
    @param order order is the location of the testplan in the list of
                 testplans. The order effects the location the testplan
                 appears on web pages.
    """
    from testdb.models import Product
    from testdb.models import KVP

    logging.info("adding product %s %s", productname, branchname)

    ##
    # Make sure to track branch and product against KVP. This is done
    # incase user decides to make these keys strict.
    KVP.get_or_create("branch", branchname)
    KVP.get_or_create("product", productname)

    if order == -1:
        find = Product.objects.filter(context__name=CONTEXT)
        try:
            order = find.order_by("-order")[0].order
        except IndexError:
            order = 0

        order += 1
        logging.info("using order %d", order)

    ##
    # Order is specified so now we have to move something.
    products = Product.objects.filter(context__name=CONTEXT,
                                      order__gte=order).order_by("order")
    current_order = order
    for product in products:
        if product.order == current_order:
            product.order += 1
            logging.debug("updating order %s to %d", productname,
                          product.order)
            product.save()
            current_order = product.order

    (product, created) = Product.get_or_create(CONTEXT, productname,
                                               branchname)
    product.order = order
    product.save()

    return (product, created)
Exemplo n.º 3
0
    def test_add_testplan(self):
        """ test_add_testplan test add_testplan. """

        parser = TestsuiteTestCase.parser_create()

        cmd = "product add product1 branch1"
        args = parser.parse_args(cmd.split())
        args.func(args)

        cmd = "product testplan add product1 branch1 default"
        args = parser.parse_args(cmd.split())
        args.func(args)

        (product1, critem) = Product.get_or_create("product.default",
                                                   "product1", "branch1")
        self.assertFalse(critem)
        self.assertTrue(product1)

        self.assertEqual(product1.key_get("testplan"), "default")