def UpdateEntity(self, entityType, entityData, entityId): """Update an entity or multiple entities :param entityType: type of entity to update :type entityType: str :param entityData: data of entity(s) to update :type entityData: dict :param entityId: id of entity to update if updating multiple instances at once :type entityId: int | str :return: content of updated data :rtype: dict """ url = "{url}{entity}/{id}".format(url=self.url, entity=entityType, id=entityId) data = utils.DictToXml(entityData, re.sub(r's$', '', entityType)) request = self.session.put(url, data=data, headers={ 'Accept': 'application/json', 'Content-Type': 'application/xml' }) if request.status_code == 401: raise qc_exceptions.QCAuthenticationError("Not logged in") content = json.loads(request.content) if request.status_code == 200: return content raise qc_exceptions.QCError("Failed to update entity. {0}".format( content['Title']))
def Login(self): """Authenticates user :Parameters: none :return: None """ authenticationStatus = self.isAuthenticated() if authenticationStatus is True: return True headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Host': 'login.software.microfocus.com', } answer = self.session.post( 'https://login.software.microfocus.com/msg/actions/doLogin.action', headers=headers, data={ 'username': self.username, 'password': self.password }) print(answer.cookies) print(answer.status_code) if answer.status_code == 200: self.session.cookies.update({ 'LWSSO_COOKIE_KEY': answer.cookies.get('LWSSO_COOKIE_KEY'), }) request = self.session.post(self.baseUrl + 'rest/site-session') if request.status_code == 201: return raise qc_exceptions.QCAuthenticationError( "Authentication Failed [{0}]".format(answer.status_code))
def GetEntity(self, entityType, entityId=None, query=None): """Get an entity :param entityType: type of entity to get: tests/test-sets/test-configs/test-set-folders/test-instances/runs/release-cycles/defects :type entityType: str :param entityId: id of entity to get. If None returns all instances of entity :type entityId: str | int :param query: query string to filter data. e.g: {name[Basic]} :type query: str :return: requested entity(s) :rtype: dict """ url = "{url}{entityType}".format(url=self.url, entityType=entityType) if entityId: url += "/{0}".format(entityId) if query: url += "?page-size=max&query={0}".format(query) request = self.session.get(url, headers={'Accept': 'application/json'}) if request.status_code == 401: raise qc_exceptions.QCAuthenticationError("Not logged in") content = json.loads(request.content) if request.status_code == 200: data = utils.ConvertJsonToDict(content) return data raise qc_exceptions.QCError( "Failed to get data of type '{0}'. [{1}] {2}. {3}".format( entityType, request.status_code, content['Title'], url))
def Login(self): authenticationStatus = self.is_authenticated() if authenticationStatus is True: return True headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Host': 'login.software.microfocus.com', } resp = self.session.post(self.url2, headers=headers, data={ 'username': self.username, 'password': self.password }) print(resp.cookies) print(resp.status_code) if resp.status_code == 200: self.session.cookies.update({ 'LWSSO_COOKIE_KEY': resp.cookies.get('LWSSO_COOKIE_KEY'), }) request = self.session.post(self.baseUrl + 'rest/site-session') if request.status_code == 201: return raise qc_exceptions.QCAuthenticationError( "Authentication Failed [{0}]".format(resp.status_code)) # def Login(self): """Authenticates user
def GetFields(self, entityType): """Get entity's fields :param entityType: type of entity to get fields for :type entityType: str :return: requested fields for entity :rtype: list """ url = self.url + "customization/entities/{0}/fields".format(entityType) request = self.session.get(url, headers={'Accept': 'application/json'}) if request.status_code == 401: raise qc_exceptions.QCAuthenticationError("Not logged in") content = json.loads(request.content) if request.status_code == 200: return content["Fields"]["Field"] raise qc_exceptions.QCError( "Failed to get data of type '{0}'. [{1}] {2}. {3}".format( entityType, request.status_code, content['Title'], url))
def GetMandatoryFields(self, entityType): """Get mandatory fields for an entity :param entityType: name of entity to check. e.g: tests, runs, test-instances :type entityType: str :return: list of required fields """ request = self.session.get( self.url + "customization/entities/{0}/fields?required=true".format( re.sub('s$', '', entityType)), headers={'Accept': 'application/json'}) if request.status_code == 401: raise qc_exceptions.QCAuthenticationError("Not logged in") requiredFields = [ field['name'] for field in json.loads(request.content)['Fields']['Field'] ] return requiredFields
def CreateEntity(self, entityType, entityData): """Create an entity :param entityType: type of entity to create. e.g: defect, run, test :type entityType: str :param entityData: data to update. Class must inherit from base_entity.BaseEntity :type entityData: BaseEntity :return: created object data :rtype: dict """ url = "{url}{entity}".format(url=self.url, entity=entityType) request = self.session.post(url, data=entityData.ToXml(), headers={ 'Content-Type': 'application/xml', 'Accept': 'application/json' }) if request.status_code == 401: raise qc_exceptions.QCAuthenticationError("Not logged in") content = json.loads(request.content) if request.status_code in [200, 201]: return utils.ConvertJsonToDict(content) raise qc_exceptions.QCError("Failed to create entity. {0}".format( content['Title']))