def tearDown(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(["delete", self.container, "--recursive"]) cli = CLI(args=args, stdout=stdout, stderr=stderr) cli.main()
def test_post_container(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['post', self.container, '-h', 'x-container-meta-swiftly-test:one']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue(), '') stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['head', self.container]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = \ dict(x.split(':', 1) for x in stdout.getvalue().split('\n') if x) self.assertEquals( sorted(stdout.keys()), ['X-Container-Bytes-Used', 'X-Container-Meta-Swiftly-Test', 'X-Container-Object-Count', 'X-Timestamp']) self.assertEquals(stderr.getvalue(), '')
def tearDown(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['delete', self.container, '--recursive']) cli = CLI(args=args, stdout=stdout, stderr=stderr) cli.main()
def test_post_obj(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['post', self.obj, '-h', 'x-object-meta-swiftly-test:one']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue(), '') stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['head', self.obj]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = \ dict(x.split(':', 1) for x in stdout.getvalue().split('\n') if x) self.assertEquals( sorted(stdout.keys()), ['Content-Length', 'Content-Type', 'Etag', 'Last-Modified', 'X-Object-Meta-Swiftly-Test', 'X-Timestamp']) self.assertEquals(stdout['Content-Length'].strip(), '9') self.assertEquals(stdout['Content-Type'].strip(), 'application/octet-stream') self.assertEquals(stdout['Etag'].strip(), 'e9de89b0a5e9ad6efd5e5ab543ec617c') self.assertEquals(stdout['X-Object-Meta-Swiftly-Test'].strip(), 'one') self.assertEquals(stderr.getvalue(), '')
def test_get_container(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['get', self.container]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), 'test\n') self.assertEquals(stderr.getvalue(), '')
def test_get_account(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(["get"]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertTrue(self.container in stdout.getvalue()) self.assertEquals(stderr.getvalue(), "")
def test_help_command(self): stdout = StringIO() stderr = StringIO() cli = CLI(args=['help', 'head'], stdout=stdout, stderr=stderr) rv = cli.main() stdout = stdout.getvalue() stderr = stderr.getvalue() self.assertEquals(rv, 1) self.assertTrue('Usage:' in stdout, stdout) self.assertTrue(not stderr)
def test_get_obj(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(["get", self.obj]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), "testvalue") self.assertEquals(stderr.getvalue(), "")
def test_head_container(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(["head", self.container]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = dict(x.split(":", 1) for x in stdout.getvalue().split("\n") if x) self.assertEquals(sorted(stdout.keys()), ["X-Container-Bytes-Used", "X-Container-Object-Count"]) self.assertEquals(stderr.getvalue(), "")
def test_help_invalid_command(self): stdout = StringIO() stderr = StringIO() cli = CLI(args=['help', 'slkdfjsdkfj'], stdout=stdout, stderr=stderr) rv = cli.main() stdout = stdout.getvalue() stderr = stderr.getvalue() self.assertEquals(rv, 1) self.assertTrue('Usage:' in stdout, stdout) self.assertTrue('Options:' in stdout, stdout) self.assertTrue('Commands:' in stdout, stdout) self.assertTrue(not stderr)
def test_invalid_args(self): stdout = StringIO() stderr = StringIO() cli = CLI(args=['asfsdasdf'], stdout=stdout, stderr=stderr) rv = cli.main() stdout = stdout.getvalue() stderr = stderr.getvalue() self.assertEquals(rv, 1) self.assertTrue('Usage:' in stdout, stdout) self.assertTrue('Options:' in stdout, stdout) self.assertTrue('Commands:' in stdout, stdout) self.assertTrue(not stderr)
def test_get_account_raw(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['get', '-r']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = json.loads(stdout.getvalue()) self.assertTrue(len(stdout)) stdout = stdout[0] self.assertEquals(sorted(stdout.keys()), ['bytes', 'count', 'name'])
def test_direct(self): stdout = StringIO() stderr = StringIO() cli = CLI(args=['-D', SWIFT_PROXY_STORAGE_PATH, 'auth'], stdout=stdout, stderr=stderr) rv = cli.main() stdout = stdout.getvalue() stderr = stderr.getvalue() self.assertEquals(rv, 0) stdout = stdout.split() self.assertEquals(stdout, ['Direct', 'Storage', 'Path:', '/v1/AUTH_test']) self.assertTrue(not stderr)
def test_head_account(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(["head"]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = dict(x.split(":", 1) for x in stdout.getvalue().split("\n") if x) self.assertTrue("X-Account-Bytes-Used" in stdout) self.assertTrue("X-Account-Container-Count" in stdout) self.assertTrue("X-Account-Object-Count" in stdout) self.assertEquals(stderr.getvalue(), "")
def test_head_obj(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(["head", self.obj]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = dict(x.split(":", 1) for x in stdout.getvalue().split("\n") if x) self.assertEquals(sorted(stdout.keys()), ["Content-Length", "Content-Type", "Etag", "Last-Modified"]) self.assertEquals(stdout["Content-Length"].strip(), "9") self.assertEquals(stdout["Content-Type"].strip(), "application/octet-stream") self.assertEquals(stdout["Etag"].strip(), "e9de89b0a5e9ad6efd5e5ab543ec617c") self.assertEquals(stderr.getvalue(), "")
def test_head_account(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['head']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = \ dict(x.split(':', 1) for x in stdout.getvalue().split('\n') if x) self.assertTrue('X-Account-Bytes-Used' in stdout) self.assertTrue('X-Account-Container-Count' in stdout) self.assertTrue('X-Account-Object-Count' in stdout) self.assertEquals(stderr.getvalue(), '')
def test_head_container(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['head', self.container]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = \ dict(x.split(':', 1) for x in stdout.getvalue().split('\n') if x) self.assertEquals(sorted(stdout.keys()), [ 'X-Container-Bytes-Used', 'X-Container-Object-Count', 'X-Timestamp' ]) self.assertEquals(stderr.getvalue(), '')
def test_get_container_full(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(["get", self.container, "-f"]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = stdout.getvalue().split() self.assertEquals(len(stdout), 6) self.assertEquals(stdout[0], "9") self.assertEquals(stdout[3], "e9de89b0a5e9ad6efd5e5ab543ec617c") self.assertEquals(stdout[4], "application/octet-stream") self.assertEquals(stdout[5], "test") self.assertEquals(stderr.getvalue(), "")
def test_get_container_full(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['get', self.container, '-f']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = stdout.getvalue().split() self.assertEquals(len(stdout), 6) self.assertEquals(stdout[0], '9') self.assertEquals(stdout[3], 'e9de89b0a5e9ad6efd5e5ab543ec617c') self.assertEquals(stdout[4], 'application/octet-stream') self.assertEquals(stdout[5], 'test') self.assertEquals(stderr.getvalue(), '')
def test_client(self): stdout = StringIO() stderr = StringIO() cli = CLI( args=['-A', AUTH_URL, '-U', AUTH_USER, '-K', AUTH_KEY, 'auth'], stdout=stdout, stderr=stderr) rv = cli.main() stdout = stdout.getvalue() stderr = stderr.getvalue() self.assertEquals(rv, 0) stdout = stdout.split() self.assertEquals(stdout[:2], ['Storage', 'URL:']) urlparse(stdout[2]) self.assertEquals(stdout[3:-1], ['Auth', 'Token:']) self.assertTrue(not stderr)
def test_get_container_raw(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['get', self.container, '-r']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = json.loads(stdout.getvalue()) self.assertEquals(len(stdout), 1) stdout = stdout[0] self.assertEquals(stdout['bytes'], 9) self.assertEquals(stdout['hash'], 'e9de89b0a5e9ad6efd5e5ab543ec617c') self.assertEquals(stdout['content_type'], 'application/octet-stream') self.assertEquals(stdout['name'], 'test') self.assertEquals(stderr.getvalue(), '')
def test_get_container_raw(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(["get", self.container, "-r"]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = json.loads(stdout.getvalue()) self.assertEquals(len(stdout), 1) stdout = stdout[0] self.assertEquals(stdout["bytes"], 9) self.assertEquals(stdout["hash"], "e9de89b0a5e9ad6efd5e5ab543ec617c") self.assertEquals(stdout["content_type"], "application/octet-stream") self.assertEquals(stdout["name"], "test") self.assertEquals(stderr.getvalue(), "")
def test_post_account(self): uuid = uuid4().hex stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend( ['post', '-h', 'x-account-meta-swiftly-test-%s:one' % uuid]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue(), '') stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['head']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = \ dict(x.split(':', 1) for x in stdout.getvalue().split('\n') if x) self.assertTrue('X-Account-Bytes-Used' in stdout) self.assertTrue('X-Account-Container-Count' in stdout) self.assertTrue('X-Account-Object-Count' in stdout) self.assertTrue( ('X-Account-Meta-Swiftly-Test-%s' % uuid).title() in stdout) self.assertEquals(stderr.getvalue(), '') stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend( ['post', '-h', 'x-account-meta-swiftly-test-%s:' % uuid]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue(), '') stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['head']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = \ dict(x.split(':', 1) for x in stdout.getvalue().split('\n') if x) self.assertTrue('X-Account-Bytes-Used' in stdout) self.assertTrue('X-Account-Container-Count' in stdout) self.assertTrue('X-Account-Object-Count' in stdout) self.assertTrue( ('X-Account-Meta-Swiftly-Test-%s' % uuid).title() not in stdout) self.assertEquals(stderr.getvalue(), '')
def test_head_obj_ignore_404(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(["head", self.obj + "2"]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 1) self.assertEquals(stdout.getvalue(), "") self.assertEquals(stderr.getvalue().split(), ["404", "Not", "Found"]) stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(["head", self.obj + "2", "--ignore-404"]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), "") self.assertEquals(stderr.getvalue(), "")
def test_delete_recursive(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['delete', self.container]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 1) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue().split(), ['409', 'Conflict']) stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['delete', self.container, '--recursive']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue(), '')
def test_get_account_full(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['get', '-f']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) match = None for line in stdout.getvalue().split('\n'): if self.container in line: match = line break self.assertTrue(match) stdout = match.split() self.assertEquals(len(stdout), 3) int(stdout[0]) int(stdout[1]) self.assertEquals(stdout[2], self.container) self.assertEquals(stderr.getvalue(), '')
def setUp(self): self.uuid = uuid4().hex self.container = "swiftly_test_" + self.uuid self.obj = "swiftly_test_" + self.uuid + "/test" stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(["put", self.container]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() stdin = StringIO("testvalue") stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(["put", self.obj]) cli = CLI(args=args, stdin=stdin, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0)
def setUp(self): self.uuid = uuid4().hex self.container = 'swiftly_test_' + self.uuid self.obj = 'swiftly_test_' + self.uuid + '/test' stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['put', self.container]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() stdin = StringIO('testvalue') stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['put', self.obj]) cli = CLI(args=args, stdin=stdin, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0)
def test_head_obj_ignore_404(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['head', self.obj + '2']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 1) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue().split(), ['404', 'Not', 'Found']) stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['head', self.obj + '2', '--ignore-404']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue(), '')
def test_head_obj(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['head', self.obj]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = \ dict(x.split(':', 1) for x in stdout.getvalue().split('\n') if x) self.assertEquals(sorted(stdout.keys()), [ 'Content-Length', 'Content-Type', 'Etag', 'Last-Modified', 'X-Timestamp' ]) self.assertEquals(stdout['Content-Length'].strip(), '9') self.assertEquals(stdout['Content-Type'].strip(), 'application/octet-stream') self.assertEquals(stdout['Etag'].strip(), 'e9de89b0a5e9ad6efd5e5ab543ec617c') self.assertEquals(stderr.getvalue(), '')
def test_delete_ignore_404(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['delete', self.container + '/test2', '--ignore-404']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue(), '') stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['delete', self.container + '2', '--ignore-404']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue(), '') stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['delete', self.container, '--ignore-404']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 1) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue().split(), ['409', 'Conflict']) stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['delete', '--ignore-404']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 1) self.assertEquals(stdout.getvalue(), '') self.assertTrue('THERE IS NO GOING BACK' in stderr.getvalue())
def test_get_obj_ignore_404(self): stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['get', self.obj + '2']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 1) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue().split(), ['404', 'Not', 'Found']) stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['get', self.obj + '2', '--ignore-404']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue(), '')
def test_post_account(self): uuid = uuid4().hex stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend( ['post', '-h', 'x-account-meta-swiftly-test-%s:one' % uuid]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue(), '') stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['head']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = \ dict(x.split(':', 1) for x in stdout.getvalue().split('\n') if x) self.assertTrue('X-Account-Bytes-Used' in stdout) self.assertTrue('X-Account-Container-Count' in stdout) self.assertTrue('X-Account-Object-Count' in stdout) self.assertTrue(('X-Account-Meta-Swiftly-Test-%s' % uuid).title() in stdout) self.assertEquals(stderr.getvalue(), '') stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['post', '-h', 'x-account-meta-swiftly-test-%s:' % uuid]) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) self.assertEquals(stdout.getvalue(), '') self.assertEquals(stderr.getvalue(), '') stdout = StringIO() stderr = StringIO() args = list(self.start_args) args.extend(['head']) cli = CLI(args=args, stdout=stdout, stderr=stderr) rv = cli.main() self.assertEquals(rv, 0) stdout = \ dict(x.split(':', 1) for x in stdout.getvalue().split('\n') if x) self.assertTrue('X-Account-Bytes-Used' in stdout) self.assertTrue('X-Account-Container-Count' in stdout) self.assertTrue('X-Account-Object-Count' in stdout) self.assertTrue(('X-Account-Meta-Swiftly-Test-%s' % uuid).title() not in stdout) self.assertEquals(stderr.getvalue(), '')