~ubuntu-branches/ubuntu/vivid/swift/vivid

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): James Page, Chuck Short, James Page
  • Date: 2014-12-19 14:33:19 UTC
  • mfrom: (1.2.34)
  • Revision ID: package-import@ubuntu.com-20141219143319-kbs2wk1dixt2aoqq
Tags: 2.2.1-0ubuntu1
[ Chuck Short ]
* Open for Vivid.
* d/control: Update branch locations.

[ James Page ]
* New upstream release:
  - d/p/*: Refresh.
* d/control: Bumped Standards-Version 3.9.6, no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import cPickle as pickle
20
20
import datetime
 
21
import errno
21
22
import operator
22
23
import os
23
24
import mock
551
552
            '/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
552
553
            headers={'X-Timestamp': timestamp,
553
554
                     'Content-Length': '6',
554
 
                     'Content-Type': 'application/octet-stream'})
 
555
                     'Content-Type': 'application/octet-stream',
 
556
                     'x-object-meta-test': 'one',
 
557
                     'Custom-Header': '*',
 
558
                     'X-Backend-Replication-Headers':
 
559
                     'Content-Type Content-Length'})
555
560
        req.body = 'VERIFY'
556
 
        resp = req.get_response(self.object_controller)
 
561
        with mock.patch.object(self.object_controller, 'allowed_headers',
 
562
                               ['Custom-Header']):
 
563
            self.object_controller.allowed_headers = ['Custom-Header']
 
564
            resp = req.get_response(self.object_controller)
 
565
 
557
566
        self.assertEquals(resp.status_int, 201)
558
567
        objfile = os.path.join(
559
568
            self.testdir, 'sda1',
567
576
                           'Content-Length': '6',
568
577
                           'ETag': '0b4c12d7e0a73840c1c4f148fda3b037',
569
578
                           'Content-Type': 'application/octet-stream',
570
 
                           'name': '/a/c/o'})
 
579
                           'name': '/a/c/o',
 
580
                           'X-Object-Meta-Test': 'one',
 
581
                           'Custom-Header': '*'})
571
582
 
572
583
    def test_PUT_overwrite(self):
573
584
        req = Request.blank(
716
727
                           'X-Object-Meta-1': 'One',
717
728
                           'X-Object-Meta-Two': 'Two'})
718
729
 
 
730
    def test_PUT_user_metadata_no_xattr(self):
 
731
        timestamp = normalize_timestamp(time())
 
732
        req = Request.blank(
 
733
            '/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
 
734
            headers={'X-Timestamp': timestamp,
 
735
                     'Content-Type': 'text/plain',
 
736
                     'ETag': 'b114ab7b90d9ccac4bd5d99cc7ebb568',
 
737
                     'X-Object-Meta-1': 'One',
 
738
                     'X-Object-Meta-Two': 'Two'})
 
739
        req.body = 'VERIFY THREE'
 
740
 
 
741
        def mock_get_and_setxattr(*args, **kargs):
 
742
            error_num = errno.ENOTSUP if hasattr(errno, 'ENOTSUP') else \
 
743
                errno.EOPNOTSUPP
 
744
            raise IOError(error_num, 'Operation not supported')
 
745
 
 
746
        with mock.patch('xattr.getxattr', mock_get_and_setxattr):
 
747
            with mock.patch('xattr.setxattr', mock_get_and_setxattr):
 
748
                resp = req.get_response(self.object_controller)
 
749
                self.assertEquals(resp.status_int, 507)
 
750
 
719
751
    def test_PUT_client_timeout(self):
720
752
        class FakeTimeout(BaseException):
721
753
            def __enter__(self):
1303
1335
        req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
1304
1336
                            headers={
1305
1337
                                'X-Timestamp': normalize_timestamp(time()),
1306
 
                                'Content-Type': 'application/octet-stream',
 
1338
                                'X-Object-Meta-Soup': 'gazpacho',
 
1339
                                'Content-Type': 'application/fizzbuzz',
1307
1340
                                'Content-Length': '4'})
1308
1341
        req.body = 'test'
1309
1342
        resp = req.get_response(self.object_controller)
1320
1353
        resp = req.get_response(self.object_controller)
1321
1354
        self.assertEquals(resp.status_int, 304)
1322
1355
        self.assertEquals(resp.etag, etag)
 
1356
        self.assertEquals(resp.headers['Content-Type'], 'application/fizzbuzz')
 
1357
        self.assertEquals(resp.headers['X-Object-Meta-Soup'], 'gazpacho')
1323
1358
 
1324
1359
        req = Request.blank('/sda1/p/a/c/o2',
1325
1360
                            environ={'REQUEST_METHOD': 'GET'},
1547
1582
        req = Request.blank('/sda1/p/a/c/o', environ={'REQUEST_METHOD': 'PUT'},
1548
1583
                            headers={
1549
1584
                                'X-Timestamp': timestamp,
1550
 
                                'Content-Type': 'application/octet-stream',
 
1585
                                'X-Object-Meta-Burr': 'ito',
 
1586
                                'Content-Type': 'application/cat-picture',
1551
1587
                                'Content-Length': '4'})
1552
1588
        req.body = 'test'
1553
1589
        resp = req.get_response(self.object_controller)
1570
1606
                            headers={'If-Unmodified-Since': since})
1571
1607
        resp = req.get_response(self.object_controller)
1572
1608
        self.assertEquals(resp.status_int, 412)
 
1609
        self.assertEquals(resp.headers['Content-Type'],
 
1610
                          'application/cat-picture')
 
1611
        self.assertEquals(resp.headers['X-Object-Meta-Burr'], 'ito')
1573
1612
 
1574
1613
        since = \
1575
1614
            strftime('%a, %d %b %Y %H:%M:%S GMT', gmtime(float(timestamp) + 9))
4414
4453
        self.wsgi_greenlet = spawn(
4415
4454
            wsgi.server, listener, self.object_controller, NullLogger())
4416
4455
 
4417
 
        self.http_conn = httplib.HTTPConnection('localhost', port)
 
4456
        self.http_conn = httplib.HTTPConnection('127.0.0.1', port)
4418
4457
        self.http_conn.connect()
4419
4458
 
4420
4459
    def tearDown(self):