~notmyname/swift/stats_mapper

« back to all changes in this revision

Viewing changes to test/unit/proxy/test_server.py

  • Committer: Tarmac
  • Author(s): Clay Gerrard, John Dickinson, gholt
  • Date: 2010-11-05 15:57:20 UTC
  • mfrom: (108.3.5 copy_auth)
  • Revision ID: hudson@openstack.org-20101105155720-bx7i73nrt4r4umgg
fixed auth_copy bug, bytes_transferred copy logging bug, and early denial for proxy.server.ObjectController.COPY method; added tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1782
1782
            self.assert_(hasattr(req, 'bytes_transferred'))
1783
1783
            self.assertEquals(req.bytes_transferred, 10)
1784
1784
 
 
1785
    def test_copy_zero_bytes_transferred_attr(self):
 
1786
        with save_globals():
 
1787
            proxy_server.http_connect = \
 
1788
                fake_http_connect(200, 200, 200, 200, 200, 201, 201, 201,
 
1789
                                  body='1234567890')
 
1790
            controller = proxy_server.ObjectController(self.app, 'account',
 
1791
                            'container', 'object')
 
1792
            req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
 
1793
                                headers={'X-Copy-From': 'c/o2',
 
1794
                                         'Content-Length': '0'})
 
1795
            self.app.update_request(req)
 
1796
            res = controller.PUT(req)
 
1797
            self.assert_(hasattr(req, 'bytes_transferred'))
 
1798
            self.assertEquals(req.bytes_transferred, 0)
 
1799
 
1785
1800
    def test_response_bytes_transferred_attr(self):
1786
1801
        with save_globals():
1787
1802
            proxy_server.http_connect = \
1904
1919
            res = controller.PUT(req)
1905
1920
        self.assert_(called[0])
1906
1921
 
 
1922
    def test_COPY_calls_authorize(self):
 
1923
        called = [False]
 
1924
 
 
1925
        def authorize(req):
 
1926
            called[0] = True
 
1927
            return HTTPUnauthorized(request=req)
 
1928
        with save_globals():
 
1929
            proxy_server.http_connect = \
 
1930
                fake_http_connect(200, 200, 200, 200, 200, 201, 201, 201)
 
1931
            controller = proxy_server.ObjectController(self.app, 'account',
 
1932
                            'container', 'object')
 
1933
            req = Request.blank('/a/c/o', environ={'REQUEST_METHOD': 'COPY'},
 
1934
                                headers={'Destination': 'c/o'})
 
1935
            req.environ['swift.authorize'] = authorize
 
1936
            self.app.update_request(req)
 
1937
            res = controller.COPY(req)
 
1938
        self.assert_(called[0])
1907
1939
 
1908
1940
class TestContainerController(unittest.TestCase):
1909
1941
    "Test swift.proxy_server.ContainerController"