~gaurav-gangalwar/swift/object_acl

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): David Goetz
  • Date: 2011-07-25 16:12:56 UTC
  • mfrom: (325.1.3 swift-1.4.1-4)
  • Revision ID: tarmac-20110725161256-f1qe2pqfkruin4ym
Rollback of XML:
rolling back xml changes bzr merge -r323..322
rolling back xml changes bzr merge -r319..318

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import simplejson
23
23
import xml.dom.minidom
24
24
from webob import Request
25
 
from xml.parsers.expat import ExpatError
26
25
 
27
26
from swift.account.server import AccountController, ACCOUNT_LISTING_LIMIT
28
27
from swift.common.utils import normalize_timestamp
451
450
                                     'X-Bytes-Used': '0',
452
451
                                     'X-Timestamp': normalize_timestamp(0)})
453
452
        self.controller.PUT(req)
454
 
        req = Request.blank('/sda1/p/a/c2%04',
455
 
                            environ={'REQUEST_METHOD': 'PUT'},
 
453
        req = Request.blank('/sda1/p/a/c2', environ={'REQUEST_METHOD': 'PUT'},
456
454
                            headers={'X-Put-Timestamp': '2',
457
455
                                     'X-Delete-Timestamp': '0',
458
456
                                     'X-Object-Count': '0',
464
462
        resp = self.controller.GET(req)
465
463
        self.assertEquals(resp.content_type, 'application/xml')
466
464
        self.assertEquals(resp.status_int, 200)
467
 
        try:
468
 
            dom = xml.dom.minidom.parseString(resp.body)
469
 
        except ExpatError, err:
470
 
            # Expat doesn't like control characters, which are XML 1.1
471
 
            # compatible. Soooo, we have to replace them. We'll do a specific
472
 
            # replace in this case, but real code that uses Expat will need
473
 
            # something more resilient.
474
 
            dom = xml.dom.minidom.parseString(
475
 
                resp.body.replace('', '\\x04'))
 
465
        dom = xml.dom.minidom.parseString(resp.body)
476
466
        self.assertEquals(dom.firstChild.nodeName, 'account')
477
467
        listing = \
478
468
            [n for n in dom.firstChild.childNodes if n.nodeName != '#text']
493
483
        self.assertEquals(sorted([n.nodeName for n in container]),
494
484
                          ['bytes', 'count', 'name'])
495
485
        node = [n for n in container if n.nodeName == 'name'][0]
496
 
        self.assertEquals(node.firstChild.nodeValue, 'c2\\x04')
 
486
        self.assertEquals(node.firstChild.nodeValue, 'c2')
497
487
        node = [n for n in container if n.nodeName == 'count'][0]
498
488
        self.assertEquals(node.firstChild.nodeValue, '0')
499
489
        node = [n for n in container if n.nodeName == 'bytes'][0]
505
495
                                     'X-Bytes-Used': '2',
506
496
                                     'X-Timestamp': normalize_timestamp(0)})
507
497
        self.controller.PUT(req)
508
 
        req = Request.blank('/sda1/p/a/c2%04',
509
 
                            environ={'REQUEST_METHOD': 'PUT'},
 
498
        req = Request.blank('/sda1/p/a/c2', environ={'REQUEST_METHOD': 'PUT'},
510
499
                            headers={'X-Put-Timestamp': '2',
511
500
                                     'X-Delete-Timestamp': '0',
512
501
                                     'X-Object-Count': '3',
517
506
                            environ={'REQUEST_METHOD': 'GET'})
518
507
        resp = self.controller.GET(req)
519
508
        self.assertEquals(resp.status_int, 200)
520
 
        try:
521
 
            dom = xml.dom.minidom.parseString(resp.body)
522
 
        except ExpatError, err:
523
 
            # Expat doesn't like control characters, which are XML 1.1
524
 
            # compatible. Soooo, we have to replace them. We'll do a specific
525
 
            # replace in this case, but real code that uses Expat will need
526
 
            # something more resilient.
527
 
            dom = xml.dom.minidom.parseString(
528
 
                resp.body.replace('', '\\x04'))
 
509
        dom = xml.dom.minidom.parseString(resp.body)
529
510
        self.assertEquals(dom.firstChild.nodeName, 'account')
530
511
        listing = \
531
512
            [n for n in dom.firstChild.childNodes if n.nodeName != '#text']
545
526
        self.assertEquals(sorted([n.nodeName for n in container]),
546
527
                          ['bytes', 'count', 'name'])
547
528
        node = [n for n in container if n.nodeName == 'name'][0]
548
 
        self.assertEquals(node.firstChild.nodeValue, 'c2\\x04')
 
529
        self.assertEquals(node.firstChild.nodeValue, 'c2')
549
530
        node = [n for n in container if n.nodeName == 'count'][0]
550
531
        self.assertEquals(node.firstChild.nodeValue, '3')
551
532
        node = [n for n in container if n.nodeName == 'bytes'][0]
978
959
            resp = self.controller.GET(req)
979
960
            self.assert_(resp.status_int in (204, 412), resp.status_int)
980
961
 
981
 
    def test_params_no_null(self):
982
 
        self.controller.PUT(Request.blank('/sda1/p/a',
983
 
                            headers={'X-Timestamp': normalize_timestamp(1)},
984
 
                            environ={'REQUEST_METHOD': 'PUT'}))
985
 
        for param in ('delimiter', 'format', 'limit', 'marker',
986
 
                      'prefix'):
987
 
            req = Request.blank('/sda1/p/a?%s=\x00' % param,
988
 
                                environ={'REQUEST_METHOD': 'GET'})
989
 
            resp = self.controller.GET(req)
990
 
            self.assertEquals(resp.status_int, 400)
991
 
 
992
 
    def test_PUT_account_no_null(self):
993
 
        req = Request.blank('/sda1/p/test\x00test',
994
 
            environ={'REQUEST_METHOD': 'PUT', 'HTTP_X_TIMESTAMP': '1'})
995
 
        resp = self.controller.PUT(req)
996
 
        self.assertEquals(resp.status_int, 400)
997
 
 
998
 
    def test_PUT_container_no_null(self):
999
 
        req = Request.blank('/sda1/p/a',
1000
 
            environ={'REQUEST_METHOD': 'PUT', 'HTTP_X_TIMESTAMP': '1'})
1001
 
        resp = self.controller.PUT(req)
1002
 
        self.assertEquals(resp.status_int, 201)
1003
 
        req = Request.blank('/sda1/p/a/test\x00test',
1004
 
            environ={'REQUEST_METHOD': 'PUT', 'HTTP_X_PUT_TIMESTAMP': '1',
1005
 
                     'HTTP_X_DELETE_TIMESTAMP': '0',
1006
 
                     'HTTP_X_OBJECT_COUNT': '0', 'HTTP_X_BYTES_USED': '0'})
1007
 
        resp = self.controller.PUT(req)
1008
 
        self.assertEquals(resp.status_int, 400)
1009
 
 
1010
962
 
1011
963
if __name__ == '__main__':
1012
964
    unittest.main()