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, inset=None): """ Fetch currently attached tags from the server """ # If data initialized from the inset ---> we're done if Container._fetch(self, inset): return log.info("Fetching tags for {0}".format(self._identifier)) injects = self._server.Tag.filter({'case': self.id}) log.debug(pretty(injects)) self._current = set([Tag(inject) for inject in injects]) self._original = set(self._current)
def _fetch(self, inject=None): """ Initialize / refresh test case 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 case " + self.identifier) try: inject = self._server.TestCase.filter({'pk': self.id})[0] except IndexError as error: log.debug(error) raise TCMSError( "Failed to fetch test case TC#{0}".format(self.id)) self._inject = inject else: self._id = inject["case_id"] log.debug("Initializing test case " + self.identifier) log.data(pretty(inject)) # Set up attributes self._arguments = inject["arguments"] self._author = User(inject["author_id"]) self._category = Category(inject["category_id"]) if isinstance(inject["create_date"], str): self._created = datetime.datetime.strptime( inject["create_date"], "%Y-%m-%d %H:%M:%S") else: self._created = inject["create_date"] self._link = inject["extra_link"] self._notes = inject["notes"] self._priority = Priority(inject["priority_id"]) self._requirement = inject["requirement"] self._script = inject["script"] self._status = CaseStatus(inject["case_status_id"]) self._summary = inject["summary"] self._time = inject["estimated_time"] if inject["default_tester_id"] is not None: self._tester = User(inject["default_tester_id"]) else: self._tester = None # Handle manual, automated and autoproposed self._automated = inject["is_automated"] in [1, '1', 2, '2'] self._manual = inject["is_automated"] in [0, '0', 2, '2'] self._autoproposed = inject["is_automated_proposed"] # Empty script or arguments to be handled same as None if self._script == "": self._script = None if self._arguments == "": self._arguments = None # Test case documentation for attribute in ["setup", "action", "effect", "breakdown"]: if "text" in inject: setattr(self, "_" + attribute, inject["text"][attribute]) else: setattr(self, "_" + attribute, None) # Initialize containers self._bugs = CaseBugs(self) self._testplans = CasePlans(self) self._components = CaseComponents(self) # If all tags are cached, initialize them directly from the inject if "tag" in inject and Tag._is_cached(inject["tag"]): self._tags = CaseTags( self, inset=[Tag(tag) for tag in inject["tag"]]) else: self._tags = CaseTags(self) # Index the fetched object into cache self._index()
def remove(self, tags): """ Remove a tag or a list of tags """ tags = [tags] if not isinstance(tags, list) else tags tags = [Tag(tag) if isinstance(tag, str) else tag for tag in tags] super(TagContainer, self).remove(tags)
def add(self, tags): """ Add a tag or a list of tags """ tags = [tags] if not isinstance(tags, list) else tags tags = [Tag(tag) if isinstance(tag, str) else tag for tag in tags] super(TagContainer, self).add(tags)
def __contains__(self, tag): """ Tag 'in' operator """ tag = Tag(tag) if isinstance(tag, str) else tag return tag in self._items