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["roboxuri"], None) self.assertEqual(config["roboxpass"], None) self.assertEqual(config["username"], None) self.assertEqual(config["useremail"], None) args = [ "ro", "config", "-b", ro_test_config.ROBASEDIR, "-r", ro_test_config.ROBOXURI, "-n", ro_test_config.ROBOXUSERNAME, "-p", ro_test_config.ROBOXPASSWORD, "-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["roboxuri"], ro_test_config.ROBOXURI) self.assertEqual(config["roboxpass"], ro_test_config.ROBOXPASSWORD) self.assertEqual(config["username"], ro_test_config.ROBOXUSERNAME) self.assertEqual(config["useremail"], ro_test_config.ROBOXEMAIL) return
def testAnnotate(self): """ Annotate file in created RO ro annotate file attribute-name [ attribute-value ] """ rodir = self.createTestRo("data/ro-test-1", "RO test annotation", "ro-testRoAnnotate") args = [ "ro", "annotate", rodir+"/"+"subdir1/subdir1-file.txt", "title", "subdir1-file title", "-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) #self.assertRegexpMatches(outtxt, "annotation.*dc:title") # Read manifest and check for annotation manifestgraph = ro_manifest.readManifestGraph(rodir) filesubj = ro_manifest.getComponentUri(rodir, "subdir1/subdir1-file.txt") log.debug("filesubj %s"%filesubj) filetitle = manifestgraph.value(filesubj, DCTERMS.title, None), self.assertEqual(len(filetitle), 1, "Singleton result expected") self.assertEqual(filetitle[0], "subdir1-file title") self.deleteTestRo(rodir) return
def testListDefault(self): """ Display contents of created RO containing current directory ro ls """ rodir = self.createTestRo("data/ro-test-1", "RO test list", "ro-testRoList") 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.deleteTestRo(rodir) return
def testStatusDefault(self): """ Display status of created RO ro status """ rodir = self.createTestRo("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 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 createTestRo(self, src, roname, roident): """ Create test research object Returns name of research object directory """ rodir = self.createRoFixture(src, ro_test_config.ROBASEDIR, ro_utils.ronametoident(roname)) args = [ "ro", "create", roname, "-v", "-d", rodir, "-i", roident, ] with SwitchStdout(self.outstr): status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args) assert status == 0 return rodir
def annotationTest(self, anntype, annvalue, anntypeuri, annexpect): rodir = self.createTestRo("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 manifestgraph = ro_manifest.readManifestGraph(rodir) filesubj = ro_manifest.getComponentUri(rodir, "subdir1/subdir1-file.txt") fileann = manifestgraph.value(filesubj, anntypeuri, None), #@@TODO: deal with case that expected result is a list self.assertEqual(len(fileann), 1, "Singleton result expected") self.assertEqual(fileann[0], annexpect) self.deleteTestRo(rodir) return
def testCreateBadDir(self): """ Create a new Research Object with directory not in configured area ro create RO-name [ -d dir ] [ -i RO-ident ] """ rodir = self.createRoFixture("data/ro-test-1", ro_test_config.NOBASEDIR, "ro-testCreateBadDir") args = [ "ro", "create", "Test Create RO bad directory", "-d", rodir, "-v" ] with SwitchStdout(self.outstr): status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args) self.assertTrue(status == 1, "Expected failure due to bad RO directory"); self.assertEqual(self.outstr.getvalue().count("research object not"), 1) manifestdir = rodir+"/"+ro_test_config.ROMANIFESTDIR self.assertFalse(os.path.exists(manifestdir), msg="checking created RO manifest dir") self.deleteRoFixture(rodir) return
def testCreate(self): """ Create a new Research Object. ro create RO-name [ -d dir ] [ -i RO-ident ] """ rodir = self.createRoFixture("data/ro-test-1", ro_test_config.ROBASEDIR, "ro-testCreate") args = [ "ro", "create", "Test Create RO", "-v", "-d", rodir, "-i", "RO-id-testCreate", ] 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 create"), 1) self.checkRoFixtureManifest(rodir) self.checkManifestContent(rodir, "Test Create RO", "RO-id-testCreate") self.deleteRoFixture(rodir) return
def testList(self): """ Display contents of created RO ro ls -d rodir """ rodir = self.createTestRo("data/ro-test-1", "RO test list", "ro-testRoList") 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.deleteTestRo(rodir) return
def testCreateDefaults(self): """ Create a new Research Object with default options ro create RO-name [ -d dir ] [ -i RO-ident ] """ rodir = self.createRoFixture("data/ro-test-1", ro_test_config.ROBASEDIR, "ro-testCreateDefaults") args = [ "ro", "create", "Test Create RO_+_defaults", "-v" ] configbase = os.path.abspath(ro_test_config.CONFIGDIR) save_cwd = os.getcwd() os.chdir(rodir) with SwitchStdout(self.outstr): status = ro.runCommand(configbase, ro_test_config.ROBASEDIR, args) os.chdir(save_cwd) assert status == 0 self.assertEqual(self.outstr.getvalue().count("ro create"), 1) self.checkRoFixtureManifest(rodir) self.deleteRoFixture(rodir) return
def testAnnotationDisplay(self): # Construct annotated RO rodir = self.createTestRo("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 args = [ "ro", "annotations", rofile , "-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 annotations"), 1) self.assertRegexpMatches(outtxt, "subdir1/subdir1-file.txt") self.assertRegexpMatches(outtxt, "type:.*atype") self.assertRegexpMatches(outtxt, "title:.*atitle") self.deleteTestRo(rodir) return
def testStatus(self): """ Display status of created RO ro status -d rodir """ rodir = self.createTestRo("data/ro-test-1", "RO test status", "ro-testRoStatus") args = [ "ro", "status", "-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 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 testHelpCommands(self): with SwitchStdout(self.outstr): status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, ["ro", "help"]) self.assertEqual(status, 0) self.assertEqual(self.outstr.getvalue().count("help"), 2) return
def testHelpVersion(self): status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, ["ro", "--version"]) self.assertEqual(status, 0) return