def testPushConflictedZip(self):
        """
        Push a Research Object in zip format to ROSRS.

        ro push <zip> | -d <dir>  [ -f ] [ -r <rosrs_uri> ] [ -t <access_token> ] 
        """
        args = [
            "ro", "push", "data/ro1.zip",
            "-r", ro_test_config.ROSRS_URI,
            "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
            "-v"
            ]
        
        #preparing
        httpsession = ROSRS_Session(ro_test_config.ROSRS_URI,
        accesskey=ro_test_config.ROSRS_ACCESS_TOKEN)
        ro_remote_metadata.deleteRO(httpsession, ro_test_config.ROSRS_URI +"ro1/")
        status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
        
        with SwitchStdout(self.outstr):
            status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
        #cleaning
        ro_remote_metadata.deleteRO(httpsession, ro_test_config.ROSRS_URI +"ro1/")
        
        assert status == 0        
        self.assertEqual(self.outstr.getvalue().count("Status: 409"),1)
        self.assertEqual(self.outstr.getvalue().count("Reason: Conflict"),1)
 def testAddDirectory(self):
     """
     Add directory to created RO
     """
     rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test add", "ro-testRoAdd")
     self.populateTestRo(testbase, rodir)
     args = [
         "ro", "add",
         "-d", rodir,
         rodir+"/subdir1/",
         ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     self.outstr = StringIO.StringIO()
     # Now list contents
     args = [
         "ro", "ls",
         "-d", rodir,
         "-v"
         ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     self.assertEqual(outtxt.count("ro list"), 1)
     self.assertRegexpMatches(outtxt, "README-ro-test-1")
     self.assertRegexpMatches(outtxt, "subdir1/subdir1-file.txt")
     self.assertRegexpMatches(outtxt, "subdir2/subdir2-file.txt")
     self.assertRegexpMatches(outtxt, "subdir1/\\s")
     self.assertNotRegexpMatches(outtxt, "subdir2/\\s")
     self.deleteTestRo(rodir)
     return
 def testEvaluateMissingRDF(self):
     # repeat previous test case, but with RDF output
     self.setupConfig()
     rodir = self.createTestRo(testbase, "test-simple-wf", "RO test minim", "ro-testMinim")
     self.populateTestRo(testbase, rodir)
     self.annotateWfRo(testbase, rodir)
     rometa   = ro_metadata(ro_config, rodir)
     minimuri = rometa.getComponentUri("simple-wf-minim.rdf")
     # Evaluate
     args = [ "ro", "evaluate", "checklist"
            , "-a"
            , "-d", rodir+"/"
            , "-o", "rdfxml"
            , "simple-wf-minim.rdf"
            , "Missing"
            , "."
            ]
     self.outstr.seek(0)
     with StdoutContext.SwitchStdout(self.outstr):
         status = ro.runCommand(
             os.path.join(testbase, TestConfig.ro_test_config.CONFIGDIR),
             os.path.join(testbase, TestConfig.ro_test_config.ROBASEDIR),
             args)
     outtxt = self.outstr.getvalue()
     assert status == 0, "Status %d, outtxt: %s"%(status,outtxt)
     # log.debug("status %d, outtxt: \n--------\n%s----"%(status, outtxt))
     # Check response returned
     self.outstr.seek(0)
     outgraph = rdflib.Graph()
     outgraph.parse(self.outstr)
     prefixes = make_sparql_prefixes()
     rouri    = rometa.getRoUri()
     modeluri = rometa.getComponentUriAbs("simple-wf-minim.rdf#missing_RO_model")
     log.debug("------ outgraph:\n%s\n----"%(outgraph.serialize(format='turtle')))
     probequeries = (
         [ "ASK { _:r minim:testedRO <%s> ; minim:minimUri <%s> }"%
           (rouri, minimuri)
         , "ASK { _:r minim:testedRO <%s> ; minim:testedModel <%s> }"%
           (rouri, modeluri)
         , """ASK 
           { _:r minim:testedRO <%(rouri)s> ; 
               minim:testedPurpose "Missing" ;
               minim:missingMust 
                 [ minim:tryMessage "No workflow present with hens tooth" ;
                   result:binding [ result:variable "_count" ; result:value 0 ]
                 ]
           }"""% { 'rouri': rouri }
         , '''ASK { _:r minim:testedRO <%s> ; minim:missingMust [ minim:tryMessage "%s" ] }'''%
           (rouri, "No workflow present with hens tooth")
         , '''ASK { _:r minim:testedRO <%s> ; minim:testedTarget <%s> }'''%
           (rouri, rouri)
         , '''ASK { <%s> rdfs:label "%s" }'''%
           (rouri, rdflib.Literal("RO test minim"))
       ])
     for q in probequeries:
         r = outgraph.query(prefixes+q)
         self.assertEqual(r.type, 'ASK', "Result type %s for: %s"%(r.type, q))
         self.assertTrue(r.askAnswer, "Failed query: %s"%(q))
     self.deleteTestRo(rodir)
     return
 def testAddAggregatedResourcesCommand(self):
     """
     Test function that adds aggregated resources to a research object manifest
     """
     rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test annotation", "ro-testRoAnnotate")
     args = [
         "ro", "add", "-v", "-a",
         "-d", rodir,
         rodir
         ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     log.debug("outtxt %s"%outtxt)
     def URIRef(path):
         return ro_manifest.getComponentUriAbs(rodir, path)
     s = ro_manifest.getComponentUri(rodir, "")
     g = rdflib.Graph()
     g.add( (s, RDF.type,            RO.ResearchObject                       ) )
     g.add( (s, ORE.aggregates,      URIRef("README-ro-test-1")              ) )
     g.add( (s, ORE.aggregates,      URIRef("filename%20with%20spaces.txt")  ) )
     g.add( (s, ORE.aggregates,      URIRef("filename%23with%23hashes.txt")  ) )
     g.add( (s, ORE.aggregates,      URIRef("README-ro-test-1")              ) )
     g.add( (s, ORE.aggregates,      URIRef("subdir1/subdir1-file.txt")      ) )
     g.add( (s, ORE.aggregates,      URIRef("subdir2/subdir2-file.txt")      ) )
     self.checkManifestGraph(rodir, g)
     self.deleteTestRo(rodir)
     return
 def testConfig(self):
     """
     $ ro config \
       -r http://calatola.man.poznan.pl/robox/dropbox_accounts/1/ro_containers/2 \
       -p d41d8cd98f00b204e9800998ecf8427e \
       -b /usr/workspace/Dropbox/myROs \
       -n "Graham Klyne" \
       -e [email protected]
     """
     ro_utils.resetconfig(ro_test_config.CONFIGDIR)
     config = ro_utils.readconfig(ro_test_config.CONFIGDIR)
     self.assertEqual(config["robase"],    None)
     self.assertEqual(config["rosrs_uri"],  None)
     self.assertEqual(config["rosrs_access_token"],  None)
     self.assertEqual(config["username"],  None)
     self.assertEqual(config["useremail"], None)
     args = [
         "ro", "config",
         "-b", ro_test_config.ROBASEDIR,
         "-r", ro_test_config.ROSRS_URI,
         "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
         "-n", ro_test_config.ROBOXUSERNAME,
         "-e", ro_test_config.ROBOXEMAIL
         ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
         assert status == 0
     self.assertEqual(self.outstr.getvalue().count("ro config"), 0)
     config = ro_utils.readconfig(ro_test_config.CONFIGDIR)
     self.assertEqual(config["robase"],          os.path.abspath(ro_test_config.ROBASEDIR))
     self.assertEqual(config["rosrs_uri"],       ro_test_config.ROSRS_URI)
     self.assertEqual(config["rosrs_access_token"],  ro_test_config.ROSRS_ACCESS_TOKEN)
     self.assertEqual(config["username"],        ro_test_config.ROBOXUSERNAME)
     self.assertEqual(config["useremail"],       ro_test_config.ROBOXEMAIL)
     return
    def testPushZipWithNewOption(self):
        """
        Push a Research Object in zip format to ROSRS.

        ro push <zip> | -d <dir>  [ -f ] [ -r <rosrs_uri> ] [ -t <access_token> ] 
        """
        args = [
            "ro", "push", "data/newro.zip", "--new",
            "-r", ro_test_config.ROSRS_URI,
            "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
            "-v"
            ]
        
        #preparing
        httpsession = ROSRS_Session(ro_test_config.ROSRS_URI,
        accesskey=ro_test_config.ROSRS_ACCESS_TOKEN)        
        with SwitchStdout(self.outstr):
            status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
        assert status == 0
        self.assertEqual(self.outstr.getvalue().count("new"),1)
        self.assertEqual(self.outstr.getvalue().count("Job URI"),1)
        self.assertEqual(self.outstr.getvalue().count("ENTER"),1)
        for line in self.outstr.getvalue().split("\n"):
            if "RO URI:" in line:
                id = line.split("RO URI:")[1].strip()
                self.rosrs.deleteRO(id)
    def testList(self):
        """
        Display contents of created RO

        ro ls -d rodir
        """
        rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test list", "ro-testRoList")
        self.populateTestRo(testbase, rodir)
        args = [
            "ro", "ls",
            "-d", rodir,
            "-v"
            ]
        with SwitchStdout(self.outstr):
            status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
        outtxt = self.outstr.getvalue()
        assert status == 0, outtxt
        self.assertEqual(outtxt.count("ro list"), 1)
        self.assertRegexpMatches(outtxt, "README-ro-test-1")
        self.assertRegexpMatches(outtxt, "subdir1/subdir1-file.txt")
        self.assertRegexpMatches(outtxt, "subdir2/subdir2-file.txt")
        self.assertNotRegexpMatches(outtxt, "subdir1/\\s")
        self.assertNotRegexpMatches(outtxt, "subdir2/\\s")
        self.deleteTestRo(rodir)
        return
    def testListDefault(self):
        """
        Display contents of created RO containing current directory

        ro ls
        """
        rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test list", "ro-testRoList")
        self.populateTestRo(testbase, rodir)
        args = [
            "ro", "ls",
            "-v"
            ]
        configbase = os.path.abspath(ro_test_config.CONFIGDIR)
        save_cwd = os.getcwd()
        os.chdir(rodir+"/subdir2/")
        with SwitchStdout(self.outstr):
            status = ro.runCommand(configbase, ro_test_config.ROBASEDIR, args)
        os.chdir(save_cwd)
        outtxt = self.outstr.getvalue()
        assert status == 0, outtxt
        self.assertEqual(outtxt.count("ro list"), 1)
        self.assertRegexpMatches(outtxt, "README-ro-test-1")
        self.assertRegexpMatches(outtxt, "subdir1/subdir1-file.txt")
        self.assertRegexpMatches(outtxt, "subdir2/subdir2-file.txt")
        self.assertNotRegexpMatches(outtxt, "subdir1/\\s")
        self.assertNotRegexpMatches(outtxt, "subdir2/\\s")
        self.deleteTestRo(rodir)
        return
    def testStatusDefault(self):
        """
        Display status of created RO

        ro status 
        """
        rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test status", "ro-testRoStatus")
        args = [
            "ro", "status",
            "-v"
            ]
        configbase = os.path.abspath(ro_test_config.CONFIGDIR)
        save_cwd = os.getcwd()
        os.chdir(rodir+"/subdir1/")
        with SwitchStdout(self.outstr):
            status = ro.runCommand(configbase, ro_test_config.ROBASEDIR, args)
        os.chdir(save_cwd)
        outtxt = self.outstr.getvalue()
        assert status == 0, outtxt
        self.assertEqual(outtxt.count("ro status"), 1)
        self.assertRegexpMatches(outtxt, "identifier.*ro-testRoStatus")
        self.assertRegexpMatches(outtxt, "title.*RO test status")
        self.assertRegexpMatches(outtxt, "path.*%s"%rodir)
        self.assertRegexpMatches(outtxt, "creator.*%s"%ro_test_config.ROBOXUSERNAME)
        self.assertRegexpMatches(outtxt, "created")
        self.deleteTestRo(rodir)
        return
 def annotateTest(self, anntype, annvalue, anntypeuri, annexpect):
     rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test annotation", "ro-testRoAnnotate")
     args = [
         "ro", "annotate", rodir+"/"+"subdir1/subdir1-file.txt", anntype, annvalue,
         "-v",
         ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     self.assertEqual(outtxt.count("ro annotate"), 1)
     # Read manifest and check for annotation
     annotations = ro_annotation._getFileAnnotations(rodir, "subdir1/subdir1-file.txt")
     resourceuri = ro_manifest.getComponentUri(rodir, "subdir1/subdir1-file.txt")
     expected_annotations = (
         [ (resourceuri, anntypeuri, rdflib.Literal(annexpect))
         ])
     for i in range(1):
         next = annotations.next()
         #log.debug("Next %s"%(repr(next)))
         if ( next not in expected_annotations):
             self.assertTrue(False, "Not expected (%d) %s"%(i, repr(next)))
     self.assertRaises(StopIteration, annotations.next)
     self.deleteTestRo(rodir)
     return
Example #11
0
 def testChecklistEvalExcel(self):
     """
     Test checklist evaluation with generated Minim file from Excel source
     """
     self.setupConfig()
     rodir = self.createTestRo(testbase, "testro", "RO for testMkMinim", "ro-testMkMinim")
     self.populateTestRo(testbase, rodir)
     self.annotateResource(testbase, rodir, "", "FileAnnotations.ttl")
     rouri = ro_manifest.getRoUri(rodir)
     # Create minim graph from CSV file
     gridname = "TestMkMinim.xls"
     griduri = ro_manifest.getComponentUri(rodir, gridname)
     gridxls = os.path.join(rodir, gridname)
     gridbase = "http://example.org/base/"
     grid = GridExcel(gridxls, baseuri=gridbase)
     (status, minimgr) = mkminim.mkminim(grid, baseuri=grid.resolveUri(""))
     self.assertEquals(status, 0)
     # Write Minim
     minimname = "TestMkMinim_minim.ttl"
     with open(rodir + "/" + minimname, "w") as minimfile:
         minimgr.serialize(minimfile, format="turtle")
     # Evaluate checklist
     minimuri = ro_manifest.getComponentUri(rodir, minimname)
     minimpurpose = "test1"
     args = ["ro", "evaluate", "checklist", "-a", "-d", rodir + "/", minimname, minimpurpose, "."]
     self.outstr.seek(0)
     with StdoutContext.SwitchStdout(self.outstr):
         status = ro.runCommand(
             os.path.join(testbase, TestConfig.ro_test_config.CONFIGDIR),
             os.path.join(testbase, TestConfig.ro_test_config.ROBASEDIR),
             args,
         )
     outtxt = self.outstr.getvalue()
     assert status == 0, "Status %d, outtxt: %s" % (status, outtxt)
     log.debug("status %d, outtxt: %s" % (status, outtxt))
     # Check response returned
     # filelist  = [ unicode(ro_manifest.getComponentUri(rodir, f))
     #               for f in ["File1.txt", "File2.txt", "File3.txt"] ]
     filelist = ValueList(
         [str(ro_manifest.getComponentUri(rodir, f)) for f in ["File1.txt", "File2.txt", "File3.txt"]]
     )
     expect = [
         "Research Object file://%s/:" % (rodir),
         "Fully complete for test1 of resource .",
         "Satisfied requirements:",
         "  At least 3 file as part values are present",
         "  At most 3 file as part values are present",
         "  All part resource files %s are aggregated in RO" % (filelist),
         "  All file as part resources are accessible (live)",
         "  Python 2.7.x present",
         "  Files as part are partOf some indicated whole",
         "  File exists as a part",
         "Research object URI:     %s" % (rouri),
         "Minimum information URI: %s" % (minimuri),
     ]
     self.outstr.seek(0)
     for line in self.outstr:
         self.assertIn(str(line)[:-1], expect)
     self.deleteTestRo(rodir)
     return
Example #12
0
 def testAnnotationDisplayDefault(self):
     # Construct annotated RO
     rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test annotation", "ro-testRoAnnotate")
     rofile = rodir+"/"+"subdir1/subdir1-file.txt"
     annotations = (
         [ {"atypename": "type",        "avalue":"atype",    "atypeuri":DCTERMS.type,        "aexpect":"atype" }
         , {"atypename": "title",       "avalue":"atitle",   "atypeuri":DCTERMS.title,       "aexpect":"atitle" }
         ])
     self.annotateMultiple(rodir, rofile, annotations)
     # Display annotations with RO in curremnt directory and target "."
     args = [ "ro", "annotations", "."
            , "-v"
            ]
     configdir = os.path.abspath(ro_test_config.CONFIGDIR)
     robasedir = os.path.abspath(ro_test_config.ROBASEDIR)
     with SwitchWorkingDirectory(rodir):
         with SwitchStdout(self.outstr):
             status = ro.runCommand(configdir, robasedir, args)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     log.debug("outtxt: %s"%(outtxt))
     self.assertEqual(outtxt.count("ro annotations"), 1)
     self.assertRegexpMatches(outtxt, "title.*RO test annotation")
     self.assertRegexpMatches(outtxt, "rdf:type.*<%s>"%(RO.ResearchObject))
     self.assertNotRegexpMatches(outtxt, "\n<subdir1/subdir1-file.txt>")
     self.deleteTestRo(rodir)
     return
Example #13
0
 def testLinkWithNotExistentGraph(self):
     rodir  = self.createTestRo(testbase, "data/ro-test-1", "RO test annotation", "ro-testRoAnnotate")
     rofile = rodir+"/"+"subdir1/subdir1-file.txt"
     # Apply non-exietent graph annotation
     annotation_graph_filename = os.path.join(os.path.abspath(rodir), "annotate-none.rdf")
     rouri = ro_manifest.getRoUri(rodir)
     args = ["ro", "annotate", rodir+"/", "-g", annotation_graph_filename ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     # Read manifest and check for annotation
     annotations = ro_annotation.getAllAnnotations(rodir)
     expected_annotations = (
         [ ( rouri, DCTERMS.identifier,  rdflib.Literal('ro-testRoAnnotate')  )
         , ( rouri, DCTERMS.description, rdflib.Literal('RO test annotation') )
         , ( rouri, DCTERMS.title,       rdflib.Literal('RO test annotation') )
         , ( rouri, DCTERMS.creator,     rdflib.Literal('Test User') )
         , ( rouri, RDF.type,            RO.ResearchObject )
         ])
     count = 0
     for next in list(annotations):
         if ( # not isinstance(next[2], rdflib.BNode) and
              not next[1] in [ORE.aggregates, DCTERMS.created] and
              not next[1] == DCTERMS.created ):
             log.debug("- next %s"%(str(next[0])) )
             log.debug("       - (%s, %s)"%(str(next[1]),str(next[2])) )
             if next in expected_annotations:
                 count += 1
             else:
                 self.assertTrue(False, "Not expected (%d) %s"%(count, repr(next)))
     self.assertEqual(count,5)
     # Clean up
     self.deleteTestRo(rodir)
     return
Example #14
0
 def testSnapshotAsynchronous(self):
     args = [
         "ro", "snapshot" , str(self.CREATED_RO), self.TEST_SNAPHOT_ID, 
         "--asynchronous",
         "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
         "-r", ro_test_config.ROSRS_URI,
         "-v"
     ]    
     outLines = ""
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
         assert status == 0
         # simple check if the verbouse mode works well            
         for word in ("ro snapshot --asynchronous "+ro_test_config.ROSRS_URI + self.TEST_RO_ID + " " + self.TEST_SNAPHOT_ID).split(" "):
             self.assertTrue(self.outstr.getvalue().count(word+ " ") or self.outstr.getvalue().count(" " + word), "snapshot command wasn't parse well")
         self.assertEqual(self.outstr.getvalue().count("Job Status: "), 1)
         self.assertEqual(self.outstr.getvalue().count("Job URI: "), 1)
         self.assertEqual(self.outstr.getvalue().count("Target URI: "), 1)
         self.assertEqual(self.outstr.getvalue().count("Target Name: "), 1)
         self.assertEqual(self.outstr.getvalue().count("Response Status: "), 1)
         self.assertEqual(self.outstr.getvalue().count("Response Reason: "), 1)
         outLines = self.outstr.getvalue().split("\n")
     for line in outLines:
         if "Job URI:" in line:
             jobLocation = line.split("Job URI:")[1].strip()
             status = "RUNNING"
             while status == "RUNNING":
                 (status, id) = parse_job(self.rosrs, jobLocation)
             assert status == "DONE"
             self.rosrs.deleteRO(id)
     return
Example #15
0
 def linkTest(self, anntype, annvalue, anntypeuri, annexpect):
     rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test annotation", "ro-testRoAnnotate")
     args = [
         "ro", "link", rodir+"/"+"subdir1/subdir1-file.txt", anntype, annvalue,
         "-v",
         ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     self.assertEqual(outtxt.count("ro link"), 1)
     # Read manifest and check for annotation
     annotations = ro_annotation._getFileAnnotations(rodir, "subdir1/subdir1-file.txt")
     resourceuri = ro_manifest.getComponentUri(rodir, "subdir1/subdir1-file.txt")
     expected_annotations = (
         [ (resourceuri, anntypeuri, annexpect)
         ])
     count = 0
     for next in list(annotations):
         log.debug("- next %s"%(str(next[0])) )
         log.debug("       - (%s, %s)"%(str(next[1]),str(next[2])) )
         if next in expected_annotations:
             count += 1
         else:
             self.assertTrue(False, "Not expected (%d) %s"%(count, repr(next)))
     self.assertEqual(count,1)
     self.deleteTestRo(rodir)
     return
    def testPushZipSynchronous(self):
        """
        Push a Research Object in zip format to ROSRS.

        ro push <zip> | -d <dir>  [ -f ] [ -r <rosrs_uri> ] [ -t <access_token> ] 
        """
        args = [
            "ro", "push", "zips/pushro-6.zip",
            "-r", ro_test_config.ROSRS_URI,
            "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
            "-v"
            ]
        
        #preparing
        httpsession = ROSRS_Session(ro_test_config.ROSRS_URI,
        accesskey=ro_test_config.ROSRS_ACCESS_TOKEN)
        with SwitchStdout(self.outstr):
            status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
        
        #cleaning
        ro_remote_metadata.deleteRO(httpsession, ro_test_config.ROSRS_URI + "ro1/")
        
        assert status == 0
        self.assertEqual(self.outstr.getvalue().count("Job URI"),1)
        for line in self.outstr.getvalue().split("\n"):
            if "RO URI:" in line:
                id = line.split("RO URI:")[1].strip()
                ro_remote_metadata.deleteRO(httpsession,id)
    def testPushZipAsynchronous(self):
        """
        Push a Research Object in zip format to ROSRS.

        ro push <zip> | -d <dir>  [ -f ] [ -r <rosrs_uri> ] [ -t <access_token> ] 
        """
        args = [
            "ro", "push", "zips/pushro-6.zip",
            "-r", ro_test_config.ROSRS_URI,
            "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
            "--asynchronous",
            "-v"
            ]
        
        #preparing
        httpsession = ROSRS_Session(ro_test_config.ROSRS_URI,
        accesskey=ro_test_config.ROSRS_ACCESS_TOKEN)
        ro_remote_metadata.deleteRO(httpsession, ro_test_config.ROSRS_URI + "ro/")
        
        with SwitchStdout(self.outstr):
            status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
        assert status == 0
        self.assertEqual(self.outstr.getvalue().count("Job URI"),1)
        #self.assertEqual(self.outstr.getvalue().count("Job Status:"),1)
        for line in self.outstr.getvalue().split("\n"):
            if "Job URI:" in line:
                jobLocation = line.split("Job URI:")[1].strip()
                status = "RUNNING"
                while status == "RUNNING":
                    time.sleep(1)
                    (status, id, processed_resources, submitted_resources) = parse_job(self.rosrs, jobLocation)
                assert status == "DONE"
                self.rosrs.deleteRO(id)
Example #18
0
    def FreezeNonExistetSnaphot(self):
        """
        freeze <RO-id> 
        """
        #preapre snaphot
        (status, reason) = self.rosrs.deleteRO(self.TEST_RO_ID+"/")
        (status, reason) = self.rosrs.deleteRO(self.TEST_SNAPHOT_ID+"/")

        (status, reason, rouri, manifest) = self.rosrs.createRO(self.TEST_RO_ID,
            "Test RO for ROEVO", "Test Creator", "2012-09-06")        
        self.createSnapshot(self.TEST_RO_ID+"/", self.TEST_SNAPHOT_ID, True)
        
        args = [
            "ro", "freeze", self.TEST_SNAPHOT_RO_ID + "non exited", 
            "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
            "-r", ro_test_config.ROSRS_URI,
            "-v"
        ]
        with SwitchStdout(self.outstr):
            status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
            assert status == -1
            self.assertEqual(self.outstr.getvalue().count("Given URI isn't correct"), 0)
        (status, reason) = self.rosrs.deleteRO(self.TEST_SNAPHOT_ID+"/")
        (status, reason) = self.rosrs.deleteRO(self.TEST_RO_ID+"/")
        return
Example #19
0
    def testFreeze(self):
        """
        freeze <RO-id> 
        """
        #preapre snaphot
        
        (status, reason) = self.rosrs.deleteRO(self.TEST_RO_ID+"/")
        (status, reason) = self.rosrs.deleteRO(self.TEST_SNAPHOT_ID+"/")

        (status, reason, createdRoUri, manifest) = self.rosrs.createRO(self.TEST_RO_ID,
            "Test RO for ROEVO", "Test Creator", "2012-09-06")        
        (createdSnapshotStatus, createdSnapshotId) =  self.createSnapshot(createdRoUri, self.TEST_SNAPHOT_ID, False)
        args = [
            "ro", "freeze",str(createdSnapshotId), 
            "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
            "-r", ro_test_config.ROSRS_URI,
            "-v"
        ]
        with SwitchStdout(self.outstr):
            status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
            assert status == 0
            self.assertEqual(self.outstr.getvalue().count("freeze operation finished successfully"), 1)
        (status, reason) = self.rosrs.deleteRO(createdRoUri)
        (status, reason) = self.rosrs.deleteRO(createdSnapshotId)
        return
 def testEvaluateWfInputsRDF(self):
     # repeat previous test case, but with RDF output
     self.setupConfig()
     rodir = self.createTestRo(testbase, "test-simple-wf", "RO test minim", "ro-testMinim")
     self.populateTestRo(testbase, rodir)
     self.annotateWfRo(testbase, rodir)
     rometa   = ro_metadata(ro_config, rodir)
     minimuri = rometa.getComponentUri("simple-wf-minim.rdf")
     # Evaluate
     args = [ "ro", "evaluate", "checklist"
            , "-a"
            , "-d", rodir+"/"
            , "-o", "rdfxml"
            , "simple-wf-minim.rdf"
            , "Runnable"
            , "."
            ]
     self.outstr.seek(0)
     with StdoutContext.SwitchStdout(self.outstr):
         status = ro.runCommand(
             os.path.join(testbase, TestConfig.ro_test_config.CONFIGDIR),
             os.path.join(testbase, TestConfig.ro_test_config.ROBASEDIR),
             args)
     outtxt = self.outstr.getvalue()
     assert status == 0, "Status %d, outtxt: %s"%(status,outtxt)
     log.debug("status %d, outtxt: \n--------\n%s----"%(status, outtxt))
     # Check response returned
     self.outstr.seek(0)
     outgraph = rdflib.Graph()
     outgraph.parse(self.outstr)
     prefixes = make_sparql_prefixes()
     rouri    = rometa.getRoUri()
     modeluri = rometa.getComponentUriAbs("simple-wf-minim.rdf#runnable_RO_model")
     probequeries = (
         [ '''ASK { _:r minim:testedRO <%s> ; minim:minimUri <%s> }'''%
           (rouri, minimuri)
         , '''ASK { _:r minim:testedRO <%s> ; minim:testedModel <%s> }'''%
           (rouri, modeluri)
         , '''ASK { _:r minim:testedRO <%s> ; minim:satisfied [ minim:tryMessage "%s" ] }'''%
           (rouri, "Workflow instance or template found")
         , '''ASK { _:r minim:testedRO <%s> ; minim:satisfied [ minim:tryMessage "%s" ] }'''%
           (rouri, "All workflow inputs referenced or present")
         , '''ASK { _:r minim:testedRO <%s> ; minim:fullySatisfies <%s> }'''%
           (rouri, modeluri)
         , '''ASK { _:r minim:testedRO <%s> ; minim:nominallySatisfies <%s> }'''%
           (rouri, modeluri)
         , '''ASK { _:r minim:testedRO <%s> ; minim:minimallySatisfies <%s> }'''%
           (rouri, modeluri)
         , '''ASK { <%s> rdfs:label "%s" }'''%
           (rouri, rdflib.Literal("RO test minim"))
         ])
     for q in probequeries:
         log.debug("- query %s"%(q))
         r = outgraph.query(prefixes+q)
         self.assertEqual(r.type, 'ASK', "Result type %s for: %s"%(r.type, q))
         self.assertTrue(r.askAnswer, "Failed query: %s"%(q))
     self.deleteTestRo(rodir)
     return
 def testInvalidCommand(self):
     with SwitchStdout(self.outstr):
         status = ro.runCommand(
             ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, 
             ["ro", "nosuchcommand"])
         self.assertEqual(status, 2)
     self.assertEqual(self.outstr.getvalue().count("Unrecognized"), 1)
     self.assertEqual(self.outstr.getvalue().count("nosuchcommand"), 1)
     return
 def annotateMultiple(self, rodir, rofile, annotations):
     with SwitchStdout(self.outstr):
         for a in annotations:
             args = ["ro", "annotate", rofile, a["atypename"], a["avalue"]]
             status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
             outtxt = self.outstr.getvalue()
             assert status == 0, outtxt
     # Reset output stream buffer closed
     self.outstr = StringIO.StringIO()
     return
    def testRemoveWildcard(self):
        """
        Test remove aggregated resources from RO

        ro remove subdir2/subdir2-file.txt
        """
        rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test remove", "ro-testRoRemove")                      
        self.populateTestRo(testbase, rodir)
        # Remove resource
        args = [
            "ro", "remove",
            "-d", rodir, "-w", "\\.txt$",
            "-v"
            ]
        with SwitchStdout(self.outstr):
            status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
        outtxt = self.outstr.getvalue()
        assert status == 0, outtxt
        self.outstr = StringIO.StringIO()
        # List contents
        args = [
            "ro", "ls",
            "-d", rodir,
            "-v"
            ]
        with SwitchStdout(self.outstr):
            status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
        outtxt = self.outstr.getvalue()
        self.outstr = StringIO.StringIO()
        assert status == 0, outtxt
        self.assertEqual(outtxt.count("ro list"), 1)
        self.assertRegexpMatches(outtxt, "README-ro-test-1")
        self.assertNotRegexpMatches(outtxt, "filename%20with%20spaces.txt")
        self.assertNotRegexpMatches(outtxt, "filename%23with%23hashes.txt")
        self.assertNotRegexpMatches(outtxt, "subdir1/subdir1-file.txt")
        self.assertNotRegexpMatches(outtxt, "subdir2/subdir2-file.txt")
        self.assertNotRegexpMatches(outtxt, "subdir1/\\s")
        self.assertNotRegexpMatches(outtxt, "subdir2/\\s")
        self.deleteTestRo(rodir)
        return
 def testAddExternalResource(self):
     """
     Add external resource to created RO
     """
     rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test add", "ro-testRoAdd")
     self.populateTestRo(testbase, rodir)
     args = [
         "ro", "add",
         "-d", rodir,
         "http://example.org/external",
         ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     self.outstr = StringIO.StringIO()
     # Now list contents
     args = [
         "ro", "ls",
         "-d", rodir,
         "-v"
         ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     self.assertEqual(outtxt.count("ro list"), 1)
     self.assertRegexpMatches(outtxt, "README-ro-test-1")
     self.assertRegexpMatches(outtxt, "filename%20with%20spaces.txt")
     self.assertRegexpMatches(outtxt, "filename%23with%23hashes.txt")
     self.assertRegexpMatches(outtxt, "subdir1/subdir1-file.txt")
     self.assertRegexpMatches(outtxt, "subdir2/subdir2-file.txt")
     self.assertNotRegexpMatches(outtxt, "subdir1/\\s")
     self.assertNotRegexpMatches(outtxt, "subdir2/\\s")
     self.assertRegexpMatches(outtxt, "http://example.org/external")
     self.deleteTestRo(rodir)
     return
 def annotateWfRo(self, testbase, rodir):
     """
     Annotate test workflow research object
     Returns name of research object directory
     """
     # $RO annotate -v $TESTRO/simple-wf-wfdesc.rdf rdf:type wfdesc:Workflow
     args1 = [
         "ro", "annotate", rodir+"/make.sh", "rdf:type", "wfdesc:Workflow"
         ]
     # $RO annotate -v $TESTRO/docs/mkjson.sh -g $TESTRO/simple-ef-wfdesc.rdf
     args2 = [
         "ro", "annotate", rodir+"/docs/mkjson.sh", "-g", rodir+"/simple-wf-wfdesc.rdf"
         ]
     with StdoutContext.SwitchStdout(self.outstr):
         configdir = self.getConfigDir(testbase)
         robasedir = self.getRoBaseDir(testbase)
         #print "testbase %s, configdir %s, robasedir %s"%(testbase, configdir, robasedir)
         status = ro.runCommand(configdir, robasedir, args1)
         if status == 0:
             status = ro.runCommand(configdir, robasedir, args2)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     self.outstr = StringIO.StringIO()
     return rodir
 def testAnnotateWildcardPattern2(self):
     """
     Same as previous test, but includes filenames with spaces and hashes
     """
     rodir  = self.createTestRo(testbase, "data/ro-test-1", "RO test annotation", "ro-testRoAnnotate")
     self.populateTestRo(testbase, rodir)
     # Apply annotation to filename pattern
     rouri = ro_manifest.getRoUri(rodir)
     args = ["ro", "annotate"
            ,"-d", rodir+"/"
            , "-w", "\\.txt$"
            , "dcterms:description", "pattern annotation" ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     # Read manifest and check for annotation
     annotations = ro_annotation.getAllAnnotations(rodir)
     res_spc_uri = ro_manifest.getComponentUriAbs(rodir, "filename%20with%20spaces.txt")
     res_hsh_uri = ro_manifest.getComponentUriAbs(rodir, "filename%23with%23hashes.txt")
     resource1uri = ro_manifest.getComponentUriAbs(rodir, "subdir1/subdir1-file.txt")
     resource2uri = ro_manifest.getComponentUriAbs(rodir, "subdir2/subdir2-file.txt")
     expected_annotations = (
         [ ( rouri, DCTERMS.identifier,  rdflib.Literal('ro-testRoAnnotate')  )
         , ( rouri, DCTERMS.description, rdflib.Literal('RO test annotation') )
         , ( rouri, DCTERMS.title,       rdflib.Literal('RO test annotation') )
         , ( rouri, DCTERMS.creator,     rdflib.Literal('Test User') )
         , ( rouri, RDF.type,            RO.ResearchObject )
         , ( res_spc_uri,  DCTERMS.description, rdflib.Literal('pattern annotation') )
         , ( res_hsh_uri,  DCTERMS.description, rdflib.Literal('pattern annotation') )
         , ( resource1uri, DCTERMS.description, rdflib.Literal('pattern annotation') )
         , ( resource2uri, DCTERMS.description, rdflib.Literal('pattern annotation') )
         ])
     count = 0
     for next in list(annotations):
         if ( not isinstance(next[2], rdflib.BNode) and
              not next[1] in [ORE.aggregates, DCTERMS.created] ):
             log.debug("- next %s"%(str(next[0])) )
             log.debug("       - (%s, %s)"%(str(next[1]),str(next[2])) )
             if next in expected_annotations:
                 count += 1
             else:
                 self.assertTrue(False, "Not expected (%d) %s"%(count, repr(next)))
     self.assertEqual(count,9)
     # Clean up
     #self.deleteTestRo(rodir)
     return
Example #27
0
    def annotateResource(self, testbase, rodir, resref, annref):
        """
        Annotate named resource with named annotation resource
        Names are appended to the RO directory.

        Returns RO directory.
        """
        # $RO annotate $resuri -g $annuri
        args = ["ro", "annotate", rodir + "/" + resref, "-g", rodir + "/" + annref]
        with StdoutContext.SwitchStdout(self.outstr):
            configdir = self.getConfigDir(testbase)
            robasedir = self.getRoBaseDir(testbase)
            status = ro.runCommand(configdir, robasedir, args)
        outtxt = self.outstr.getvalue()
        assert status == 0, outtxt
        self.outstr = StringIO.StringIO()
        return rodir
Example #28
0
 def testRemoteStatusWithWrongUriGiven(self):
     self.rosrs = ROSRS_Session(ro_test_config.ROSRS_URI, accesskey=ro_test_config.ROSRS_ACCESS_TOKEN)
     self.rosrs.deleteRO(self.TEST_RO_ID + "/")
     self.rosrs.deleteRO("some-strange-uri/")
     args = [
         "ro", "status", ro_test_config.ROSRS_URI + "some-strange-uri/",
         "-r", ro_test_config.ROSRS_URI, 
         "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
         "-v"
     ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
         outtxt = self.outstr.getvalue()
         assert status == -1
         self.assertEqual(outtxt.count("Wrong URI was given"), 1)
     self.rosrs.deleteRO(self.TEST_RO_ID + "/")
     return
Example #29
0
 def testRemoteStatusLiveRO(self):
     self.rosrs = ROSRS_Session(ro_test_config.ROSRS_URI, accesskey=ro_test_config.ROSRS_ACCESS_TOKEN)
     (status, reason) = self.rosrs.deleteRO(self.TEST_RO_ID+"/")
     (status, reason, rouri, manifest) = self.rosrs.createRO(self.TEST_RO_ID,
         "Test RO for ROEVO", "Test Creator", "2012-09-06")
     args = [
         "ro", "status", str(rouri),
         "-r", ro_test_config.ROSRS_URI, 
         "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
         "-v"
     ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
         assert status == 0
         outtxt = self.outstr.getvalue()
         self.assertEqual(outtxt.count("LIVE"), 1)
     (status, reason) = self.rosrs.deleteRO(rouri)
     return
Example #30
0
 def testArchiveSynchronous(self):
     args = [
         "ro", "archive", ro_test_config.ROSRS_URI + self.TEST_RO_ID, ro_test_config.ROSRS_URI + self.TEST_SNAPHOT_ID, 
         "-t", ro_test_config.ROSRS_ACCESS_TOKEN,
         "-r", ro_test_config.ROSRS_URI,
         "-v"
     ]
     outLines = ""
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
         assert status == 0
         # simple check if the verbouse mode works well
         self.assertEqual(self.outstr.getvalue().count("--asynchronous"), 0, "shouldn't be asynchronous")
         outLines = self.outstr.getvalue().split("\n")
     for line in outLines:
         if "Target URI:" in line:
             id = line.split("Target URI:")[1].strip()
             self.rosrs.deleteRO(id)
     return