]> git-server-git.apps.pok.os.sepia.ceph.com Git - radosgw-agent.git/commitdiff
Merge remote-tracking branch 'origin/wip-10015' into wip-boto wip-testing
authorJosh Durgin <jdurgin@redhat.com>
Sat, 6 Dec 2014 05:20:03 +0000 (21:20 -0800)
committerJosh Durgin <jdurgin@redhat.com>
Sat, 6 Dec 2014 05:20:03 +0000 (21:20 -0800)
Conflicts:
radosgw_agent/tests/test_client.py

1  2 
radosgw_agent/client.py
radosgw_agent/tests/test_client.py

Simple merge
index d3d331106996d70767f5d146f1f4bbd81765adc9,73a1b95b3c3a2b0db48e8440c26fb6f130337a8b..2d025c65c78da5896994bf141a9f7bb69fffcd69
@@@ -1,6 -1,7 +1,8 @@@
 +import boto
  import py.test
  from mock import Mock
+ import httpretty
+ import re
  
  from radosgw_agent import client
  
@@@ -330,50 -331,95 +332,119 @@@ def http_valid_status_codes()
          200, 201, 202, 203, 204, 205, 207, 208, 226,
      ]
  
- class TestCheckResultStatus(object):
-     @py.test.mark.parametrize('code', http_invalid_status_codes())
-     def test_check_raises_http_error(self, code):
-         response = Mock()
-         response.status_code = code
-         with py.test.raises(client.HttpError):
-             client.check_result_status(response)
-     @py.test.mark.parametrize('code', http_valid_status_codes())
-     def test_check_does_not_raise_http_error(self, code):
-         response = Mock()
-         response.status_code = code
-         assert client.check_result_status(response) is None
-     def test_check_raises_not_found(self):
-         response = Mock()
-         response.status_code = 404
-         with py.test.raises(client.NotFound):
-             client.check_result_status(response)
 +class TestBotoCall(object):
 +
 +    def test_return_val(self):
 +        @client.boto_call
 +        def foo(*args, **kwargs):
 +            return (args, kwargs)
 +        assert foo(1) == ((1,), {})
 +        assert foo(b=2) == (tuple(), {'b': 2})
 +
 +    def test_boto_exception_not_found(self):
 +        @client.boto_call
 +        def foo():
 +            raise boto.exception.S3ResponseError(404, '')
 +
 +        with py.test.raises(client.NotFound):
 +            foo()
 +
 +    def test_non_boto_exception(self):
 +        @client.boto_call
 +        def foo():
 +            raise ValueError('')
 +
 +        with py.test.raises(ValueError):
 +            foo()
++
+ class TestCheckResultStatus(object):
+     @py.test.mark.parametrize('code', http_invalid_status_codes())
+     def test_check_raises_http_error(self, code):
+         response = Mock()
+         response.status = code
+         with py.test.raises(client.HttpError):
+             client.check_result_status(response)
+     @py.test.mark.parametrize('code', http_valid_status_codes())
+     def test_check_does_not_raise_http_error(self, code):
+         response = Mock()
+         response.status = code
+         assert client.check_result_status(response) is None
+     def test_check_raises_not_found(self):
+         response = Mock()
+         response.status = 404
+         with py.test.raises(client.NotFound):
+             client.check_result_status(response)
 -
+ class TestRequest(object):
+     @httpretty.activate
+     def test_url(self):
+         httpretty.register_uri(
+             httpretty.GET,
+             re.compile("http://localhost:8888/(.*)"),
+             body='{}',
+             content_type="application/json",
+         )
+         connection = client.S3Connection(
+             aws_access_key_id='key',
+             aws_secret_access_key='secret',
+             is_secure=False,
+             host='localhost',
+             port=8888,
+             calling_format=client.boto.s3.connection.OrdinaryCallingFormat(),
+             debug=True,
+         )
+         client.request(connection, 'get', '/%7E~', _retries=0)
+         server_request = httpretty.last_request()
+         assert server_request.path == '/%257E%7E'
+     @httpretty.activate
+     def test_url_response(self):
+         httpretty.register_uri(
+             httpretty.GET,
+             re.compile("http://localhost:8888/(.*)"),
+             body='{"msg": "ok"}',
+             content_type="application/json",
+         )
+         connection = client.S3Connection(
+             aws_access_key_id='key',
+             aws_secret_access_key='secret',
+             is_secure=False,
+             host='localhost',
+             port=8888,
+             calling_format=client.boto.s3.connection.OrdinaryCallingFormat(),
+             debug=True,
+         )
+         result = client.request(connection, 'get', '/%7E~', _retries=0)
+         assert result == {'msg': 'ok'}
+     @httpretty.activate
+     def test_url_bad(self):
+         httpretty.register_uri(
+             httpretty.GET,
+             re.compile("http://localhost:8888/(.*)"),
+             body='{}',
+             content_type="application/json",
+             status=500,
+         )
+         connection = client.S3Connection(
+             aws_access_key_id='key',
+             aws_secret_access_key='secret',
+             is_secure=False,
+             host='localhost',
+             port=8888,
+             calling_format=client.boto.s3.connection.OrdinaryCallingFormat(),
+             debug=True,
+         )
+         with py.test.raises(client.HttpError):
+             client.request(connection, 'get', '/%7E~', _retries=0)