def test_01_dip_config_dipdir(self): dipdir = os.path.join(self._dipdir, "testdip") argv = ["dip", "config", "--dip", "testdip"] outstr = StringIO.StringIO() with SwitchStdout(outstr): status = runCommand(self._cnfdir, self._dipdir, argv) self.assertEqual(status, diperrors.DIP_SUCCESS) self.assertEqual(dip_get_default_dir(self._cnfdir), self._dipdir+"/testdip") result = outstr.getvalue() self.assertIn('''dipdir="%s"'''%(dipdir), result) self.assertIn('''dipbase="%s"'''%(self._dipdir), result) # Show config argv = ["dip", "config"] outstr = StringIO.StringIO() with SwitchStdout(outstr): status = runCommand(self._cnfdir, self._dipdir, argv) self.assertEqual(status, diperrors.DIP_SUCCESS) self.assertEqual(dip_get_default_dir(self._cnfdir), self._dipdir+"/testdip") result = outstr.getvalue() self.assertIn('''dipdir="%s"'''%(dipdir), result) self.assertIn('''dipbase="%s"'''%(self._dipdir), result) return
def test_02_dip_config_sword_collection(self): dipdir = os.path.join(self._dipdir, "testdip") argv = ( [ "dip", "config" , '''--collection_uri="%s"'''%DSS.collection_uri , '''--servicedoc_uri="%s"'''%DSS.servicedoc_uri , '''--username="******"'''%DSS.username , '''--password="******"'''%DSS.password ]) outstr = StringIO.StringIO() with SwitchStdout(outstr): status = runCommand(self._cnfdir, self._dipdir, argv) self.assertEqual(status, diperrors.DIP_SUCCESS) result = outstr.getvalue() # print("========\n%s\n========"%result) self.assertIn('''collection_uri="%s"'''%(DSS.collection_uri), result) self.assertIn('''servicedoc_uri="%s"'''%(DSS.servicedoc_uri), result) self.assertIn('''username="******"'''%(DSS.username), result) self.assertIn('''password="******"'''%("*"*len(DSS.password)), result) self.assertNotIn('''dipdir="%s"'''%(dipdir), result) self.assertNotIn('''dipbase="%s"'''%(self._dipdir), result) # Show config argv = ["dip", "config"] outstr = StringIO.StringIO() with SwitchStdout(outstr): status = runCommand(self._cnfdir, self._dipdir, argv) self.assertEqual(status, diperrors.DIP_SUCCESS) self.assertEqual(dip_get_default_dir(self._cnfdir), self._dipdir+"/testdip") result = outstr.getvalue() # print("========\n%s\n========"%result) self.assertIn('''collection_uri="%s"'''%(DSS.collection_uri), result) self.assertIn('''servicedoc_uri="%s"'''%(DSS.servicedoc_uri), result) self.assertIn('''username="******"'''%(DSS.username), result) self.assertIn('''password="******"'''%("*"*len(DSS.password)), result) # self.assertNotIn('''dipdir="%s"'''%(dipdir), result) # self.assertNotIn('''dipbase="%s"'''%(self._dipdir), result) return
def test_11_dip_create(self): dipdir = os.path.join(self._dipdir, "testdip") argv = ["dip", "create", "--dip", "testdip"] outstr = StringIO.StringIO() with SwitchStdout(outstr): status = runCommand(self._cnfdir, self._dipdir, argv) self.assertEqual(status, diperrors.DIP_SUCCESS) self.assertTrue(os.path.isdir(dipdir)) self.assertEqual(dip_get_default_dir(self._cnfdir), self._dipdir+"/testdip") self.assertEqual( outstr.getvalue(), "Created deposit information package at %s\n"%(dipdir) ) # again... outstr = StringIO.StringIO() with SwitchStdout(outstr): with SwitchStderr(outstr): status = runCommand(self._cnfdir, self._dipdir, argv) self.assertEqual(status, diperrors.DIP_EXISTS) self.assertEqual( outstr.getvalue(), "Specified directory already exists: %s\n"%(dipdir) ) return