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 _fetch(self, inject=None): """ Fetch tag data from the server """ TCMS._fetch(self, inject) # Directly fetch from the initial object dict if inject is not None: log.debug("Initializing Tag ID#{0}".format(inject["id"])) log.data(pretty(inject)) self._id = inject["id"] self._name = inject["name"] # Search by tag id elif self._id is not TCMSNone: try: log.info("Fetching tag " + self.identifier) inject = self._server.Tag.get_tags({'ids': [self.id]}) log.debug("Initializing tag " + self.identifier) log.data(pretty(inject)) self._inject = inject self._name = inject[0]["name"] except IndexError: raise TCMSError("Cannot find tag for {0}".format( self.identifier)) # Search by tag name else: try: log.info("Fetching tag '{0}'".format(self.name)) inject = self._server.Tag.get_tags({'names': [self.name]}) log.debug("Initializing tag '{0}'".format(self.name)) log.data(pretty(inject)) self._inject = inject self._id = inject[0]["id"] except IndexError: raise TCMSError("Cannot find tag '{0}'".format(self.name)) # Index the fetched object into cache self._index(self.name)
def _fetch(self, inject=None): """ Fetch product data from the server """ TCMS._fetch(self, inject) # Directly fetch from the initial object dict if inject is not None: log.debug("Initializing Product ID#{0}".format(inject["id"])) log.data(pretty(inject)) self._id = inject["id"] self._name = inject["name"] # Search by product id elif self._id is not TCMSNone: try: log.info("Fetching product " + self.identifier) inject = self._server.Product.filter({'id': self.id})[0] log.debug("Initializing product " + self.identifier) log.data(pretty(inject)) self._inject = inject self._name = inject["name"] except IndexError: raise TCMSError("Cannot find product for " + self.identifier) # Search by product name else: try: log.info("Fetching product '{0}'".format(self.name)) inject = self._server.Product.filter({'name': self.name})[0] log.debug("Initializing product '{0}'".format(self.name)) log.data(pretty(inject)) self._inject = inject self._id = inject["id"] except IndexError: raise TCMSError("Cannot find product for '{0}'".format( self.name)) # Index the fetched object into cache self._index(self.name)
def _fetch(self, inject=None): """ Get the missing test plan type data """ TCMS._fetch(self, inject) # Directly fetch from the initial object dict if inject is not None: log.info("Processing PlanType ID#{0} inject".format(inject["id"])) # Search by test plan type id elif self._id is not TCMSNone: try: log.info("Fetching test plan type " + self.identifier) inject = self._server.TestPlan.get_plan_type(self.id) except xmlrpc.client.Fault as error: log.debug(error) raise TCMSError("Cannot find test plan type for " + self.identifier) # Search by test plan type name else: try: log.info("Fetching test plan type '{0}'".format(self.name)) inject = self._server.TestPlan.check_plan_type(self.name) except xmlrpc.client.Fault as error: log.debug(error) raise TCMSError("PlanType '{0}' not found".format(self.name)) # Initialize data from the inject and index into cache log.debug("Initializing PlanType ID#{0}".format(inject["id"])) log.data(pretty(inject)) self._inject = inject self._id = inject["id"] self._name = inject["name"] self._index(self.name)
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 __init__(self, status): """ Takes numeric status id (1-8) or status name which is one of: IDLE, PASSED, FAILED, RUNNING, PAUSED, BLOCKED, ERROR, WAIVED """ if isinstance(status, int): if status < 1 or status > 8: raise TCMSError("Not a valid Status id: '{0}'".format(status)) self._id = status else: try: self._id = self._statuses.index(status) except ValueError: raise TCMSError("Invalid status '{0}'".format(status))
def _fetch(self, inject=None): """ Fetch user data from the server """ TCMS._fetch(self, inject) if inject is None: # Search by id if self._id is not TCMSNone: try: log.info("Fetching user " + self.identifier) inject = self._server.User.filter({"id": self.id})[0] except IndexError: raise TCMSError("Cannot find user for " + self.identifier) # Search by login elif self._login is not TCMSNone: try: log.info("Fetching user for login '{0}'".format( self.login)) inject = self._server.User.filter({"username": self.login})[0] except IndexError: raise TCMSError("No user found for login '{0}'".format( self.login)) # Search by email elif self._email is not TCMSNone: try: log.info("Fetching user for email '{0}'".format( self.email)) inject = self._server.User.filter({"email": self.email})[0] except IndexError: raise TCMSError("No user found for email '{0}'".format( self.email)) # Otherwise initialize to the current user else: log.info("Fetching the current user") inject = self._server.User.get() self._index("i-am-current-user") # Initialize data from the inject and index into cache log.debug("Initializing user UID#{0}".format(inject["id"])) log.data(pretty(inject)) self._inject = inject self._id = inject["id"] self._login = inject["username"] self._email = inject["email"] if inject["first_name"] and inject["last_name"]: self._name = inject["first_name"] + " " + inject["last_name"] else: self._name = None self._index(self.login, self.email)
def __init__(self, casestatus): """ Takes numeric status id (1-4) or status name which is one of: PROPOSED, CONFIRMED, DISABLED, NEED_UPDATE """ if isinstance(casestatus, int): if casestatus < 1 or casestatus > 4: raise TCMSError( "Not a valid casestatus id: '{0}'".format(casestatus)) self._id = casestatus else: try: self._id = self._casestatuses.index(casestatus) except ValueError: raise TCMSError("Invalid casestatus '{0}'".format(casestatus))
def __init__(self, priority): """ Takes numeric priority id (1-5) or priority name which is one of: P1, P2, P3, P4, P5 """ if isinstance(priority, int): if priority < 1 or priority > 5: raise TCMSError( "Not a valid Priority id: '{0}'".format(priority)) self._id = priority else: try: self._id = self._priorities.index(priority) except ValueError: raise TCMSError("Invalid priority '{0}'".format(priority))
def __init__(self, id=None, name=None): """ Initialize the Product by id or name Examples: Product(60) Product(id=60) Product("Red Hat Enterprise Linux 6") Product(name="Red Hat Enterprise Linux 6") """ # Initialize (unless already done) id, name, inject, initialized = self._is_initialized(id or name) if initialized: return TCMS.__init__(self, id) # If inject given, fetch test case data from it if inject: self._fetch(inject) # Initialize by name elif name is not None: self._name = name self._index(name) # Otherwise just check that the product id was provided elif not id: raise TCMSError("Need id or name to initialize Product")
def __init__(self, id=None, name=None, product=None, **kwargs): """ Initialize by component id or component name and product """ # Initialize (unless already done) id, ignore, inject, initialized = self._is_initialized(id) if initialized: return TCMS.__init__(self, id) # If inject given, fetch component data from it if inject: self._fetch(inject) # Initialized by product and component name elif name is not None and product is not None: # Detect product format if isinstance(product, Product): self._product = product else: self._product = Product(product) self._name = name # Index by name-product (only when the product name is known) if self.product._name is not TCMSNone: self._index("{0}---in---{1}".format(self.name, self.product.name)) # Otherwise just check that the id was provided elif id is None: raise TCMSError( "Need either component id or both product " "and component name to initialize the Component object.")
def search(**query): """ Search for test cases """ # Special handling for automated & manual attributes manual = automated = None if "automated" in query: automated = query["automated"] del query["automated"] if "manual" in query: manual = query["manual"] del query["manual"] # Map to appropriate value of 'is_automated' attribute if manual is not None or automated is not None: if automated is False and manual is False: raise TCMSError("Invalid search " "('manual' and 'automated' cannot be both False)") elif automated is False: query["is_automated"] = 0 elif manual is False: query["is_automated"] = 1 elif automated is True and manual is True: query["is_automated"] = 2 elif automated is True: query["is_automated__in"] = [1, 2] elif manual is True: query["is_automated__in"] = [0, 2] log.debug("Searching for test cases") log.data(pretty(query)) return [TestCase(inject) for inject in TCMS()._server.TestCase.filter(dict(query))]
def __init__(self, id=None, testplan=None, **kwargs): """ Initialize a test run or create a new one. Initialize an existing test run if id provided, otherwise create a new test run based on specified test plan (required). Other parameters are optional and have the following defaults: build ....... "unspecified" product ..... test run product version ..... test run product version summary ..... <test plan name> on <build> notes ....... "" manager ..... current user tester ...... current user """ # Initialize (unless already done) id, name, inject, initialized = self._is_initialized(id) if initialized: return Mutable.__init__(self, id, prefix="TR") # If inject given, fetch test case data from it if inject: self._fetch(inject) # Create a new test run based on provided plan elif testplan: self._create(testplan=testplan, **kwargs) # Otherwise just check that the test run id was provided elif not id: raise TCMSError( "Need either id or test plan to initialize the test run")
def __init__(self, id=None, name=None, product=None, version=None, type=None, **kwargs): """ Initialize a test plan or create a new one. Provide id to initialize an existing test plan or name, product, version and type to create a new plan. Other parameters are optional. document .... Test plan document (default: '') parent ...... Parent test plan (object or id, default: None) Product, version and type can be provided as id, name or object. """ # Initialize (unless already done) id, ignore, inject, initialized = self._is_initialized(id) if initialized: return Mutable.__init__(self, id, prefix="TP") # If inject given, fetch test case data from it if inject: self._fetch(inject) # Create a new test plan if name, type, product and version provided elif name and type and product and version: self._create(name=name, product=product, version=version, type=type, **kwargs) # Otherwise just check that the test plan id was provided elif not id: raise TCMSError( "Need either id or name, product, version " "and type to initialize the test plan")
def __init__(self, id=None, name=None, product=None, **kwargs): """ Initialize by build id or product and build name """ # Backward compatibility for 'build' argument (now called 'name') name = name if name is not None else kwargs.get("build") # Initialize (unless already done) id, ignore, inject, initialized = self._is_initialized(id or name) if initialized: return TCMS.__init__(self, id) # If inject given, fetch build data from it if inject: self._fetch(inject) # Initialized by build name and product elif name is not None and product is not None: self._name = name # Detect product format if isinstance(product, Product): self._product = product else: self._product = Product(product) # Index by name-product (only when the product name is known) if self.product._name is not TCMSNone: self._index("{0}---in---{1}".format(self.name, self.product.name)) # Otherwise just check that the id was provided elif not id: raise TCMSError("Need either build id or both build name " "and product to initialize the Build object.")
def _idify(id): """ Pack/unpack multiple ids into/from a single id List of ids is converted into a single id. Single id is converted into list of original ids. For example: _idify([1, 2]) ---> 1000000002 _idify(1000000002) ---> [1, 2] This is used for indexing by fake internal id. """ if isinstance(id, list): result = 0 for value in id: result = result * config._MAX_ID + value return result elif isinstance(id, int): result = [] while id > 0: remainder = id % config._MAX_ID id = int(id / config._MAX_ID) result.append(int(remainder)) result.reverse() return result else: raise TCMSError("Invalid id for idifying: '{0}'".format(id))
def __init__(self, id=None, name=None, product=None, **kwargs): """ Initialize by version id or product and version """ # Backward compatibility for 'version' argument (now called 'name') name = name if name is not None else kwargs.get("version") # Initialize (unless already done) id, ignore, inject, initialized = self._is_initialized(id) if initialized: return TCMS.__init__(self, id) # If inject given, fetch tag data from it if inject: self._fetch(inject) # Initialize by version name and product elif name is not None and product is not None: self._name = name # Convert product into object if necessary if isinstance(product, Product): self._product = product else: self._product = Product(product) # Index by name/product (but only when the product name is known) if self.product._name is not TCMSNone: self._index("{0}---in---{1}".format(self.name, self.product.name)) # Otherwise just make sure the version id was provided elif not id: raise TCMSError( "Need either version id or both product " "and version name to initialize the Version object.")
def __init__(self): """ Initialize the configuration """ # Nothing to do if already parsed if self._parsed: return class Section(object): """ Trivial class for sections """ # Try system settings when the config does not exist in user directory if not os.path.exists(self.path): log.debug("User config file not found, trying /etc/tcms.conf") self.path = "/etc/tcms.conf" if not os.path.exists(self.path): log.error(self.example) raise TCMSError("No config file found") log.debug("Parsing config file {0}".format(self.path)) # Parse the config try: parser = ConfigParser() parser.read([self.path]) for section in parser.sections(): # Create a new section object for each section setattr(self, section, Section()) # Set its attributes to section contents (adjust types) for name, value in parser.items(section): try: value = int(value) except ValueError: pass if value == "True": value = True if value == "False": value = False setattr(getattr(self, section), name, value) except ConfigParser.Error: log.error(self.example) raise TCMSError("Cannot read the config file") # Make sure the server URL is set try: self.tcms.url is not None except AttributeError: log.error(self.example) raise TCMSError("No url found in the config file") self._parsed = True
def _fetch(self, inject=None): """ Get the missing build data """ TCMS._fetch(self, inject) # Directly fetch from the initial object dict if inject is not None: log.info("Processing build ID#{0} inject".format( inject["build_id"])) # Search by build id elif self._id is not TCMSNone: try: log.info("Fetching build " + self.identifier) inject = self._server.Build.filter({'pk': self.id})[0] except IndexError as error: log.debug(error) raise TCMSError("Cannot find build for " + self.identifier) # Search by build name and product else: try: log.info("Fetching build '{0}' of '{1}'".format( self.name, self.product.name)) inject = self._server.Build.filter({ 'name': self.name, 'product': self.product.id })[0] self._id = inject["build_id"] except IndexError as error: log.debug(error) raise TCMSError("Build '{0}' not found in '{1}'".format( self.name, self.product.name)) except KeyError: if "args" in inject: log.debug(inject["args"]) raise TCMSError("Build '{0}' not found in '{1}'".format( self.name, self.product.name)) # Initialize data from the inject and index into cache log.debug("Initializing Build ID#{0}".format(inject["build_id"])) log.data(pretty(inject)) self._inject = inject self._id = inject["build_id"] self._name = inject["name"] self._product = Product({ "id": inject["product_id"], "name": inject["product"] }) self._index("{0}---in---{1}".format(self.name, self.product.name))
def __eq__(self, other): """ Objects are compared based on their id """ # Special handling for comparison with None if other is None: return False # We can only compare objects of the same type if self.__class__ != other.__class__: raise TCMSError("Cannot compare '{0}' with '{1}'".format( self.__class__.__name__, other.__class__.__name__)) return self.id == other.id
def _fetch(self, inject=None): """ Fetch version data from the server """ TCMS._fetch(self, inject) # Directly fetch from the initial object dict if inject is not None: log.debug("Processing Version ID#{0} inject".format(inject["id"])) # Search by version id elif self._id is not TCMSNone: try: log.info("Fetching version {0}".format(self.identifier)) inject = self._server.Product.filter_versions({'id': self.id})[0] except IndexError: raise TCMSError("Cannot find version for {0}".format( self.identifier)) # Search by product and name else: try: log.info("Fetching version '{0}' of '{1}'".format( self.name, self.product.name)) inject = self._server.Product.filter_versions({ 'product': self.product.id, 'value': self.name })[0] except IndexError: raise TCMSError("Cannot find version for '{0}'".format( self.name)) # Initialize data from the inject and index into cache log.debug("Initializing Version ID#{0}".format(inject["id"])) log.data(pretty(inject)) self._inject = inject self._id = inject["id"] self._name = inject["value"] self._product = Product(inject["product_id"]) # Index by product name & version name (if product is cached) if self.product._name is not TCMSNone: self._index("{0}---in---{1}".format(self.name, self.product.name)) # Otherwise index by id only else: self._index()
def _create(self, testcase, testrun, **kwargs): """ Create a new case run """ hash = {} # TestCase if testcase is None: raise TCMSError("Case ID required for new case run") elif isinstance(testcase, str): testcase = TestCase(testcase) hash["case"] = testcase.id # TestRun if testrun is None: raise TCMSError("Run ID required for new case run") elif isinstance(testrun, str): testrun = TestRun(testrun) hash["run"] = testrun.id # Build is required by XMLRPC build = testrun.build hash["build"] = build.id # Submit log.info("Creating new case run") log.data(pretty(hash)) inject = self._server.TestCaseRun.create(hash) log.data(pretty(inject)) try: self._id = inject["case_run_id"] except TypeError: log.debug("Failed to create new case run") log.data(pretty(hash)) log.data(pretty(inject)) raise TCMSError("Failed to create case run") self._fetch(inject) log.info("Successfully created {0}".format(self)) # And finally add to testcases and caseruns containers self.testrun.testcases._fetch( [self.testcase] + list(self.testrun.testcases)) self.testrun.caseruns._fetch( [self] + list(self.testrun.caseruns))
def __init__(self, status): """ Takes bool, numeric status id or status name. 0 ... False ... DISABLED 1 ... True .... ENABLED """ if isinstance(status, int): if status not in [0, 1]: raise TCMSError( "Not a valid plan status id: '{0}'".format(status)) # Save id (and convert possible bool to int) self._id = int(status) else: try: self._id = self._statuses.index(status) except ValueError: raise TCMSError("Invalid plan status '{0}'".format(status))
def _fetch(self, inject=None): """ Get the missing category data """ TCMS._fetch(self, inject) # Directly fetch from the initial object dict if inject is not None: log.info("Processing category ID#{0} inject".format(inject["id"])) # Search by category id elif self._id is not TCMSNone: try: log.info("Fetching category {0}".format(self.identifier)) inject = self._server.Product.get_category(self.id) except xmlrpc.client.Fault as error: log.debug(error) raise TCMSError("Cannot find category for " + self.identifier) # Search by category name and product else: try: log.info("Fetching category '{0}' of '{1}'".format( self.name, self.product.name)) inject = self._server.Product.check_category( self.name, self.product.id) except xmlrpc.client.Fault as error: log.debug(error) raise TCMSError("Category '{0}' not found in" " '{1}'".format(self.name, self.product.name)) # Initialize data from the inject and index into cache log.debug("Initializing category ID#{0}".format(inject["id"])) log.data(pretty(inject)) self._inject = inject self._id = inject["id"] self._name = inject["name"] self._product = Product({ "id": inject["product_id"], "name": inject["product"] }) self._index("{0}---in---{1}".format(self.name, self.product.name))
def _fetch(self, inject=None): """ Initialize / refresh test run data. Either fetch them from the server or use the provided hash. """ TCMS._fetch(self, inject) # Fetch the data hash from the server unless provided if inject is None: log.info("Fetching test run {0}".format(self.identifier)) try: inject = self._server.TestRun.filter({'pk': self.id})[0] except IndexError as error: log.debug(error) raise TCMSError( "Failed to fetch test run TR#{0}".format(self.id)) self._inject = inject else: self._id = inject["run_id"] log.debug("Initializing test run {0}".format(self.identifier)) log.data(pretty(inject)) # Set up attributes self._build = Build(inject["build_id"]) self._manager = User(inject["manager_id"]) self._notes = inject["notes"] self._status = RunStatus(inject["stop_date"]) self._old_status = self._status self._summary = inject["summary"] self._tester = User(inject["default_tester_id"]) self._testplan = TestPlan(inject["plan_id"]) self._time = inject["estimated_time"] try: self._started = datetime.datetime.strptime( inject["start_date"], "%Y-%m-%d %H:%M:%S") except TypeError: self._started = None try: self._finished = datetime.datetime.strptime( inject["stop_date"], "%Y-%m-%d %H:%M:%S") except TypeError: self._finished = None # Initialize containers self._caseruns = RunCaseRuns(self) self._testcases = RunCases(self) self._tags = RunTags(self) # Index the fetched object into cache self._index()
def __init__(self, status): """ Takes numeric status id, status name or stop date. A 'None' value is considered to be a 'no stop date' running: 0 ... RUNNING ... 'None' 1 ... FINISHED ... '2011-07-27 15:14' """ if isinstance(status, int): if status not in [0, 1]: raise TCMSError( "Not a valid run status id: '{0}'".format(status)) self._id = status else: # Running or no stop date if status == "RUNNING" or status == "None" or status is None: self._id = 0 # Finished or some stop date elif status == "FINISHED" or re.match("^[-0-9: ]+$", status): self._id = 1 else: raise TCMSError("Invalid run status '{0}'".format(status))
def __init__(self, id=None, summary=None, category=None, **kwargs): """ Initialize a test case or create a new one. Initialize an existing test case (if id provided) or create a new one (based on provided summary and category. Other optional parameters supported are: product ........ product (default: category.product) status ......... test case status (default: PROPOSED) automated ...... automation flag (default: True) autoproposed ... proposed for automation (default: False) manual ......... manual flag (default: False) priority ....... priority object, id or name (default: P3) script ......... test path (default: None) arguments ...... script arguments (default: None) requirement .... requirement (default: None) tester ......... user object or login (default: None) link ........... reference link (default: None) Examples: existing = TestCase(1234) sanity = Category(name="Sanity", product="Fedora") new = TestCase(summary="Test", category=sanity) new = TestCase(summary="Test", category="Sanity", product="Fedora") Note: When providing category by name specify product as well. """ # Initialize (unless already done) id, name, inject, initialized = self._is_initialized(id) if initialized: return Mutable.__init__(self, id, prefix="TC") # If inject given, fetch test case data from it if inject: self._fetch(inject) # Create a new test case based on summary and category elif summary and category: self._create(summary=summary, category=category, **kwargs) # Otherwise just check that the test case id was provided elif not id: raise TCMSError("Need either id or both summary and category " "to initialize the test case")
def set(self, mode=None): """ Set the coloring mode """ # Detect from the environment if no mode given (only once) if mode is None: # Nothing to do if already detected if self._mode is not None: return # Detect from the environment variable COLOR try: mode = int(os.environ["COLOR"]) except Exception: mode = COLOR_AUTO elif mode < 0 or mode > 2: raise TCMSError("Invalid color mode '{0}'".format(mode)) self._mode = mode log.debug("Coloring {0} ({1})".format( "enabled" if self.enabled() else "disabled", self.MODES[self._mode]))
def __init__(self, id=None, prefix="ID"): """ Initialize the object id, prefix and internal attributes """ # Set up the prefix self._prefix = prefix # Initialize internal attributes and reset the fetch timestamp self._init() # Check and set the object id if id is None: self._id = TCMSNone elif isinstance(id, int): self._id = id else: try: self._id = int(id) except ValueError: raise TCMSError("Invalid {0} id: '{1}'".format( self.__class__.__name__, id))
def __init__(self, id=None, name=None): """ Initialize by test plan type id or name """ # Initialize (unless already done) id, name, inject, initialized = self._is_initialized(id or name) if initialized: return TCMS.__init__(self, id) # If inject given, fetch data from it if inject: self._fetch(inject) # Initialize by name elif name is not None: self._name = name self._index(name) # Otherwise just check that the test plan type id was provided elif not id: raise TCMSError( "Need either id or name to initialize the PlanType object")