Пример #1
0
    def testUpdateLocalManifestAndDatasetSubmission(self):
        outputStr =  StringIO.StringIO()

        # Invoke dataset submission program, passing faked form submission parameters

        SubmitDatasetConfirmationHandler.processDatasetSubmissionForm(TestConfig.formdata, outputStr)
        # Read the dictionary from the manifest
        actualDictionary   = ManifestRDFUtils.getDictionaryFromManifest(TestConfig.ManifestFilePath, TestConfig.ElementUriList)
        Logger.debug("\n Expected Dictionary after form submission= " + repr(ExpectedDictionary))
        Logger.debug("\n Actual Dictionary after form submission =  " + repr(actualDictionary))
        ###print "\n---- actualDictionary ---- \n"+repr(actualDictionary)
        
        # Assert that the ExpectedDictionary == actualDictionary
        self.assertEqual(ExpectedDictionary,actualDictionary, "The submit Utils Tool is unable to fetch metadata information!")
        
        # Invoke dataset submission program with updated information, passing faked updated form submission parameters
        SubmitDatasetConfirmationHandler.processDatasetSubmissionForm(TestConfig.updatedformdata, outputStr)
        # Read the dictionary from the manifest after processing the form submission with the updated faked  form  data
        actualUpdatedDictionary   = ManifestRDFUtils.getDictionaryFromManifest(TestConfig.ManifestFilePath, TestConfig.ElementUriList)
        Logger.debug("\n Expected Updated Dictionary after form resubmission = " + repr(ExpectedUpdatedDictionary))
        Logger.debug("\n Actual Updated Dictionary after form resubmission =  " + repr(actualUpdatedDictionary))
        
        # Assert that the  ExpectedUpdatedDictionary == actualUpdatedDictionary
        self.assertEqual(ExpectedUpdatedDictionary,actualUpdatedDictionary, "The submit Utils Tool was unable to update form data information in the metadata file!")
        
        return
def updateMetadataInDirectoryBeforeSubmission(manifestFilePath, elementUriList, elementValueList) :
    """
    Update the metadata RDF with the form data obtained from the dataset submission tool.
    """
    Logger.debug("Manifest Path = " + repr(manifestFilePath))
    inputDict    = ManifestRDFUtils.createDictionary(elementUriList, elementValueList)   
    if ManifestRDFUtils.ifFileExists(manifestFilePath):
        Logger.debug("Manifest File Exists... skipping creation!")
        manifestDict = ManifestRDFUtils.getDictionaryFromManifest(manifestFilePath, elementUriList) 
        if inputDict!= manifestDict:
            ManifestRDFUtils.updateManifestFile(manifestFilePath, elementUriList, elementValueList)   
    else:
        Logger.debug("Creating Manifest File...")
        ManifestRDFUtils.writeToManifestFile(manifestFilePath, NamespaceDictionary, elementUriList, elementValueList)     
    return
 def testGetDictionaryFromManifest(self):
     rdfGraph = ManifestRDFUtils.writeToManifestFile(
         TestConfig.ManifestFilePath,
         TestConfig.NamespaceDictionary,
         TestConfig.ElementUriList,
         TestConfig.ElementValueList,
     )
     actualDictionary = ManifestRDFUtils.getDictionaryFromManifest(
         TestConfig.ManifestFilePath, TestConfig.ElementUriList
     )
     Logger.debug(repr(actualDictionary))
     # print "ExpectedDictionary: "+repr(ExpectedDictionary)
     # print "actualDictionary: "+repr(actualDictionary)
     self.assertEqual(ExpectedDictionary, actualDictionary, "Error fetching dictionary from the metadata!")
     return
def getDatasetMetadata(formdata, manifestName ,outputstr):
    """
    Gets the metadata from the manifest.rdf file and formulates it into the JSON format.
    
    formdata    is a dictionary containing parameters from the dataset submission form
    """
    dirName      = SubmitDatasetUtils.getFormParam("directory",formdata)
    manifestPath = dirName  + str(os.path.sep) + manifestName
    Logger.debug("Manifest Path = " + manifestPath)
    outputstr.write("Content-type: application/JSON\n")
    outputstr.write("\n")      # end of MIME headers

    manifestDictionary = ManifestRDFUtils.getDictionaryFromManifest(manifestPath, ElementUriList)
    Logger.debug("Manifest Dictionary = " + repr(manifestDictionary))
    json.dump(manifestDictionary, outputstr, indent=4)

    Logger.debug("Manifest Dictionary = " + repr(manifestDictionary))
    return
def updateMetadataInDirectoryBeforeSubmission(manifestFilePath, elementUriList,
                                              elementValueList):
    """
    Update the metadata RDF with the form data obtained from the dataset submission tool.
    """
    Logger.debug("Manifest Path = " + repr(manifestFilePath))
    inputDict = ManifestRDFUtils.createDictionary(elementUriList,
                                                  elementValueList)
    if ManifestRDFUtils.ifFileExists(manifestFilePath):
        Logger.debug("Manifest File Exists... skipping creation!")
        manifestDict = ManifestRDFUtils.getDictionaryFromManifest(
            manifestFilePath, elementUriList)
        if inputDict != manifestDict:
            ManifestRDFUtils.updateManifestFile(manifestFilePath,
                                                elementUriList,
                                                elementValueList)
    else:
        Logger.debug("Creating Manifest File...")
        ManifestRDFUtils.writeToManifestFile(manifestFilePath,
                                             NamespaceDictionary,
                                             elementUriList, elementValueList)
    return