~gholt/swift/timeout_baseexception

« back to all changes in this revision

Viewing changes to test/unit/common/middleware/test_swift3.py

  • Committer: Tarmac
  • Author(s): Michael Barton
  • Date: 2011-03-30 20:47:28 UTC
  • mfrom: (257.2.3 noboto)
  • Revision ID: tarmac-20110330204728-lztov8h3yjvnt64f
Remove boto dependency by implementing request canonicalization logic in swift3 middleware.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
import unittest
17
17
from datetime import datetime
18
18
import cgi
 
19
import hashlib
19
20
 
20
21
from webob import Request, Response
21
22
from webob.exc import HTTPUnauthorized, HTTPCreated, HTTPNoContent,\
22
23
     HTTPAccepted, HTTPBadRequest, HTTPNotFound, HTTPConflict
23
24
import xml.dom.minidom
24
25
import simplejson
25
 
from nose.plugins.skip import SkipTest
26
 
 
27
 
try:
28
 
    from swift.common.middleware import swift3
29
 
    skip = False
30
 
except Exception:
31
 
    # Skip the swift3 tests if boto is not installed 
32
 
    skip = True
 
26
 
 
27
from swift.common.middleware import swift3
 
28
 
33
29
 
34
30
class FakeApp(object):
35
31
    def __init__(self):
195
191
 
196
192
class TestSwift3(unittest.TestCase):
197
193
    def setUp(self):
198
 
        if skip:
199
 
            raise SkipTest
200
194
        self.app = swift3.filter_factory({})(FakeApp())
201
195
 
202
196
    def test_non_s3_request_passthrough(self):
554
548
        resp = local_app(req.environ, local_app.app.do_start_response)
555
549
        self._check_acl('test:tester', resp)
556
550
 
 
551
    def test_canonical_string(self):
 
552
        """
 
553
        The hashes here were generated by running the same requests against
 
554
        boto.utils.canonical_string
 
555
        """
 
556
        def verify(hash, path, headers):
 
557
            req = Request.blank(path, headers=headers)
 
558
            self.assertEquals(hash,
 
559
                    hashlib.md5(swift3.canonical_string(req)).hexdigest())
 
560
 
 
561
        verify('6dd08c75e42190a1ce9468d1fd2eb787', '/bucket/object',
 
562
                {'Content-Type': 'text/plain', 'X-Amz-Something': 'test',
 
563
                 'Date': 'whatever'})
 
564
 
 
565
        verify('c8447135da232ae7517328f3429df481', '/bucket/object',
 
566
                {'Content-Type': 'text/plain', 'X-Amz-Something': 'test'})
 
567
 
 
568
        verify('bf49304103a4de5c325dce6384f2a4a2', '/bucket/object',
 
569
                {'content-type': 'text/plain'})
 
570
 
 
571
        verify('be01bd15d8d47f9fe5e2d9248cc6f180', '/bucket/object', {})
 
572
 
 
573
        verify('8d28cc4b8322211f6cc003256cd9439e', 'bucket/object',
 
574
                {'Content-MD5': 'somestuff'})
 
575
 
 
576
        verify('a822deb31213ad09af37b5a7fe59e55e', '/bucket/object?acl', {})
 
577
 
 
578
        verify('cce5dd1016595cb706c93f28d3eaa18f', '/bucket/object',
 
579
                {'Content-Type': 'text/plain', 'X-Amz-A': 'test',
 
580
                 'X-Amz-Z': 'whatever', 'X-Amz-B': 'lalala',
 
581
                 'X-Amz-Y': 'lalalalalalala'})
 
582
 
557
583
if __name__ == '__main__':
558
584
    unittest.main()