Ejemplo n.º 1
0
    def test_list_filter(self):
        """ Add a testsuite by context. """
        parser = TestsuiteTestCase.parser_create()

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

        cmd = "product add product2 branch2"
        args = parser.parse_args(cmd.split())
        args.func(args)

        cmd = "product add product3 branch2"
        args = parser.parse_args(cmd.split())
        args.func(args)

        cmd = "product add product3 branch3"
        args = parser.parse_args(cmd.split())
        args.func(args)

        testsuites = Product.filter(api.CONTEXT, "product3")
        branches = [str(item.branch) for item in testsuites]
        self.assertTrue(len(branches) == 2)
        self.assertTrue("branch2" in branches)
        self.assertTrue("branch3" in branches)
Ejemplo 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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def remove(product, branch):
    """ Remove a product given name and branch. """

    from testdb.models import Product
    from testdb.models import Context
    from testdb.models import Key
    from testdb.models import KVP
    from testdb.models import Testplan
    from testdb import builds

    try:
        context = Context.objects.get(name=CONTEXT)
        (product_key, _) = Key.objects.get_or_create(value=product)
        (branch_key, _) = Key.objects.get_or_create(value=branch)
    except (Context.DoesNotExist, Key.DoesNotExist), arg:
        raise Product.DoesNotExist(arg)
Ejemplo n.º 5
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")
Ejemplo n.º 6
0
    def test_order1(self):
        """ Confirm order works. """

        parser = TestsuiteTestCase.parser_create()

        cmd = "product add product4 branch1 --order 1"
        args = parser.parse_args(cmd.split())
        args.func(args)

        cmd = "product add product4 branch2 --order 2"
        args = parser.parse_args(cmd.split())
        args.func(args)

        cmd = "product add product5 branch3 --order 3"
        args = parser.parse_args(cmd.split())
        args.func(args)

        products = Product.filter(None, None)
        self.assertEqual(products.count(), 3)
        self.assertEqual(products[0].product.value, "product4")
        self.assertEqual(products[1].product.value, "product4")
        self.assertEqual(products[2].product.value, "product5")
Ejemplo n.º 7
0
    def test_order3(self):
        """ test_order3 Confirm order works. """

        parser = TestsuiteTestCase.parser_create()

        cmd = "product add product_order2 branch1 --order 2"
        args = parser.parse_args(cmd.split())
        args.func(args)

        cmd = "product add product_order1 branch2 --order 1"
        args = parser.parse_args(cmd.split())
        args.func(args)

        cmd = "product add product_order3 branch3 --order 3"
        args = parser.parse_args(cmd.split())
        args.func(args)

        products = Product.filter(api.CONTEXT, "product_order")
        self.assertEqual(products.count(), 3)
        self.assertEqual(str(products[0].product), "product_order1")
        self.assertEqual(str(products[1].product), "product_order2")
        self.assertEqual(str(products[2].product), "product_order3")
Ejemplo n.º 8
0
    try:
        context = Context.objects.get(name=CONTEXT)
        (product_key, _) = Key.objects.get_or_create(value=product)
        (branch_key, _) = Key.objects.get_or_create(value=branch)
    except (Context.DoesNotExist, Key.DoesNotExist), arg:
        raise Product.DoesNotExist(arg)
    product1 = Product.objects.get(context=context, product=product_key,
                                   branch=branch_key)

    try:
        product_kvp = KVP.objects.get(key__value="product", value=product)
        branch_kvp = KVP.objects.get(key__value="branch", value=branch)
        buildids = builds.filter(product_kvp, branch_kvp)
    except KVP.DoesNotExist, arg:
        raise Product.DoesNotExist(arg)

    testplan_name = product1.key_get("testplan", None)
    testplan_name = Testplan.context_get(testplan_name)
    testplan_context = Context.objects.get(name=testplan_name)
    testplan = Testplan.objects.get(context=testplan_context)
    for testplan in testplan.testplanorder_set.all():
        for buildid in buildids:
            for testsuite1 in testplan.testsuite_set.filter(kvps=buildid.id):
                for test1 in testsuite1.test_set.all():
                    print "MARK: ", buildid, testsuite1, test1, test1.status


def add_testplan(product, branch, testplan_name):
    """ Add testplan to product. """
    from testdb.models import Testplan