def testSubmitDatasetHandlerUpdateMetadataBeforeSubmission(self): # the initial manifest file SubmitDatasetDetailsHandler.updateMetadataInDirectoryBeforeSubmission(TestConfig.ManifestFilePath, TestConfig.ElementUriList, TestConfig.ElementValueList) # Assert that the manifets has been created self.assertEqual(True,ManifestRDFUtils.ifFileExists(TestConfig.ManifestFilePath),"Manifest file was not successfully created!") # Update the manifets contents SubmitDatasetDetailsHandler.updateMetadataInDirectoryBeforeSubmission(TestConfig.ManifestFilePath, TestConfig.ElementUriList, TestConfig.ElementValueUpdatedList) # Read the manifest again rdfGraph = ManifestRDFUtils. readManifestFile(TestConfig.ManifestFilePath) # Assert that the Updated Value list from metadata == "TestConfig.ElementValueUpdatedList" self.assertEqual(ManifestRDFUtils.getElementValuesFromManifest(rdfGraph,TestConfig.ElementUriList),TestConfig.ElementValueUpdatedList,"Error updating the metadata!") return
def processDatasetSubmissionForm(formdata, outputstr): """ Process form data, and print (to stdout) a new HTML page reflecting the outcome of the request. formdata is a dictionary containing parameters from the dataset submission form """ userName = SubmitDatasetUtils.getFormParam("user" , formdata) userPass = SubmitDatasetUtils.getFormParam("pass" , formdata) endpointhost = SubmitDatasetUtils.getFormParam("endpointhost", formdata) basepath = SubmitDatasetUtils.getFormParam("basepath" , formdata) datasetName = SubmitDatasetUtils.getFormParam("datId" , formdata) title = SubmitDatasetUtils.getFormParam("title" , formdata) description = SubmitDatasetUtils.getFormParam("description" , formdata) dirName = SubmitDatasetUtils.getFormParam("datDir" , formdata) ElementValueList = [userName, datasetName, title, description] # Host and silo name in the form data are used for testing. # In a live system, these are not provided in the form: the following values are used. if endpointhost==None or endpointhost=="": endpointhost = "localhost" if basepath==None or basepath=="": basepath = siloProxyPath ###print("\n---- processDatasetSubmissionForm:formdata ---- \n"+repr(formdata)) # Zip the selected Directory zipFileName = os.path.basename(dirName) +".zip" zipFilePath = "/tmp/" + zipFileName Logger.debug("zipFilePath = "+zipFilePath) if outputstr: sys.stdout = outputstr try: # Validate the dataset name and dataset directory fields validateFields(dirName, datasetName) # Set user credentials #session.setRequestUserPass(userName,userPass) #Create Session session = HttpSession.makeHttpSession(endpointhost, basepath, userName, userPass) SubmitDatasetUtils.createDataset(session, datasetName) # Update the local manifest manifestFilePath = dirName + str(os.path.sep) + DefaultManifestName Logger.debug("Element List = " + repr(ElementUriList)) Logger.debug("Element Value List = " + repr(ElementValueList)) SubmitDatasetDetailsHandler.updateMetadataInDirectoryBeforeSubmission(manifestFilePath, ElementUriList, ElementValueList) #Logger.debug("datasetName %s, dirName %s, zipFileName %s"%(datasetName,dirName,zipFileName)) SubmitDatasetUtils.zipLocalDirectory(dirName, FilePat, zipFilePath) # Submit zip file to dataset SubmitDatasetUtils.submitFileToDataset(session, datasetName, zipFileName, zipFilePath, ZipMimeType, zipFileName) # Unzip the contents into a new dataset datasetUnzippedName = SubmitDatasetUtils.unzipRemoteFileToNewDataset(session, datasetName, zipFileName) # Redirect to the Dataset Summary page redirectToSubmissionSummaryPage(dirName, datasetName+"-packed", datasetUnzippedName, convertToUriString(SuccessStatus)) return except SubmitDatasetUtils.SubmitDatasetError, e: SubmitDatasetUtils.printHTMLHeaders() SubmitDatasetUtils.generateErrorResponsePageFromException(e)