def add_key(context, order, key, value): """ Add a key into the testplan. """ from testdb.models import Testplan from testdb.models import Testsuite from testdb.models import Key from testdb.models import KVP logging.info("add %s=%s to testsuite %s %s", key, value, context, order) context = Testplan.context_get(context) testplan = Testplan.objects.get(context=context) planorder = testplan.testplanorder_set.get(order=order) testsuite = Testsuite.objects.get(context=context, testplanorder=planorder) (testkey, _) = KVP.get_or_create(key=key, value=value) testsuite.key_change(testkey) ## # (key, _) = Key.objects.get_or_create(value=key) testplan.testplankvp_set.get_or_create(key=key) # ## return (testsuite, testkey)
def atest_list_filter(self): """ Add a testsuite by context. """ parser = TestsuiteTestCase.parser_create() cmd = "testplan --context testplan1 add testsuite_bob1 --order 0" args = parser.parse_args(cmd.split()) args.func(args) cmd = "testplan --context testplan1 test add 0 test2" args = parser.parse_args(cmd.split()) args.func(args) cmd = "testplan --context testplan2 add testsuite_bob2 --order 1" args = parser.parse_args(cmd.split()) args.func(args) cmd = "testplan --context testplan2 test add 1 test3" args = parser.parse_args(cmd.split()) args.func(args) cmd = "testplan --context testplan2 add testsuite_ken1 --order 2" args = parser.parse_args(cmd.split()) args.func(args) cmd = "testplan --context testplan2 test add 2 test4" args = parser.parse_args(cmd.split()) args.func(args) context = Testplan.context_get("testplan2") testsuites = Testsuite.objects.filter(context=context) names = [item.name.name for item in testsuites] self.assertTrue(len(names) == 2) self.assertTrue(any("bob2" in name for name in names)) self.assertTrue(any("ken1" in name for name in names))
def add_testplan(product, branch, testplan_name): """ Add testplan to product. """ from testdb.models import Testplan (product1, _) = get_or_create(product, branch) context = Testplan.context_get(testplan_name) Testplan.objects.get_or_create(context=context) product1.key_get_or_create("testplan", testplan_name)
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)
def get(context, testkeys): """ Get testplan. """ from testdb.models import Testplan context = Testplan.context_get(context) if len(testkeys) == 0: return Testplan.objects.get(context=context) else: find = Testplan.objects.filter(context=context) for testkey in testkeys[:-1]: find = find.filter(keys=testkey) return find.get(keys=testkeys[-1])
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)
def remove_key(context, order, key): """ Remove a key from the testplan. """ from testdb.models import Testplan from testdb.models import Testsuite logging.info("remove %s from testsuite %s %s", key, context, order) context = Testplan.context_get(context) testplan = Testplan.objects.get(context=context) planorder = testplan.testplanorder_set.get(order=order) testsuite = Testsuite.objects.get(context=context, testplanorder=planorder) chitem = testsuite.key_remove(key) return chitem
def pack(testplan_name): """ Pack testplan sequentially with no gaps.""" from testdb.models import Testplan testplan_name = Testplan.context_get(testplan_name) testplan = Testplan.objects.get(context=testplan_name) ## # Make sure test plan order entries are sequential with no gaps. order = ORDER_FIRST for planorder in testplan.testplanorder_set.all().order_by("order"): if int(order) != int(planorder.order): planorder.order = order planorder.save() order += 1 ## return True
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)
(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 (product1, _) = get_or_create(product, branch)