Esempio n. 1
0
 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()
Esempio n. 2
0
    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(), '')
Esempio n. 3
0
 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()
Esempio n. 4
0
    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(), '')
Esempio n. 5
0
 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(), '')
Esempio n. 6
0
 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(), "")
Esempio n. 7
0
 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)
Esempio n. 8
0
 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(), "")
Esempio n. 9
0
 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)
Esempio n. 10
0
 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(), '')
Esempio n. 11
0
 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(), "")
Esempio n. 12
0
 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)
Esempio n. 13
0
 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)
Esempio n. 14
0
 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)
Esempio n. 15
0
 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)
Esempio n. 16
0
 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'])
Esempio n. 17
0
 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'])
Esempio n. 18
0
 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)
Esempio n. 19
0
 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(), "")
Esempio n. 20
0
 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(), "")
Esempio n. 21
0
 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(), '')
Esempio n. 22
0
 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(), '')
Esempio n. 23
0
 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)
Esempio n. 24
0
 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(), '')
Esempio n. 25
0
 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(), "")
Esempio n. 26
0
 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(), '')
Esempio n. 27
0
 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(), '')
Esempio n. 28
0
 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)
Esempio n. 29
0
 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(), '')
Esempio n. 30
0
 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)
Esempio n. 31
0
 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(), '')
Esempio n. 32
0
 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(), "")
Esempio n. 33
0
    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(), '')
Esempio n. 34
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(), "")
Esempio n. 35
0
    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(), '')
Esempio n. 36
0
 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(), '')
Esempio n. 37
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)
Esempio n. 38
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)
Esempio n. 39
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(), '')
Esempio n. 40
0
 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(), '')
Esempio n. 41
0
 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(), '')
Esempio n. 42
0
    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())
Esempio n. 43
0
    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(), '')
Esempio n. 44
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)
Esempio n. 45
0
    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(), '')
Esempio n. 46
0
    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())
Esempio n. 47
0
    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(), '')