Beispiel #1
0
class TestAccountClient(unittest.TestCase):

    def setUp(self):
        self.client = Client(AUTH_URL, AUTH_USER, AUTH_KEY, retries=1)

    def test_head(self):
        status, reason, headers, contents = self.client.head_account()
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertTrue('x-account-bytes-used' in headers)
        self.assertTrue(isinstance(contents, str))

    def test_get(self):
        uuid = uuid4().hex
        try:
            status, reason, headers, contents = \
                self.client.put_container('swiftly_test_' + uuid)
            self.assertTrue(status // 100 == 2)
            status, reason, headers, contents = \
                self.client.get_account(prefix='swiftly_test_' + uuid)
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertTrue(int(headers['x-account-container-count']) > 0)
            self.assertTrue(isinstance(contents, list))
            found = False
            for c in contents:
                if c['name'] == 'swiftly_test_' + uuid:
                    found = True
                    break
            self.assertTrue(found)
        finally:
            self.client.delete_container('swiftly_test_' + uuid)

    def test_post(self):
        uuid = uuid4().hex
        try:
            status, reason, headers, contents = self.client.post_account(
                headers={'x-account-meta-swiftly-test-' + uuid: '123456789'})
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertTrue(isinstance(headers, dict))
            self.assertTrue(isinstance(contents, str))
            status, reason, headers, contents = self.client.head_account()
            self.assertTrue(status // 100 == 2)
            self.assertEquals(headers['x-account-meta-swiftly-test-' + uuid],
                              '123456789')
            status, reason, headers, contents = self.client.post_account(
                headers={'x-account-meta-swiftly-test-' + uuid: ''})
            self.assertTrue(status // 100 == 2)
            status, reason, headers, contents = self.client.head_account()
            self.assertTrue(status // 100 == 2)
            self.assertTrue(
                'x-account-meta-swiftly-test-' + uuid not in headers)
        finally:
            status, reason, headers, contents = self.client.post_account(
                headers={'x-account-meta-swiftly-test-' + uuid: ''})
class TestAccountClient(unittest.TestCase):
    def setUp(self):
        self.client = Client(AUTH_URL, AUTH_USER, AUTH_KEY, retries=1)

    def test_head(self):
        status, reason, headers, contents = self.client.head_account()
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertTrue('x-account-bytes-used' in headers)
        self.assertTrue(isinstance(contents, str))

    def test_get(self):
        uuid = uuid4().hex
        try:
            status, reason, headers, contents = \
                self.client.put_container('swiftly_test_' + uuid)
            self.assertTrue(status // 100 == 2)
            status, reason, headers, contents = \
                self.client.get_account(prefix='swiftly_test_' + uuid)
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertTrue(int(headers['x-account-container-count']) > 0)
            self.assertTrue(isinstance(contents, list))
            found = False
            for c in contents:
                if c['name'] == 'swiftly_test_' + uuid:
                    found = True
                    break
            self.assertTrue(found)
        finally:
            self.client.delete_container('swiftly_test_' + uuid)

    def test_post(self):
        uuid = uuid4().hex
        try:
            status, reason, headers, contents = self.client.post_account(
                headers={'x-account-meta-swiftly-test-' + uuid: '123456789'})
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertTrue(isinstance(headers, dict))
            self.assertTrue(isinstance(contents, str))
            status, reason, headers, contents = self.client.head_account()
            self.assertTrue(status // 100 == 2)
            self.assertEquals(headers['x-account-meta-swiftly-test-' + uuid],
                              '123456789')
            status, reason, headers, contents = self.client.post_account(
                headers={'x-account-meta-swiftly-test-' + uuid: ''})
            self.assertTrue(status // 100 == 2)
            status, reason, headers, contents = self.client.head_account()
            self.assertTrue(status // 100 == 2)
            self.assertTrue('x-account-meta-swiftly-test-' +
                            uuid not in headers)
        finally:
            status, reason, headers, contents = self.client.post_account(
                headers={'x-account-meta-swiftly-test-' + uuid: ''})
Beispiel #3
0
class TestContainerDirect(TestContainerClient):

    def setUp(self):
        if Application is None:
            raise SkipTest
        self.client = Client(retries=1, swift_proxy=True,
                             swift_proxy_storage_path=SWIFT_PROXY_STORAGE_PATH)
        self.uuid = uuid4().hex
        self.container = 'swiftly_test_' + self.uuid
        status = self.client.put_container(self.container)[0]
        self.assertTrue(status // 100 == 2)
class TestObjectClient(unittest.TestCase):

    def setUp(self):
        self.client = Client(AUTH_URL, AUTH_USER, AUTH_KEY)
        self.uuid = uuid4().hex
        self.container = 'swiftly_test_' + self.uuid
        status = self.client.put_container(self.container)[0]
        self.assertTrue(status // 100 == 2)
        status = \
            self.client.put_object(self.container, 'object1', '123456789')[0]
        self.assertTrue(status // 100 == 2)

    def tearDown(self):
        self.client.delete_object(self.container, 'object1')
        self.client.delete_container(self.container)

    def test_head(self):
        status, reason, headers, contents = \
            self.client.head_object(self.container, 'object1')
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertEquals(headers['etag'], '25f9e794323b453885f5181f1b624d0b')
        self.assertTrue(isinstance(contents, str))

    def test_get(self):
        status, reason, headers, contents = \
            self.client.get_object(self.container, 'object1')
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertEquals(headers['etag'], '25f9e794323b453885f5181f1b624d0b')
        self.assertTrue(contents.read(), '123456789')

    def test_get_no_stream(self):
        status, reason, headers, contents = \
            self.client.get_object(self.container, 'object1', stream=False)
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertEquals(headers['etag'], '25f9e794323b453885f5181f1b624d0b')
        self.assertTrue(contents, '123456789')

    def test_put(self):
        try:
            status, reason, headers, contents = self.client.put_object(
                self.container, 'object2', 'contentvalue',
                headers={'x-object-meta-swiftly-test': 'somevalue'})
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertTrue(isinstance(headers, dict))
            self.assertTrue(isinstance(contents, str))
            status, reason, headers, contents = \
                self.client.get_object(self.container, 'object2')
            self.assertTrue(status // 100 == 2)
            self.assertEquals(
                headers['etag'], '11a49846cb4877d7f9bb9471b646464f')
            self.assertEquals(
                headers['x-object-meta-swiftly-test'], 'somevalue')
            self.assertEquals(contents.read(), 'contentvalue')
        finally:
            self.client.delete_object(self.container, 'object2')

    def test_put_with_etag(self):
        try:
            status, reason, headers, contents = self.client.put_object(
                self.container, 'object2', 'contentvalue',
                headers={'x-object-meta-swiftly-test': 'somevalue',
                         'etag': '11111111111111111111111111111111'})
            self.assertEquals(status, 422)
            status, reason, headers, contents = self.client.put_object(
                self.container, 'object2', 'contentvalue',
                headers={'x-object-meta-swiftly-test': 'somevalue',
                         'etag': '11a49846cb4877d7f9bb9471b646464f'})
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertTrue(isinstance(headers, dict))
            self.assertTrue(isinstance(contents, str))
            status, reason, headers, contents = \
                self.client.get_object(self.container, 'object2')
            self.assertTrue(status // 100 == 2)
            self.assertEquals(
                headers['etag'], '11a49846cb4877d7f9bb9471b646464f')
            self.assertEquals(
                headers['x-object-meta-swiftly-test'], 'somevalue')
            self.assertEquals(contents.read(), 'contentvalue')
        finally:
            self.client.delete_object(self.container, 'object2')

    def test_put_as_stream(self):
        try:
            status, reason, headers, contents = self.client.put_object(
                self.container, 'object2', StringIO('contentvalue'),
                headers={'content-length': '12',
                         'x-object-meta-swiftly-test': 'somevalue'})
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertTrue(isinstance(headers, dict))
            self.assertTrue(isinstance(contents, str))
            status, reason, headers, contents = \
                self.client.get_object(self.container, 'object2')
            self.assertTrue(status // 100 == 2)
            self.assertEquals(
                headers['etag'], '11a49846cb4877d7f9bb9471b646464f')
            self.assertEquals(
                headers['x-object-meta-swiftly-test'], 'somevalue')
            self.assertEquals(contents.read(), 'contentvalue')
        finally:
            self.client.delete_object(self.container, 'object2')

    def test_put_as_stream_chunked(self):
        try:
            status, reason, headers, contents = self.client.put_object(
                self.container, 'object2', StringIO('contentvalue'),
                headers={'x-object-meta-swiftly-test': 'somevalue'})
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertTrue(isinstance(headers, dict))
            self.assertTrue(isinstance(contents, str))
            status, reason, headers, contents = \
                self.client.get_object(self.container, 'object2')
            self.assertTrue(status // 100 == 2)
            self.assertEquals(
                headers['etag'], '11a49846cb4877d7f9bb9471b646464f')
            self.assertEquals(
                headers['x-object-meta-swiftly-test'], 'somevalue')
            self.assertEquals(contents.read(), 'contentvalue')
        finally:
            self.client.delete_object(self.container, 'object2')

    def test_post(self):
        status, reason, headers, contents = \
            self.client.head_object(self.container, 'object1')
        self.assertTrue(status // 100 == 2)
        self.assertTrue('x-object-meta-swiftly-test' not in headers)
        status, reason, headers, contents = self.client.post_object(
            self.container, 'object1',
            headers={'x-object-meta-swiftly-test': 'testvalue'})
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertTrue(isinstance(headers, dict))
        self.assertTrue(isinstance(contents, str))
        status, reason, headers, contents = \
            self.client.head_object(self.container, 'object1')
        self.assertTrue(status // 100 == 2)
        self.assertEquals(headers['x-object-meta-swiftly-test'], 'testvalue')

    def test_delete(self):
        status = self.client.head_object(self.container, 'object1')[0]
        self.assertTrue(status // 100 == 2)
        status, reason, headers, contents = \
            self.client.delete_object(self.container, 'object1')
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertTrue(isinstance(headers, dict))
        self.assertTrue(isinstance(contents, str))
        status = self.client.head_object(self.container, 'object1')[0]
        self.assertEquals(status, 404)
Beispiel #5
0
class TestContainerClient(unittest.TestCase):

    def setUp(self):
        self.client = Client(AUTH_URL, AUTH_USER, AUTH_KEY)
        self.uuid = uuid4().hex
        self.container = 'swiftly_test_' + self.uuid
        status = self.client.put_container(self.container)[0]
        self.assertTrue(status // 100 == 2)

    def tearDown(self):
        self.client.delete_container(self.container)

    def test_head(self):
        status, reason, headers, contents = \
            self.client.head_container(self.container)
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertTrue('x-container-bytes-used' in headers)
        self.assertTrue(isinstance(contents, str))

    def test_get(self):
        try:
            status, reason, headers, contents = \
                self.client.put_object(self.container, 'object1', 'testvalue')
            self.assertTrue(status // 100 == 2)
            status, reason, headers, contents = \
                self.client.get_container(self.container)
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertEquals(int(headers['x-container-object-count']), 1)
            self.assertTrue(isinstance(contents, list))
            found = False
            for c in contents:
                if c['name'] == 'object1':
                    found = True
                    break
            self.assertTrue(found)
        finally:
            self.client.delete_object(self.container, 'object1')

    def test_put(self):
        status, reason, headers, contents = self.client.put_container(
            self.container,
            headers={'x-container-meta-swiftly-test': '123456789'})
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertTrue(isinstance(headers, dict))
        self.assertTrue(isinstance(contents, str))
        status, reason, headers, contents = \
            self.client.head_container(self.container)
        self.assertTrue(status // 100 == 2)
        self.assertEquals(
            headers['x-container-meta-swiftly-test'], '123456789')
        status, reason, headers, contents = self.client.put_container(
            self.container, headers={'x-container-meta-swiftly-test': ''})
        self.assertTrue(status // 100 == 2)
        status, reason, headers, contents = \
            self.client.head_container(self.container)
        self.assertTrue(status // 100 == 2)
        self.assertTrue('x-container-meta-swiftly-test' not in headers)

    def test_post(self):
        status, reason, headers, contents = self.client.post_container(
            self.container,
            headers={'x-container-meta-swiftly-test': '123456789'})
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertTrue(isinstance(headers, dict))
        self.assertTrue(isinstance(contents, str))
        status, reason, headers, contents = \
            self.client.head_container(self.container)
        self.assertTrue(status // 100 == 2)
        self.assertEquals(
            headers['x-container-meta-swiftly-test'], '123456789')
        status, reason, headers, contents = self.client.post_container(
            self.container, headers={'x-container-meta-swiftly-test': ''})
        self.assertTrue(status // 100 == 2)
        status, reason, headers, contents = \
            self.client.head_container(self.container)
        self.assertTrue(status // 100 == 2)
        self.assertTrue('x-container-meta-swiftly-test' not in headers)

    def test_delete(self):
        status = self.client.head_container(self.container)[0]
        self.assertTrue(status // 100 == 2)
        status, reason, headers, contents = \
            self.client.delete_container(self.container)
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertTrue(isinstance(headers, dict))
        self.assertTrue(isinstance(contents, str))
        status = self.client.head_container(self.container)[0]
        self.assertEquals(status, 404)
Beispiel #6
0
class TestObjectClient(unittest.TestCase):
    def setUp(self):
        self.client = Client(AUTH_URL, AUTH_USER, AUTH_KEY)
        self.uuid = uuid4().hex
        self.container = 'swiftly_test_' + self.uuid
        status = self.client.put_container(self.container)[0]
        self.assertTrue(status // 100 == 2)
        status = \
            self.client.put_object(self.container, 'object1', '123456789')[0]
        self.assertTrue(status // 100 == 2)

    def tearDown(self):
        self.client.delete_object(self.container, 'object1')
        self.client.delete_container(self.container)

    def test_head(self):
        status, reason, headers, contents = \
            self.client.head_object(self.container, 'object1')
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertEquals(headers['etag'], '25f9e794323b453885f5181f1b624d0b')
        self.assertTrue(isinstance(contents, str))

    def test_get(self):
        status, reason, headers, contents = \
            self.client.get_object(self.container, 'object1')
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertEquals(headers['etag'], '25f9e794323b453885f5181f1b624d0b')
        self.assertTrue(contents.read(), '123456789')

    def test_get_no_stream(self):
        status, reason, headers, contents = \
            self.client.get_object(self.container, 'object1', stream=False)
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertEquals(headers['etag'], '25f9e794323b453885f5181f1b624d0b')
        self.assertTrue(contents, '123456789')

    def test_put(self):
        try:
            status, reason, headers, contents = self.client.put_object(
                self.container,
                'object2',
                'contentvalue',
                headers={'x-object-meta-swiftly-test': 'somevalue'})
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertTrue(isinstance(headers, dict))
            self.assertTrue(isinstance(contents, str))
            status, reason, headers, contents = \
                self.client.get_object(self.container, 'object2')
            self.assertTrue(status // 100 == 2)
            self.assertEquals(headers['etag'],
                              '11a49846cb4877d7f9bb9471b646464f')
            self.assertEquals(headers['x-object-meta-swiftly-test'],
                              'somevalue')
            self.assertEquals(contents.read(), 'contentvalue')
        finally:
            self.client.delete_object(self.container, 'object2')

    def test_put_with_etag(self):
        try:
            status, reason, headers, contents = self.client.put_object(
                self.container,
                'object2',
                'contentvalue',
                headers={
                    'x-object-meta-swiftly-test': 'somevalue',
                    'etag': '11111111111111111111111111111111'
                })
            self.assertEquals(status, 422)
            status, reason, headers, contents = self.client.put_object(
                self.container,
                'object2',
                'contentvalue',
                headers={
                    'x-object-meta-swiftly-test': 'somevalue',
                    'etag': '11a49846cb4877d7f9bb9471b646464f'
                })
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertTrue(isinstance(headers, dict))
            self.assertTrue(isinstance(contents, str))
            status, reason, headers, contents = \
                self.client.get_object(self.container, 'object2')
            self.assertTrue(status // 100 == 2)
            self.assertEquals(headers['etag'],
                              '11a49846cb4877d7f9bb9471b646464f')
            self.assertEquals(headers['x-object-meta-swiftly-test'],
                              'somevalue')
            self.assertEquals(contents.read(), 'contentvalue')
        finally:
            self.client.delete_object(self.container, 'object2')

    def test_put_as_stream(self):
        try:
            status, reason, headers, contents = self.client.put_object(
                self.container,
                'object2',
                StringIO('contentvalue'),
                headers={
                    'content-length': '12',
                    'x-object-meta-swiftly-test': 'somevalue'
                })
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertTrue(isinstance(headers, dict))
            self.assertTrue(isinstance(contents, str))
            status, reason, headers, contents = \
                self.client.get_object(self.container, 'object2')
            self.assertTrue(status // 100 == 2)
            self.assertEquals(headers['etag'],
                              '11a49846cb4877d7f9bb9471b646464f')
            self.assertEquals(headers['x-object-meta-swiftly-test'],
                              'somevalue')
            self.assertEquals(contents.read(), 'contentvalue')
        finally:
            self.client.delete_object(self.container, 'object2')

    def test_put_as_stream_chunked(self):
        try:
            status, reason, headers, contents = self.client.put_object(
                self.container,
                'object2',
                StringIO('contentvalue'),
                headers={'x-object-meta-swiftly-test': 'somevalue'})
            self.assertTrue(status // 100 == 2)
            self.assertTrue(isinstance(reason, str))
            self.assertTrue(isinstance(headers, dict))
            self.assertTrue(isinstance(contents, str))
            status, reason, headers, contents = \
                self.client.get_object(self.container, 'object2')
            self.assertTrue(status // 100 == 2)
            self.assertEquals(headers['etag'],
                              '11a49846cb4877d7f9bb9471b646464f')
            self.assertEquals(headers['x-object-meta-swiftly-test'],
                              'somevalue')
            self.assertEquals(contents.read(), 'contentvalue')
        finally:
            self.client.delete_object(self.container, 'object2')

    def test_post(self):
        status, reason, headers, contents = \
            self.client.head_object(self.container, 'object1')
        self.assertTrue(status // 100 == 2)
        self.assertTrue('x-object-meta-swiftly-test' not in headers)
        status, reason, headers, contents = self.client.post_object(
            self.container,
            'object1',
            headers={'x-object-meta-swiftly-test': 'testvalue'})
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertTrue(isinstance(headers, dict))
        self.assertTrue(isinstance(contents, str))
        status, reason, headers, contents = \
            self.client.head_object(self.container, 'object1')
        self.assertTrue(status // 100 == 2)
        self.assertEquals(headers['x-object-meta-swiftly-test'], 'testvalue')

    def test_delete(self):
        status = self.client.head_object(self.container, 'object1')[0]
        self.assertTrue(status // 100 == 2)
        status, reason, headers, contents = \
            self.client.delete_object(self.container, 'object1')
        self.assertTrue(status // 100 == 2)
        self.assertTrue(isinstance(reason, str))
        self.assertTrue(isinstance(headers, dict))
        self.assertTrue(isinstance(contents, str))
        status = self.client.head_object(self.container, 'object1')[0]
        self.assertEquals(status, 404)