def _create(self, name, product, version, type, **kwargs): """ Create a new test plan """ hash = {} # Name if name is None: raise TCMSError("Name required for creating new test plan") hash["name"] = name # Product if product is None: raise TCMSError("Product required for creating new test plan") elif isinstance(product, (int, str)): product = Product(product) hash["product"] = product.id # Version if version is None: raise TCMSError("Version required for creating new test plan") elif isinstance(version, int): version = Version(version) elif isinstance(version, str): version = Version(name=version, product=product) hash["default_product_version"] = version.id # Type if type is None: raise TCMSError("Type required for creating new test plan") elif isinstance(type, (int, str)): type = PlanType(type) hash["type"] = type.id # Parent parent = kwargs.get("parent") if parent is not None: if isinstance(parent, int): parent = TestPlan(parent) hash["parent"] = parent.id # Document - if not explicitly specified, put empty text hash["text"] = kwargs.get("text", " ") # Workaround for BZ#725995 hash["is_active"] = "1" # Submit log.info("Creating a new test plan") log.data(pretty(hash)) inject = self._server.TestPlan.create(hash) log.data(pretty(inject)) try: self._id = inject["plan_id"] except TypeError: log.debug("Failed to create a new test plan") log.data(pretty(hash)) log.data(pretty(inject)) raise TCMSError("Failed to create test plan") self._fetch(inject) log.info("Successfully created {0}".format(self))
def _fetch(self, inject=None): """ Initialize / refresh test plan data. Either fetch them from the server or use provided hash. """ TCMS._fetch(self, inject) # Fetch the data hash from the server unless provided if inject is None: log.info("Fetching test plan " + self.identifier) try: inject = self._server.TestPlan.filter({'pk': self.id})[0] except IndexError as error: log.debug(error) raise TCMSError( "Failed to fetch test plan TP#{0}".format(self.id)) self._inject = inject # Otherwise just initialize the id from inject else: self._id = inject["plan_id"] log.debug("Initializing test plan " + self.identifier) log.data(pretty(inject)) if "plan_id" not in inject: log.data(pretty(inject)) raise TCMSError("Failed to initialize " + self.identifier) # Set up attributes self._author = User(inject["author_id"]) if inject["owner_id"] is not None: self._owner = User(inject["owner_id"]) else: self._owner = None self._name = inject["name"] self._product = Product({ "id": inject["product_id"], "name": inject["product"]}) self._version = Version({ "id": inject["product_version_id"], "value": inject["product_version"], "product_id": inject["product_id"]}) self._type = PlanType(inject["type_id"]) self._status = PlanStatus(inject["is_active"] in ["True", True]) if inject["parent_id"] is not None: self._parent = TestPlan(inject["parent_id"]) else: self._parent = None # Initialize containers self._testcases = PlanCases(self) self._testruns = PlanRuns(self) self._children = ChildPlans(self) # If all tags are cached, initialize them directly from the inject if "tag" in inject and Tag._is_cached(inject["tag"]): self._tags = PlanTags( self, inset=[Tag(tag) for tag in inject["tag"]]) else: self._tags = PlanTags(self) # Index the fetched object into cache self._index()
def _create(self, testplan, product=None, version=None, build=None, summary=None, notes=None, manager=None, tester=None, **kwargs): """ Create a new test run """ hash = {} # Test plan if isinstance(testplan, int): testplan = TestPlan(testplan) hash["plan"] = testplan.id # Product & version if product is None: product = testplan.product elif not isinstance(product, Product): product = Product(product) hash["product"] = product.id if version is None: version = testplan.version elif isinstance(version, int): version = Version(version) else: version = Version(name=version, product=product) hash["product_version"] = version.id # Build if build is None: build = "unspecified" if isinstance(build, str): build = Build(build=build, product=product) hash["build"] = build.id # Summary & notes if summary is None: summary = "{0} on {1}".format(testplan.name, build) if notes is None: notes = "" hash["summary"] = summary hash["notes"] = notes # Manager & tester (current user by default) if not isinstance(manager, User): manager = User(manager) if not isinstance(tester, User): tester = User(tester) hash["manager"] = manager.id hash["default_tester"] = tester.id # Submit to the server and initialize log.info("Creating a new test run based on {0}".format(testplan)) log.data(pretty(hash)) testrunhash = self._server.TestRun.create(hash) log.data(pretty(testrunhash)) try: self._id = testrunhash["run_id"] except TypeError: log.debug("Failed to create a new test run based on {0}".format( testplan)) log.data(pretty(hash)) log.data(pretty(testrunhash)) raise TCMSError("Failed to create test run") self._fetch(testrunhash) # Add newly created test run to testplan.testruns container if PlanRuns._is_cached(testplan.testruns): testplan.testruns._fetch(list(testplan.testruns) + [self]) log.info("Successfully created {0}".format(self))