def setupValidMetadata(type,id,tags,priority,description): #create metadata for a test case myMetadata = TBMetadata(type) myMetadata.setAssetID(id) myMetadata.setTags(tags) myMetadata.setPriority(priority) myMetadata.setAssetDescription(description) return myMetadata
def _parseXML(s,f,t): ''' Inputs: ----<s>: String potentially containing the pXML-encoded metadata. ----<f>: Filename where said string was obtained from. ----<t>: Metadata type according to caller. Outputs: ----TBMetadata instance containing the corresponding metadata. ------None if no metadata was found or a required field was empty or not found. Process: ----(1) Loads XML data from string. May return with None. ----(2) Based on the current specifications [1] do: ----(2.1) Get metadata ----(2.2) Confirm required info ----(2.3) Fill TBMetadata instance, ----(2.3*) Assign the corresponding uninitialized value for empty tags. ''' if s is None: logging.info("No metadata (no comment on first line) found in" " file " + f) return None try: e = xml.etree.ElementTree.fromstring(s) except xml.etree.ElementTree.ParseError: logging.info("No metadata found in file " + f) return None assetID = e.find("TestID") tags = e.find("Tags") priority = e.find("Priority") assetDescription = e.find("Description") if t == TBTAFMetadataType.TEST_CODE: if assetID is None or assetID.text is None : logging.info("ID (required) not found in file " + f) return None md = TBMetadata(TBTAFMetadataType.TEST_CODE) else: md = TBMetadata(TBTAFMetadataType.PRODUCT_CODE) if tags is None or tags.text is None : logging.info("Tags (required) not found in file " + f) return None if assetID is not None and assetID.text is not None : md.setAssetID(int(assetID.text)) else: md.setAssetID(TBMetadata.NON_INITIALIZED) if tags.text is not None : md.setTags([t.strip() for t in tags.text.split(',')]) else: md.setTags([]) if priority is not None and priority.text is not None: md.setPriority(int(priority.text)) else: md.setPriority(TBMetadata.NON_INITIALIZED) if assetDescription is not None and assetDescription.text is not None: md.setAssetDescription(assetDescription.text) else: md.setAssetDescription('') return md