Exemplo n.º 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: ''})
Exemplo n.º 2
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: ''})
Exemplo n.º 3
0
class TestAcountClientOnly(unittest.TestCase):
    def setUp(self):
        self.client = Client(AUTH_URL, AUTH_USER, AUTH_KEY, retries=1)

    def test_head_bad_auth(self):
        self.client = Client(AUTH_URL, AUTH_USER, AUTH_KEY + "invalid", retries=0)
        exc = None
        try:
            self.client.head_account()
        except HTTPException, err:
            exc = err
        self.assertTrue(exc is not None)
        self.assertEquals(
            str(exc), "Auth failure ['401 Unauthorized', '400 Bad Request', " "'400 Bad Request', '400 Bad Request']."
        )
Exemplo n.º 4
0
class TestAcountClientOnly(unittest.TestCase):

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

    def test_head_bad_auth(self):
        self.client = Client(AUTH_URL, AUTH_USER, AUTH_KEY + 'invalid',
                             retries=0)
        exc = None
        try:
            self.client.head_account()
        except HTTPException, err:
            exc = err
        self.assertTrue(exc is not None)
        self.assertEquals(exc.args[1], 401)
Exemplo n.º 5
0
class TestAcountClientOnly(unittest.TestCase):
    def setUp(self):
        self.client = Client(AUTH_URL, AUTH_USER, AUTH_KEY, retries=1)

    def test_head_bad_auth(self):
        self.client = Client(AUTH_URL,
                             AUTH_USER,
                             AUTH_KEY + 'invalid',
                             retries=0)
        exc = None
        try:
            self.client.head_account()
        except HTTPException, err:
            exc = err
        self.assertTrue(exc is not None)
        self.assertEquals(
            str(exc), "Auth failure ['401 Unauthorized', '400 Bad Request', "
            "'400 Bad Request', '400 Bad Request'].")