예제 #1
0
    def test_get_object_chunked(self):
        chunk_size = 10
        # stub request validators
        auth_validator = lambda *args: None

        def get_object_validator(method, path, body, headers):
            self.assertEquals(method, 'GET')
            self.assertEquals(path, '/vol1/chunk1')
            self.assertEquals(body, '')

        self.validators = [lambda *args: None, get_object_validator]
        # stub mock responses
        full_body = ('a' * chunk_size) + ('b' * chunk_size)
        get_response = MockResponse(body=full_body)
        self.responses = [_stub_auth_response(), get_response]
        # create connection
        c = swift.Connection('http://localauth.com/auth1/', 'user', 'key',
                             'USA')
        # request object get
        headers, body = c.get_object('vol1',
                                     'chunk1',
                                     resp_chunk_size=chunk_size)
        # verify validators called and responses consumed
        self.assert_(get_object_validator.called)
        self.assert_(get_response.consumed)
        # body should be iterable
        first_chunk = body.next()
        self.assertEquals(first_chunk, 'a' * 10)
        second_chunk = body.next()
        self.assertEquals(second_chunk, 'b' * 10)
        self.assertRaises(StopIteration, body.next)
        self.assertEquals(full_body, first_chunk + second_chunk)
예제 #2
0
 def setUp(self):
     self.conn = swift.Connection('http:/localauth.com/auth1/',
                                  'user',
                                  'key',
                                  'USA',
                                  retries=5)
     self.conn.get_auth = lambda: (None, None)
     self.conn.http_connection = lambda: None
예제 #3
0
    def test_valid_auth(self):
        # stub request validators
        auth_validator = lambda *args: None

        def get_object_validator(method, path, body, headers):
            self.assertEquals(method, 'GET')
            self.assertEquals(path, '/vol1/block')
            self.assertEquals(body, '')
        self.validators = [lambda *args: None, get_object_validator]
        full_body = 'the body'
        get_response = MockResponse(body=full_body)
        self.responses = [_stub_auth_response(), get_response]
        c = swift.Connection(
            'http://localauth.com/auth1/', 'user', 'key', 'USA')
        headers, body = c.get_object('vol1', 'block')
        self.assert_(get_object_validator.called)
        self.assert_(get_response.consumed)
        self.assertEquals(body, full_body)
예제 #4
0
    def test_bad_service_auth(self):
        error_message = 'Service Type object-store not found'
        # stub request validators
        auth_validator = lambda *args: None

        def get_object_validator(method, path, body, headers):
            self.assertEquals(method, 'GET')
            self.assertEquals(path, '/vol1/block')
            self.assertEquals(body, '')
        self.validators = [lambda *args: None, get_object_validator]
        full_body = 'the body'
        get_response = MockResponse(body=full_body)
        self.responses = [_bad_service_auth_response(), get_response]
        try:
            c = swift.Connection(
                'http://localauth.com/auth1/', 'user', 'key', 'USA')
            headers, body = c.get_object('vol1', 'block')
        except swift.ClientException as e:
            self.assertEqual(e.msg, error_message)
예제 #5
0
    def test_get_object_non_chunked(self):
        # stub request validators
        auth_validator = lambda *args: None

        def get_object_validator(method, path, body, headers):
            self.assertEquals(method, 'GET')
            self.assertEquals(path, '/vol1/chunk1')
            self.assertEquals(body, '')
        self.validators = [lambda *args: None, get_object_validator]
        # stub mock responses
        full_body = 'full chunk 1 body'
        get_response = MockResponse(body=full_body)
        self.responses = [_stub_auth_response(), get_response]
        # create connection
        c = swift.Connection(
            'http://localauth.com/auth1/', 'user', 'key', 'USA')
        # request object get
        headers, body = c.get_object('vol1', 'chunk1')
        # verify validators called and responses consumed
        self.assert_(get_object_validator.called)
        self.assert_(get_response.consumed)
        # body should be string
        self.assertEquals(body, full_body)