def test_print_info(self): db_file = 'foo' self.assertRaises(InfoSystemExit, print_info, 'object', db_file) db_file = os.path.join(self.testdir, './acct.db') self.assertRaises(InfoSystemExit, print_info, 'account', db_file) controller = AccountController( {'devices': self.testdir, 'mount_check': 'false'}) req = Request.blank('/sda1/1/acct', environ={'REQUEST_METHOD': 'PUT', 'HTTP_X_TIMESTAMP': '0'}) resp = req.get_response(controller) self.assertEqual(resp.status_int, 201) out = StringIO() exp_raised = False with mock.patch('sys.stdout', out): db_file = os.path.join(self.testdir, 'sda1', 'accounts', '1', 'b47', 'dc5be2aa4347a22a0fee6bc7de505b47', 'dc5be2aa4347a22a0fee6bc7de505b47.db') try: print_info('account', db_file, swift_dir=self.testdir) except Exception: exp_raised = True if exp_raised: self.fail("Unexpected exception raised") else: self.assertTrue(len(out.getvalue().strip()) > 800) controller = ContainerController( {'devices': self.testdir, 'mount_check': 'false'}) req = Request.blank('/sda1/1/acct/cont', environ={'REQUEST_METHOD': 'PUT', 'HTTP_X_TIMESTAMP': '0'}) resp = req.get_response(controller) self.assertEqual(resp.status_int, 201) out = StringIO() exp_raised = False with mock.patch('sys.stdout', out): db_file = os.path.join(self.testdir, 'sda1', 'containers', '1', 'cae', 'd49d0ecbb53be1fcc49624f2f7c7ccae', 'd49d0ecbb53be1fcc49624f2f7c7ccae.db') orig_cwd = os.getcwd() try: os.chdir(os.path.dirname(db_file)) print_info('container', os.path.basename(db_file), swift_dir='/dev/null') except Exception: exp_raised = True finally: os.chdir(orig_cwd) if exp_raised: self.fail("Unexpected exception raised") else: self.assertTrue(len(out.getvalue().strip()) > 600)
def test_print_info(self): db_file = 'foo' self.assertRaises(InfoSystemExit, print_info, 'object', db_file) db_file = os.path.join(self.testdir, './acct.db') self.assertRaises(InfoSystemExit, print_info, 'account', db_file) controller = AccountController({ 'devices': self.testdir, 'mount_check': 'false' }) req = Request.blank('/sda1/1/acct', environ={ 'REQUEST_METHOD': 'PUT', 'HTTP_X_TIMESTAMP': '0' }) resp = req.get_response(controller) self.assertEqual(resp.status_int, 201) out = StringIO() exp_raised = False with mock.patch('sys.stdout', out): db_file = os.path.join(self.testdir, 'sda1', 'accounts', '1', 'b47', 'dc5be2aa4347a22a0fee6bc7de505b47', 'dc5be2aa4347a22a0fee6bc7de505b47.db') try: print_info('account', db_file, swift_dir=self.testdir) except Exception: exp_raised = True if exp_raised: self.fail("Unexpected exception raised") else: self.assertTrue(len(out.getvalue().strip()) > 800) controller = ContainerController({ 'devices': self.testdir, 'mount_check': 'false' }) req = Request.blank('/sda1/1/acct/cont', environ={ 'REQUEST_METHOD': 'PUT', 'HTTP_X_TIMESTAMP': '0' }) resp = req.get_response(controller) self.assertEqual(resp.status_int, 201) out = StringIO() exp_raised = False with mock.patch('sys.stdout', out): db_file = os.path.join(self.testdir, 'sda1', 'containers', '1', 'cae', 'd49d0ecbb53be1fcc49624f2f7c7ccae', 'd49d0ecbb53be1fcc49624f2f7c7ccae.db') orig_cwd = os.getcwd() try: os.chdir(os.path.dirname(db_file)) print_info('container', os.path.basename(db_file), swift_dir='/dev/null') except Exception: exp_raised = True finally: os.chdir(orig_cwd) if exp_raised: self.fail("Unexpected exception raised") else: self.assertTrue(len(out.getvalue().strip()) > 600) out = StringIO() exp_raised = False with mock.patch('sys.stdout', out): db_file = os.path.join(self.testdir, 'sda1', 'containers', '1', 'cae', 'd49d0ecbb53be1fcc49624f2f7c7ccae', 'd49d0ecbb53be1fcc49624f2f7c7ccae.db') orig_cwd = os.getcwd() try: os.chdir(os.path.dirname(db_file)) print_info('account', os.path.basename(db_file), swift_dir='/dev/null') except InfoSystemExit: exp_raised = True finally: os.chdir(orig_cwd) if exp_raised: exp_out = 'Does not appear to be a DB of type "account":' \ ' ./d49d0ecbb53be1fcc49624f2f7c7ccae.db' self.assertEqual(out.getvalue().strip(), exp_out) else: self.fail("Expected an InfoSystemExit exception to be raised")
def test_print_info(self): db_file = "foo" self.assertRaises(InfoSystemExit, print_info, "object", db_file) db_file = os.path.join(self.testdir, "./acct.db") self.assertRaises(InfoSystemExit, print_info, "account", db_file) controller = AccountController({"devices": self.testdir, "mount_check": "false"}) req = Request.blank("/sda1/1/acct", environ={"REQUEST_METHOD": "PUT", "HTTP_X_TIMESTAMP": "0"}) resp = req.get_response(controller) self.assertEqual(resp.status_int, 201) out = StringIO() exp_raised = False with mock.patch("sys.stdout", out): db_file = os.path.join( self.testdir, "sda1", "accounts", "1", "b47", "dc5be2aa4347a22a0fee6bc7de505b47", "dc5be2aa4347a22a0fee6bc7de505b47.db", ) try: print_info("account", db_file, swift_dir=self.testdir) except Exception: exp_raised = True if exp_raised: self.fail("Unexpected exception raised") else: self.assertTrue(len(out.getvalue().strip()) > 800) controller = ContainerController({"devices": self.testdir, "mount_check": "false"}) req = Request.blank("/sda1/1/acct/cont", environ={"REQUEST_METHOD": "PUT", "HTTP_X_TIMESTAMP": "0"}) resp = req.get_response(controller) self.assertEqual(resp.status_int, 201) out = StringIO() exp_raised = False with mock.patch("sys.stdout", out): db_file = os.path.join( self.testdir, "sda1", "containers", "1", "cae", "d49d0ecbb53be1fcc49624f2f7c7ccae", "d49d0ecbb53be1fcc49624f2f7c7ccae.db", ) orig_cwd = os.getcwd() try: os.chdir(os.path.dirname(db_file)) print_info("container", os.path.basename(db_file), swift_dir="/dev/null") except Exception: exp_raised = True finally: os.chdir(orig_cwd) if exp_raised: self.fail("Unexpected exception raised") else: self.assertTrue(len(out.getvalue().strip()) > 600) out = StringIO() exp_raised = False with mock.patch("sys.stdout", out): db_file = os.path.join( self.testdir, "sda1", "containers", "1", "cae", "d49d0ecbb53be1fcc49624f2f7c7ccae", "d49d0ecbb53be1fcc49624f2f7c7ccae.db", ) orig_cwd = os.getcwd() try: os.chdir(os.path.dirname(db_file)) print_info("account", os.path.basename(db_file), swift_dir="/dev/null") except InfoSystemExit: exp_raised = True finally: os.chdir(orig_cwd) if exp_raised: exp_out = 'Does not appear to be a DB of type "account":' " ./d49d0ecbb53be1fcc49624f2f7c7ccae.db" self.assertEquals(out.getvalue().strip(), exp_out) else: self.fail("Expected an InfoSystemExit exception to be raised")