def testUpdateMetadata(self):
        updatedTitle = "Submission tool updated test title"
        updatedDescription = "Submission tool updated test description"

        initialGraph = ManifestRDFUtils.writeToManifestFile(
            TestConfig.ManifestFilePath,
            TestConfig.NamespaceDictionary,
            TestConfig.ElementUriList,
            TestConfig.ElementValueList,
        )
        updatedGraph = ManifestRDFUtils.updateManifestFile(
            TestConfig.ManifestFilePath,
            [TestConfig.ElementTitleUri, TestConfig.ElementDescriptionUri],
            [updatedTitle, updatedDescription],
        )
        readGraph = ManifestRDFUtils.readManifestFile(TestConfig.ManifestFilePath)

        # Assert that (initialGraph != updatedGraph)
        self.assertEqual(
            False,
            ManifestRDFUtils.compareRDFGraphs(initialGraph, updatedGraph, TestConfig.ElementUriList),
            "Error updating the manifest file!",
        )

        # Assert that (updatedGraph == readGraph)
        self.assertEqual(
            True,
            ManifestRDFUtils.compareRDFGraphs(updatedGraph, readGraph, TestConfig.ElementUriList),
            "Error updating the manifest file!",
        )
        return
Exemple #2
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 testReadMetadata(self):

        rdfGraphBeforeSerialisation = ManifestRDFUtils.writeToManifestFile(
            TestConfig.ManifestFilePath,
            TestConfig.NamespaceDictionary,
            TestConfig.ElementUriList,
            TestConfig.ElementValueList,
        )
        rdfGraphAfterSerialisation = ManifestRDFUtils.readManifestFile(TestConfig.ManifestFilePath)

        # Compare the serialised graph obtained with the graph before serialisation
        self.assertEqual(len(rdfGraphBeforeSerialisation), 5, "Graph length %i" % len(rdfGraphAfterSerialisation))

        subject = rdfGraphAfterSerialisation.value(None, RDF.type, URIRef(ManifestRDFUtils.oxds + "Grouping"))
        self.failUnless(
            (subject, RDF.type, URIRef(TestConfig.oxds + "Grouping")) in rdfGraphAfterSerialisation,
            "Testing submission type: " + subject + ", " + URIRef(TestConfig.oxds + "Grouping"),
        )
        self.failUnless(
            (subject, TestConfig.ElementCreatorUri, TestConfig.User) in rdfGraphAfterSerialisation, "dcterms:creator"
        )
        self.failUnless(
            (subject, TestConfig.ElementIdentifierUri, TestConfig.DatasetId) in rdfGraphAfterSerialisation,
            "ManifestRDFUtils.dcterms:identifier",
        )
        self.failUnless(
            (subject, TestConfig.ElementTitleUri, TestConfig.Title) in rdfGraphAfterSerialisation, "dcterms:title"
        )
        self.failUnless(
            (subject, TestConfig.ElementDescriptionUri, TestConfig.Description) in rdfGraphAfterSerialisation,
            "dcterms:TestConfig.Description",
        )
        return
Exemple #4
0
    def testGetDatasetMetadataResponse(self):
        outputStr = StringIO.StringIO()

        # Create a manifest file from mocked up form data
        ManifestRDFUtils.writeToManifestFile(TestConfig.ManifestFilePath,
                                             TestConfig.NamespaceDictionary,
                                             TestConfig.ElementUriList,
                                             TestConfig.ElementValueList)

        # Invoke get metatadata submission program, passing faked dataset directory
        GetDatasetMetadataHandler.getDatasetMetadata(TestConfig.formdata,
                                                     TestConfig.ManifestName,
                                                     outputStr)

        outputStr.seek(0, os.SEEK_SET)
        firstLine = outputStr.readline()
        self.assertEqual(firstLine, "Content-type: application/JSON\n",
                         "Expected Metadata as application/JSON")

        Logger.debug("Output String from output stream: " +
                     outputStr.getvalue())

        # Check retrieving metadata
        metadata = json.load(outputStr)

        Logger.debug("Metadata Length = " + repr(len(metadata)))
        self.assertEquals(len(metadata), 4,
                          "Expected 4 pairs of field-values to be returned")

        return
 def testGetElementValuesFromManifest(self):
     rdfGraph = ManifestRDFUtils.writeToManifestFile(
         TestConfig.ManifestFilePath,
         TestConfig.NamespaceDictionary,
         TestConfig.ElementUriList,
         TestConfig.ElementValueList,
     )
     fields = ManifestRDFUtils.getElementValuesFromManifest(rdfGraph, TestConfig.ElementUriList)
     self.assertEquals(fields, TestConfig.ElementValueList, "Problem reading submit dataset utility Fields!")
     return
Exemple #6
0
 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 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 testGetDatasetMetadataResponse(self):
        outputStr = StringIO.StringIO()
        
        # Create a manifest file from mocked up form data
        ManifestRDFUtils.writeToManifestFile(TestConfig.ManifestFilePath, TestConfig.NamespaceDictionary,TestConfig.ElementUriList, TestConfig.ElementValueList)

        # Invoke get metatadata submission program, passing faked dataset directory
        GetDatasetMetadataHandler.getDatasetMetadata(TestConfig.formdata, TestConfig.ManifestName, outputStr)
    
        outputStr.seek(0, os.SEEK_SET)
        firstLine = outputStr.readline()
        self.assertEqual( firstLine, "Content-type: application/JSON\n", "Expected Metadata as application/JSON")
        
        Logger.debug("Output String from output stream: " + outputStr.getvalue())

        # Check retrieving metadata
        metadata = json.load(outputStr)

        Logger.debug("Metadata Length = "+ repr(len(metadata)))
        self.assertEquals(len(metadata), 4, "Expected 4 pairs of field-values to be returned")


        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 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