objects.py 75.4 KB
Newer Older
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/usr/bin/env python
#coding=utf8

# Copyright 2011-2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
#   1. Redistributions of source code must retain the above
#      copyright notice, this list of conditions and the following
#      disclaimer.
#
#   2. Redistributions in binary form must reproduce the above
#      copyright notice, this list of conditions and the following
#      disclaimer in the documentation and/or other materials
#      provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from collections import defaultdict
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
38
from urllib import quote, unquote
39
from functools import partial
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
40 41 42

from pithos.api.test import (PithosAPITest, pithos_settings,
                             AssertMappingInvariant, AssertUUidInvariant,
43
                             TEST_BLOCK_SIZE, TEST_HASH_ALGORITHM,
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
44
                             DATE_FORMATS)
45 46
from pithos.api.test.util import (md5_hash, merkle, strnextling,
                                  get_random_data, get_random_name)
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
47 48 49 50 51 52 53 54

from synnefo.lib import join_urls

import django.utils.simplejson as json

import random
import re
import datetime
55 56 57 58 59
import time as _time

merkle = partial(merkle,
                 blocksize=TEST_BLOCK_SIZE,
                 blockhash=TEST_HASH_ALGORITHM)
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
60 61


Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
62
class ObjectHead(PithosAPITest):
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
63
    def test_get_object_meta(self):
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
64 65 66
        cname = self.create_container()[0]
        oname, odata = self.upload_object(cname)[:-1]

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.head(url)

        mandatory = ['Etag',
                     'Content-Length',
                     'Content-Type',
                     'Last-Modified',
                     'X-Object-Hash',
                     'X-Object-UUID',
                     'X-Object-Version',
                     'X-Object-Version-Timestamp',
                     'X-Object-Modified-By']
        for i in mandatory:
            self.assertTrue(i in r)

        r = self.post(url, content_type='',
                      HTTP_CONTENT_ENCODING='gzip',
                      HTTP_CONTENT_DISPOSITION=(
                          'attachment; filename="%s"' % oname))
        self.assertEqual(r.status_code, 202)

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
88
        r = self.head(url)
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
        for i in mandatory:
            self.assertTrue(i in r)
        self.assertTrue('Content-Encoding' in r)
        self.assertEqual(r['Content-Encoding'], 'gzip')
        self.assertTrue('Content-Disposition' in r)
        self.assertEqual(unquote(r['Content-Disposition']),
                         'attachment; filename="%s"' % oname)

        prefix = 'myobject/'
        data = ''
        for i in range(random.randint(2, 10)):
            part = '%s%d' % (prefix, i)
            data += self.upload_object(cname, oname=part)[1]

        manifest = '%s/%s' % (cname, prefix)
        oname = get_random_name()
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.put(url, data='', HTTP_X_OBJECT_MANIFEST=manifest)
        self.assertEqual(r.status_code, 201)

        r = self.head(url)
        for i in mandatory:
            self.assertTrue(i in r)
        self.assertTrue('X-Object-Manifest' in r)
        self.assertEqual(r['X-Object-Manifest'], manifest)
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
114 115


Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
class ObjectGet(PithosAPITest):
    def setUp(self):
        PithosAPITest.setUp(self)
        self.containers = ['c1', 'c2']

        # create some containers
        for c in self.containers:
            self.create_container(c)

        # upload files
        self.objects = defaultdict(list)
        self.objects['c1'].append(self.upload_object('c1')[0])

    def test_versions(self):
        c = 'c1'
        o = self.objects[c][0]
        url = join_urls(self.pithos_path, self.user, c, o)

        meta = {'HTTP_X_OBJECT_META_QUALITY': 'AAA'}
        r = self.post(url, content_type='', **meta)
        self.assertEqual(r.status_code, 202)

        url = join_urls(self.pithos_path, self.user, c, o)
        r = self.get('%s?version=list&format=json' % url)
        self.assertEqual(r.status_code, 200)
        l1 = json.loads(r.content)['versions']
        self.assertEqual(len(l1), 2)

        # update meta
        meta = {'HTTP_X_OBJECT_META_QUALITY': 'AB',
                'HTTP_X_OBJECT_META_STOCK': 'True'}
        r = self.post(url, content_type='', **meta)
        self.assertEqual(r.status_code, 202)

        # assert a newly created version has been created
        r = self.get('%s?version=list&format=json' % url)
        self.assertEqual(r.status_code, 200)
        l2 = json.loads(r.content)['versions']
        self.assertEqual(len(l2), len(l1) + 1)
        self.assertEqual(l2[:-1], l1)

        vserial, _ = l2[-2]
        self.assertEqual(self.get_object_meta(c, o, version=vserial),
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
159
                         {'Quality': 'AAA'})
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
160 161 162 163 164 165 166 167 168 169 170

        # update data
        self.append_object_data(c, o)

        # assert a newly created version has been created
        r = self.get('%s?version=list&format=json' % url)
        self.assertEqual(r.status_code, 200)
        l3 = json.loads(r.content)['versions']
        self.assertEqual(len(l3), len(l2) + 1)
        self.assertEqual(l3[:-1], l2)

171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
    def test_get_version(self):
        c = 'c1'
        o = self.objects[c][0]
        url = join_urls(self.pithos_path, self.user, c, o)

        # Update metadata
        meta = {'HTTP_X_OBJECT_META_QUALITY': 'AAA'}
        r = self.post(url, content_type='', **meta)
        self.assertEqual(r.status_code, 202)

        url = join_urls(self.pithos_path, self.user, c, o)
        r = self.get('%s?version=list&format=json' % url)
        self.assertEqual(r.status_code, 200)
        l = json.loads(r.content)['versions']
        self.assertEqual(len(l), 2)

        r = self.head('%s?version=%s' % (url, l[0][0]))
        self.assertEqual(r.status_code, 200)
        self.assertTrue('X-Object-Meta-Quality' not in r)

        r = self.head('%s?version=%s' % (url, l[1][0]))
        self.assertEqual(r.status_code, 200)
        self.assertTrue('X-Object-Meta-Quality' in r)

        # test invalid version
        r = self.head('%s?version=-1' % url)
        self.assertEqual(r.status_code, 404)

        other_name, other_data, r = self.upload_object(c)
        self.assertTrue('X-Object-Version' in r)
        other_version = r['X-Object-Version']

        self.assertTrue(o != other_name)

        r = self.get('%s?version=%s' % (url, other_version))
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
206
        self.assertEqual(r.status_code, 404)
207 208

        r = self.head('%s?version=%s' % (url, other_version))
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
209
        self.assertEqual(r.status_code, 404)
210

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
    def test_objects_with_trailing_spaces(self):
        # create object
        oname = self.upload_object('c1')[0]
        url = join_urls(self.pithos_path, self.user, 'c1', oname)

        r = self.get(quote('%s ' % url))
        self.assertEqual(r.status_code, 404)

        # delete object
        self.delete(url)

        r = self.get(url)
        self.assertEqual(r.status_code, 404)

        # upload object with trailing space
226
        oname = self.upload_object('c1', quote('%s ' % get_random_name()))[0]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292

        url = join_urls(self.pithos_path, self.user, 'c1', oname)
        r = self.get(url)
        self.assertEqual(r.status_code, 200)

        url = join_urls(self.pithos_path, self.user, 'c1', oname[:-1])
        r = self.get(url)
        self.assertEqual(r.status_code, 404)

    def test_get_partial(self):
        cname = self.containers[0]
        oname, odata = self.upload_object(cname, length=512)[:-1]
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.get(url, HTTP_RANGE='bytes=0-499')
        self.assertEqual(r.status_code, 206)
        data = r.content
        self.assertEqual(data, odata[:500])
        self.assertTrue('Content-Range' in r)
        self.assertEqual(r['Content-Range'], 'bytes 0-499/%s' % len(odata))
        self.assertTrue('Content-Type' in r)
        self.assertTrue(r['Content-Type'], 'application/octet-stream')

    def test_get_final_500(self):
        cname = self.containers[0]
        oname, odata = self.upload_object(cname, length=512)[:-1]
        size = len(odata)
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.get(url, HTTP_RANGE='bytes=-500')
        self.assertEqual(r.status_code, 206)
        self.assertEqual(r.content, odata[-500:])
        self.assertTrue('Content-Range' in r)
        self.assertEqual(r['Content-Range'],
                         'bytes %s-%s/%s' % (size - 500, size - 1, size))
        self.assertTrue('Content-Type' in r)
        self.assertTrue(r['Content-Type'], 'application/octet-stream')

    def test_get_rest(self):
        cname = self.containers[0]
        oname, odata = self.upload_object(cname, length=512)[:-1]
        size = len(odata)
        url = join_urls(self.pithos_path, self.user, cname, oname)
        offset = len(odata) - random.randint(1, 512)
        r = self.get(url, HTTP_RANGE='bytes=%s-' % offset)
        self.assertEqual(r.status_code, 206)
        self.assertEqual(r.content, odata[offset:])
        self.assertTrue('Content-Range' in r)
        self.assertEqual(r['Content-Range'],
                         'bytes %s-%s/%s' % (offset, size - 1, size))
        self.assertTrue('Content-Type' in r)
        self.assertTrue(r['Content-Type'], 'application/octet-stream')

    def test_get_range_not_satisfiable(self):
        cname = self.containers[0]
        oname, odata = self.upload_object(cname, length=512)[:-1]
        url = join_urls(self.pithos_path, self.user, cname, oname)

        # TODO
        #r = self.get(url, HTTP_RANGE='bytes=50-10')
        #self.assertEqual(r.status_code, 416)

        offset = len(odata) + 1
        r = self.get(url, HTTP_RANGE='bytes=0-%s' % offset)
        self.assertEqual(r.status_code, 416)

    def test_multiple_range(self):
        cname = self.containers[0]
293
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
        url = join_urls(self.pithos_path, self.user, cname, oname)

        l = ['0-499', '-500', '1000-']
        ranges = 'bytes=%s' % ','.join(l)
        r = self.get(url, HTTP_RANGE=ranges)
        self.assertEqual(r.status_code, 206)
        self.assertTrue('content-type' in r)
        p = re.compile(
            'multipart/byteranges; boundary=(?P<boundary>[0-9a-f]{32}\Z)',
            re.I)
        m = p.match(r['content-type'])
        if m is None:
            self.fail('Invalid multiple range content type')
        boundary = m.groupdict()['boundary']
        cparts = r.content.split('--%s' % boundary)[1:-1]

        # assert content parts length
        self.assertEqual(len(cparts), len(l))

        # for each content part assert headers
        i = 0
        for cpart in cparts:
            content = cpart.split('\r\n')
            headers = content[1:3]
            content_range = headers[0].split(': ')
            self.assertEqual(content_range[0], 'Content-Range')

            r = l[i].split('-')
            if not r[0] and not r[1]:
                pass
            elif not r[0]:
                start = len(odata) - int(r[1])
                end = len(odata)
            elif not r[1]:
                start = int(r[0])
                end = len(odata)
            else:
                start = int(r[0])
                end = int(r[1]) + 1
            fdata = odata[start:end]
            sdata = '\r\n'.join(content[4:-1])
            self.assertEqual(len(fdata), len(sdata))
            self.assertEquals(fdata, sdata)
            i += 1

    def test_multiple_range_not_satisfiable(self):
        # perform get with multiple range
        cname = self.containers[0]
342
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
343 344 345 346 347 348 349
        out_of_range = len(odata) + 1
        l = ['0-499', '-500', '%d-' % out_of_range]
        ranges = 'bytes=%s' % ','.join(l)
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.get(url, HTTP_RANGE=ranges)
        self.assertEqual(r.status_code, 416)

350
    def test_get_if_match(self):
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
351
        cname = self.containers[0]
352
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
353 354 355 356 357

        # perform get with If-Match
        url = join_urls(self.pithos_path, self.user, cname, oname)

        if pithos_settings.UPDATE_MD5:
358
            etag = md5_hash(odata)
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
359 360 361 362 363 364 365 366 367 368 369
        else:
            etag = merkle(odata)

        r = self.get(url, HTTP_IF_MATCH=etag)

        # assert get success
        self.assertEqual(r.status_code, 200)

        # assert response content
        self.assertEqual(r.content, odata)

370
    def test_get_if_match_star(self):
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
371
        cname = self.containers[0]
372
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
373 374 375 376 377 378 379 380 381 382 383

        # perform get with If-Match *
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.get(url, HTTP_IF_MATCH='*')

        # assert get success
        self.assertEqual(r.status_code, 200)

        # assert response content
        self.assertEqual(r.content, odata)

384
    def test_get_multiple_if_match(self):
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
385
        cname = self.containers[0]
386
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
387 388 389 390 391

        # perform get with If-Match
        url = join_urls(self.pithos_path, self.user, cname, oname)

        if pithos_settings.UPDATE_MD5:
392
            etag = md5_hash(odata)
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
393 394 395
        else:
            etag = merkle(odata)

396 397 398
        quoted = lambda s: '"%s"' % s
        r = self.get(url, HTTP_IF_MATCH=','.join(
            [quoted(etag), quoted(get_random_data(64))]))
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
399 400 401 402 403 404 405 406 407

        # assert get success
        self.assertEqual(r.status_code, 200)

        # assert response content
        self.assertEqual(r.content, odata)

    def test_if_match_precondition_failed(self):
        cname = self.containers[0]
408
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
409 410 411

        # perform get with If-Match
        url = join_urls(self.pithos_path, self.user, cname, oname)
412
        r = self.get(url, HTTP_IF_MATCH=get_random_name())
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
413 414
        self.assertEqual(r.status_code, 412)

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
415
    def test_if_none_match(self):
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
416 417
        # upload object
        cname = self.containers[0]
418
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
419 420

        if pithos_settings.UPDATE_MD5:
421
            etag = md5_hash(odata)
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
        else:
            etag = merkle(odata)

        # perform get with If-None-Match
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.get(url, HTTP_IF_NONE_MATCH=etag)

        # assert precondition_failed
        self.assertEqual(r.status_code, 304)

        # update object data
        r = self.append_object_data(cname, oname)[-1]
        self.assertTrue(etag != r['ETag'])

        # perform get with If-None-Match
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.get(url, HTTP_IF_NONE_MATCH=etag)

        # assert get success
        self.assertEqual(r.status_code, 200)

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
443
    def test_if_none_match_star(self):
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
444 445
        # upload object
        cname = self.containers[0]
446
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
447 448 449 450 451 452 453 454 455 456

        # perform get with If-None-Match with star
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.get(url, HTTP_IF_NONE_MATCH='*')

        self.assertEqual(r.status_code, 304)

    def test_if_modified_since(self):
        # upload object
        cname = self.containers[0]
457
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
        object_info = self.get_object_info(cname, oname)
        last_modified = object_info['Last-Modified']
        t1 = datetime.datetime.strptime(last_modified, DATE_FORMATS[-1])
        t1_formats = map(t1.strftime, DATE_FORMATS)

        # Check not modified since
        url = join_urls(self.pithos_path, self.user, cname, oname)
        for t in t1_formats:
            r = self.get(url, HTTP_IF_MODIFIED_SINCE=t)
            self.assertEqual(r.status_code, 304)

        _time.sleep(1)

        # update object data
        appended_data = self.append_object_data(cname, oname)[1]

        # Check modified since
        url = join_urls(self.pithos_path, self.user, cname, oname)
        for t in t1_formats:
            r = self.get(url, HTTP_IF_MODIFIED_SINCE=t)
            self.assertEqual(r.status_code, 200)
            self.assertEqual(r.content, odata + appended_data)

    def test_if_modified_since_invalid_date(self):
        cname = self.containers[0]
483
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
484 485 486 487 488 489 490
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.get(url, HTTP_IF_MODIFIED_SINCE='Monday')
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.content, odata)

    def test_if_not_modified_since(self):
        cname = self.containers[0]
491
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
492 493 494 495 496 497 498 499 500 501 502
        url = join_urls(self.pithos_path, self.user, cname, oname)
        object_info = self.get_object_info(cname, oname)
        last_modified = object_info['Last-Modified']
        t = datetime.datetime.strptime(last_modified, DATE_FORMATS[-1])

        # Check unmodified
        t1 = t + datetime.timedelta(seconds=1)
        t1_formats = map(t1.strftime, DATE_FORMATS)
        for t in t1_formats:
            r = self.get(url, HTTP_IF_UNMODIFIED_SINCE=t)
            self.assertEqual(r.status_code, 200)
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
503
            self.assertEqual(r.content, odata)
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
504 505 506 507 508 509 510 511 512 513 514

        # modify object
        _time.sleep(2)
        self.append_object_data(cname, oname)

        object_info = self.get_object_info(cname, oname)
        last_modified = object_info['Last-Modified']
        t = datetime.datetime.strptime(last_modified, DATE_FORMATS[-1])
        t2 = t - datetime.timedelta(seconds=1)
        t2_formats = map(t2.strftime, DATE_FORMATS)

515
        # check modified
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
516 517 518 519
        for t in t2_formats:
            r = self.get(url, HTTP_IF_UNMODIFIED_SINCE=t)
            self.assertEqual(r.status_code, 412)

520
        # modify account: update object meta
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
521 522 523 524 525 526 527 528 529
        _time.sleep(1)
        self.update_object_meta(cname, oname, {'foo': 'bar'})

        object_info = self.get_object_info(cname, oname)
        last_modified = object_info['Last-Modified']
        t = datetime.datetime.strptime(last_modified, DATE_FORMATS[-1])
        t3 = t - datetime.timedelta(seconds=1)
        t3_formats = map(t3.strftime, DATE_FORMATS)

530
        # check modified
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
531 532 533 534 535 536
        for t in t3_formats:
            r = self.get(url, HTTP_IF_UNMODIFIED_SINCE=t)
            self.assertEqual(r.status_code, 412)

    def test_if_unmodified_since(self):
        cname = self.containers[0]
537
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
538 539 540 541 542 543 544 545 546 547 548 549 550 551
        url = join_urls(self.pithos_path, self.user, cname, oname)
        object_info = self.get_object_info(cname, oname)
        last_modified = object_info['Last-Modified']
        t = datetime.datetime.strptime(last_modified, DATE_FORMATS[-1])
        t = t + datetime.timedelta(seconds=1)
        t_formats = map(t.strftime, DATE_FORMATS)

        for tf in t_formats:
            r = self.get(url, HTTP_IF_UNMODIFIED_SINCE=tf)
            self.assertEqual(r.status_code, 200)
            self.assertEqual(r.content, odata)

    def test_if_unmodified_since_precondition_failed(self):
        cname = self.containers[0]
552
        oname, odata = self.upload_object(cname)[:-1]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
        url = join_urls(self.pithos_path, self.user, cname, oname)
        object_info = self.get_object_info(cname, oname)
        last_modified = object_info['Last-Modified']
        t = datetime.datetime.strptime(last_modified, DATE_FORMATS[-1])
        t = t - datetime.timedelta(seconds=1)
        t_formats = map(t.strftime, DATE_FORMATS)

        for tf in t_formats:
            r = self.get(url, HTTP_IF_UNMODIFIED_SINCE=tf)
            self.assertEqual(r.status_code, 412)

    def test_hashes(self):
        l = random.randint(2, 5) * pithos_settings.BACKEND_BLOCK_SIZE
        cname = self.containers[0]
        oname, odata = self.upload_object(cname, length=l)[:-1]
        size = len(odata)

        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.get('%s?format=json&hashmap' % url)
        self.assertEqual(r.status_code, 200)
        body = json.loads(r.content)

        hashes = body['hashes']
        block_size = body['block_size']
        block_num = size / block_size if size / block_size == 0 else\
            size / block_size + 1
        self.assertTrue(len(hashes), block_num)
        i = 0
        for h in hashes:
            start = i * block_size
            end = (i + 1) * block_size
584
            hash = merkle(odata[start:end])
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
585 586 587 588 589 590 591
            self.assertEqual(h, hash)
            i += 1


class ObjectPut(PithosAPITest):
    def setUp(self):
        PithosAPITest.setUp(self)
592
        self.container = get_random_name()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
593 594 595 596
        self.create_container(self.container)

    def test_upload(self):
        cname = self.container
597
        oname = get_random_name()
598
        data = get_random_data()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
        meta = {'test': 'test1'}
        headers = dict(('HTTP_X_OBJECT_META_%s' % k.upper(), v)
                       for k, v in meta.iteritems())
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.put(url, data=data, content_type='application/pdf', **headers)
        self.assertEqual(r.status_code, 201)
        self.assertTrue('ETag' in r)
        self.assertTrue('X-Object-Version' in r)

        info = self.get_object_info(cname, oname)

        # assert object meta
        self.assertTrue('X-Object-Meta-Test' in info)
        self.assertEqual(info['X-Object-Meta-Test'], 'test1')

        # assert content-type
        self.assertEqual(info['content-type'], 'application/pdf')

        # assert uploaded content
        r = self.get(url)
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.content, data)

    def test_maximum_upload_size_exceeds(self):
        cname = self.container
624
        oname = get_random_name()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640

        # set container quota to 100
        url = join_urls(self.pithos_path, self.user, cname)
        r = self.post(url, HTTP_X_CONTAINER_POLICY_QUOTA='100')
        self.assertEqual(r.status_code, 202)

        info = self.get_container_info(cname)
        length = int(info['X-Container-Policy-Quota']) + 1

        data = get_random_data(length)
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.put(url, data=data)
        self.assertEqual(r.status_code, 413)

    def test_upload_with_name_containing_slash(self):
        cname = self.container
641
        oname = '/%s' % get_random_name()
642
        data = get_random_data()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
643 644 645 646 647 648 649 650 651 652 653 654
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.put(url, data=data)
        self.assertEqual(r.status_code, 201)
        self.assertTrue('ETag' in r)
        self.assertTrue('X-Object-Version' in r)

        r = self.get(url)
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.content, data)

    def test_upload_unprocessable_entity(self):
        cname = self.container
655
        oname = get_random_name()
656
        data = get_random_data()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
657 658 659 660
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.put(url, data=data, HTTP_ETAG='123')
        self.assertEqual(r.status_code, 422)

661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
    def test_upload_if_none_match(self):
        cname = self.container
        oname = get_random_name()
        data = get_random_data()
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.put(url, data=data, HTTP_IF_NONE_MATCH='*')
        self.assertEqual(r.status_code, 201)

        r = self.get(url)
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.content, data)
        self.assertTrue('ETag' in r)
        etag = r['ETag']

        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.put(url, data=data, HTTP_IF_NONE_MATCH=etag)
        self.assertEqual(r.status_code, 412)

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
679 680
#    def test_chunked_transfer(self):
#        cname = self.container
681
#        oname = '/%s' % get_random_name()
682
#        data = get_random_data()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
#        url = join_urls(self.pithos_path, self.user, cname, oname)
#        r = self.put(url, data=data, HTTP_TRANSFER_ENCODING='chunked')
#        self.assertEqual(r.status_code, 201)
#        self.assertTrue('ETag' in r)
#        self.assertTrue('X-Object-Version' in r)

    def test_manifestation(self):
        cname = self.container
        prefix = 'myobject/'
        data = ''
        for i in range(random.randint(2, 10)):
            part = '%s%d' % (prefix, i)
            data += self.upload_object(cname, oname=part)[1]

        manifest = '%s/%s' % (cname, prefix)
698
        oname = get_random_name()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
699 700 701 702 703 704 705 706 707 708 709 710
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.put(url, data='', HTTP_X_OBJECT_MANIFEST=manifest)
        self.assertEqual(r.status_code, 201)

        # assert object exists
        r = self.get(url)
        self.assertEqual(r.status_code, 200)

        # assert its content
        self.assertEqual(r.content, data)

        # invalid manifestation
711
        invalid_manifestation = '%s/%s' % (cname, get_random_name())
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
712 713 714 715 716 717
        self.put(url, data='', HTTP_X_OBJECT_MANIFEST=invalid_manifestation)
        r = self.get(url)
        self.assertEqual(r.content, '')

    def test_create_zero_length_object(self):
        cname = self.container
718
        oname = get_random_name()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
719 720 721 722 723 724 725 726 727 728 729 730 731
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.put(url, data='')
        self.assertEqual(r.status_code, 201)

        r = self.get(url)
        self.assertEqual(r.status_code, 200)
        self.assertEqual(int(r['Content-Length']), 0)
        self.assertEqual(r.content, '')

        r = self.get('%s?hashmap=&format=json' % url)
        self.assertEqual(r.status_code, 200)
        body = json.loads(r.content)
        hashes = body['hashes']
732
        hash = merkle('')
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
733 734 735 736 737 738 739 740 741 742 743 744
        self.assertEqual(hashes, [hash])

    def test_create_object_by_hashmap(self):
        cname = self.container
        block_size = pithos_settings.BACKEND_BLOCK_SIZE

        # upload an object
        oname, data = self.upload_object(cname, length=block_size + 1)[:-1]
        # get it hashmap
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.get('%s?hashmap=&format=json' % url)

745
        oname = get_random_name()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
746 747 748 749 750 751 752 753
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.put('%s?hashmap=' % url, data=r.content)
        self.assertEqual(r.status_code, 201)

        r = self.get(url)
        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.content, data)

754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
    def test_create_object_by_invalid_hashmap(self):
        cname = self.container
        block_size = pithos_settings.BACKEND_BLOCK_SIZE

        # upload an object
        oname, data = self.upload_object(cname, length=block_size + 1)[:-1]
        # get it hashmap
        url = join_urls(self.pithos_path, self.user, cname, oname)
        r = self.get('%s?hashmap=&format=json' % url)
        data = r.content
        try:
            hashmap = json.loads(data)
        except:
            self.fail('JSON format expected')

        oname = get_random_name()
        url = join_urls(self.pithos_path, self.user, cname, oname)
        hashmap['hashes'] = [get_random_name()]
        r = self.put('%s?hashmap=' % url, data=json.dumps(hashmap))
        self.assertEqual(r.status_code, 400)

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
775

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
776
class ObjectPutCopy(PithosAPITest):
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
    def setUp(self):
        PithosAPITest.setUp(self)
        self.container = 'c1'
        self.create_container(self.container)
        self.object, self.data = self.upload_object(self.container)[:-1]

        url = join_urls(
            self.pithos_path, self.user, self.container, self.object)
        r = self.head(url)
        self.etag = r['X-Object-Hash']

    def test_copy(self):
        with AssertMappingInvariant(self.get_object_info, self.container,
                                    self.object):
            # copy object
792
            oname = get_random_name()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
            url = join_urls(self.pithos_path, self.user, self.container, oname)
            r = self.put(url, data='', HTTP_X_OBJECT_META_TEST='testcopy',
                         HTTP_X_COPY_FROM='/%s/%s' % (
                             self.container, self.object))

            # assert copy success
            self.assertEqual(r.status_code, 201)

            # assert access the new object
            r = self.head(url)
            self.assertEqual(r.status_code, 200)
            self.assertTrue('X-Object-Meta-Test' in r)
            self.assertEqual(r['X-Object-Meta-Test'], 'testcopy')

            # assert etag is the same
            self.assertTrue('X-Object-Hash' in r)
            self.assertEqual(r['X-Object-Hash'], self.etag)

    def test_copy_from_different_container(self):
        cname = 'c2'
        self.create_container(cname)
        with AssertMappingInvariant(self.get_object_info, self.container,
                                    self.object):
816
            oname = get_random_name()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
            url = join_urls(self.pithos_path, self.user, cname, oname)
            r = self.put(url, data='', HTTP_X_OBJECT_META_TEST='testcopy',
                         HTTP_X_COPY_FROM='/%s/%s' % (
                             self.container, self.object))

            # assert copy success
            self.assertEqual(r.status_code, 201)

            # assert access the new object
            r = self.head(url)
            self.assertEqual(r.status_code, 200)
            self.assertTrue('X-Object-Meta-Test' in r)
            self.assertEqual(r['X-Object-Meta-Test'], 'testcopy')

            # assert etag is the same
            self.assertTrue('X-Object-Hash' in r)
            self.assertEqual(r['X-Object-Hash'], self.etag)

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
    def test_copy_from_other_account(self):
        cname = 'c2'
        self.create_container(cname, user='chuck')
        self.create_container(cname, user='alice')

        # share object for read with alice
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.post(url, content_type='', HTTP_CONTENT_RANGE='bytes */*',
                      HTTP_X_OBJECT_SHARING='read=alice')
        self.assertEqual(r.status_code, 202)

        # assert not allowed for chuck
        oname = get_random_name()
        url = join_urls(self.pithos_path, 'chuck', cname, oname)
        r = self.put(url, data='', user='chuck',
                     HTTP_X_OBJECT_META_TEST='testcopy',
                     HTTP_X_COPY_FROM='/%s/%s' % (
                         self.container, self.object),
                     HTTP_X_SOURCE_ACCOUNT='user')

        self.assertEqual(r.status_code, 403)

        # assert copy success for alice
        url = join_urls(self.pithos_path, 'alice', cname, oname)
        r = self.put(url, data='', user='alice',
                     HTTP_X_OBJECT_META_TEST='testcopy',
                     HTTP_X_COPY_FROM='/%s/%s' % (
                         self.container, self.object),
                     HTTP_X_SOURCE_ACCOUNT='user')
        self.assertEqual(r.status_code, 201)

        # assert access the new object
        r = self.head(url, user='alice')
        self.assertEqual(r.status_code, 200)
        self.assertTrue('X-Object-Meta-Test' in r)
        self.assertEqual(r['X-Object-Meta-Test'], 'testcopy')

        # assert etag is the same
        self.assertTrue('X-Object-Hash' in r)
        self.assertEqual(r['X-Object-Hash'], self.etag)

        # share object for write
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.post(url, content_type='', HTTP_CONTENT_RANGE='bytes */*',
                      HTTP_X_OBJECT_SHARING='write=dan')
        self.assertEqual(r.status_code, 202)

        # assert not allowed copy for alice
        url = join_urls(self.pithos_path, 'alice', cname, oname)
        r = self.put(url, data='', user='alice',
                     HTTP_X_OBJECT_META_TEST='testcopy',
                     HTTP_X_COPY_FROM='/%s/%s' % (
                         self.container, self.object),
                     HTTP_X_SOURCE_ACCOUNT='user')
        self.assertEqual(r.status_code, 403)

        # assert allowed copy for dan
        self.create_container(cname, user='dan')
        url = join_urls(self.pithos_path, 'dan', cname, oname)
        r = self.put(url, data='', user='dan',
                     HTTP_X_OBJECT_META_TEST='testcopy',
                     HTTP_X_COPY_FROM='/%s/%s' % (
                         self.container, self.object),
                     HTTP_X_SOURCE_ACCOUNT='user')
        self.assertEqual(r.status_code, 201)

        # assert access the new object
        r = self.head(url, user='dan')
        self.assertEqual(r.status_code, 200)
        self.assertTrue('X-Object-Meta-Test' in r)
        self.assertEqual(r['X-Object-Meta-Test'], 'testcopy')

        # assert etag is the same
        self.assertTrue('X-Object-Hash' in r)
        self.assertEqual(r['X-Object-Hash'], self.etag)

        # assert source object still exists
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.head(url)
        self.assertEqual(r.status_code, 200)
        # assert etag is the same
        self.assertTrue('X-Object-Hash' in r)
        self.assertEqual(r['X-Object-Hash'], self.etag)

        r = self.get(url)
        self.assertEqual(r.status_code, 200)
        # assert etag is the same
        self.assertTrue('X-Object-Hash' in r)
        self.assertEqual(r['X-Object-Hash'], self.etag)

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
928 929
    def test_copy_invalid(self):
        # copy from non-existent object
930
        oname = get_random_name()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
931 932 933
        url = join_urls(self.pithos_path, self.user, self.container, oname)
        r = self.put(url, data='', HTTP_X_OBJECT_META_TEST='testcopy',
                     HTTP_X_COPY_FROM='/%s/%s' % (
934
                         self.container, get_random_name()))
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
935 936 937
        self.assertEqual(r.status_code, 404)

        # copy from non-existent container
938
        oname = get_random_name()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
939 940 941
        url = join_urls(self.pithos_path, self.user, self.container, oname)
        r = self.put(url, data='', HTTP_X_OBJECT_META_TEST='testcopy',
                     HTTP_X_COPY_FROM='/%s/%s' % (
942
                         get_random_name(), self.object))
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
943 944 945 946 947
        self.assertEqual(r.status_code, 404)

    def test_copy_dir(self):
        folder = self.create_folder(self.container)[0]
        subfolder = self.create_folder(
948
            self.container, oname='%s/%s' % (folder, get_random_name()))[0]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
949 950 951
        objects = [subfolder]
        append = objects.append
        append(self.upload_object(self.container,
952
                                  '%s/%s' % (folder, get_random_name()),
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
953
                                  depth='1')[0])
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
954
        append(self.upload_object(self.container,
955
                                  '%s/%s' % (subfolder, get_random_name()),
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
956
                                  depth='2')[0])
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976
        other = self.upload_object(self.container, strnextling(folder))[0]

        # copy dir
        copy_folder = self.create_folder(self.container)[0]
        url = join_urls(self.pithos_path, self.user, self.container,
                        copy_folder)
        r = self.put('%s?delimiter=/' % url, data='',
                     HTTP_X_COPY_FROM='/%s/%s' % (self.container, folder))
        self.assertEqual(r.status_code, 201)

        for obj in objects:
            # assert object exists
            url = join_urls(self.pithos_path, self.user, self.container,
                            obj.replace(folder, copy_folder))
            r = self.head(url)
            self.assertEqual(r.status_code, 200)

            # assert metadata
            meta = self.get_object_meta(self.container, obj)
            for k in meta.keys():
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
977 978 979
                key = 'X-Object-Meta-%s' % k
                self.assertTrue(key in r)
                self.assertEqual(r[key], meta[k])
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
980 981 982 983 984 985 986 987 988

        # assert other has not been created under copy folder
        url = join_urls(self.pithos_path, self.user, self.container,
                        '%s/%s' % (copy_folder,
                                   other.replace(folder, copy_folder)))
        r = self.head(url)
        self.assertEqual(r.status_code, 404)


Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
989
class ObjectPutMove(PithosAPITest):
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
990 991 992 993 994 995 996 997 998 999 1000 1001 1002
    def setUp(self):
        PithosAPITest.setUp(self)
        self.container = 'c1'
        self.create_container(self.container)
        self.object, self.data = self.upload_object(self.container)[:-1]

        url = join_urls(
            self.pithos_path, self.user, self.container, self.object)
        r = self.head(url)
        self.etag = r['X-Object-Hash']

    def test_move(self):
        # move object
1003
        oname = get_random_name()
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
        url = join_urls(self.pithos_path, self.user, self.container, oname)
        r = self.put(url, data='', HTTP_X_OBJECT_META_TEST='testcopy',
                     HTTP_X_MOVE_FROM='/%s/%s' % (
                         self.container, self.object))

        # assert move success
        self.assertEqual(r.status_code, 201)

        # assert access the new object
        r = self.head(url)
        self.assertEqual(r.status_code, 200)
        self.assertTrue('X-Object-Meta-Test' in r)
        self.assertEqual(r['X-Object-Meta-Test'], 'testcopy')

        # assert etag is the same
        self.assertTrue('X-Object-Hash' in r)

        # assert the initial object has been deleted
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.head(url)
        self.assertEqual(r.status_code, 404)

    def test_move_dir(self):
        folder = self.create_folder(self.container)[0]
        subfolder = self.create_folder(
1030
            self.container, oname='%s/%s' % (folder, get_random_name()))[0]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1031 1032 1033
        objects = [subfolder]
        append = objects.append
        append(self.upload_object(self.container,
1034
                                  '%s/%s' % (folder, get_random_name()),
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1035
                                  depth='1')[0])
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1036
        append(self.upload_object(self.container,
1037
                                  '%s/%s' % (subfolder, get_random_name()),
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1038
                                  depth='1')[0])
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
        other = self.upload_object(self.container, strnextling(folder))[0]

        # move dir
        copy_folder = self.create_folder(self.container)[0]
        url = join_urls(self.pithos_path, self.user, self.container,
                        copy_folder)
        r = self.put('%s?delimiter=/' % url, data='',
                     HTTP_X_MOVE_FROM='/%s/%s' % (self.container, folder))
        self.assertEqual(r.status_code, 201)

        for obj in objects:
            # assert initial object does not exist
            url = join_urls(self.pithos_path, self.user, self.container, obj)
            r = self.head(url)
            self.assertEqual(r.status_code, 404)

            # assert new object was created
            url = join_urls(self.pithos_path, self.user, self.container,
                            obj.replace(folder, copy_folder))
            r = self.head(url)
            self.assertEqual(r.status_code, 200)

        # assert other has not been created under copy folder
        url = join_urls(self.pithos_path, self.user, self.container,
                        '%s/%s' % (copy_folder,
                                   other.replace(folder, copy_folder)))
        r = self.head(url)
        self.assertEqual(r.status_code, 404)

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463
    def test_move_from_other_account(self):
        cname = 'c2'
        self.create_container(cname, user='chuck')
        self.create_container(cname, user='alice')

        # share object for read with alice
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.post(url, content_type='', HTTP_CONTENT_RANGE='bytes */*',
                      HTTP_X_OBJECT_SHARING='read=alice')
        self.assertEqual(r.status_code, 202)

        # assert not allowed move for chuck
        oname = get_random_name()
        url = join_urls(self.pithos_path, 'chuck', cname, oname)
        r = self.put(url, data='', user='chuck',
                     HTTP_X_OBJECT_META_TEST='testcopy',
                     HTTP_X_MOVE_FROM='/%s/%s' % (
                         self.container, self.object),
                     HTTP_X_SOURCE_ACCOUNT='user')

        self.assertEqual(r.status_code, 403)

        # assert no new object was created
        r = self.head(url, user='chuck')
        self.assertEqual(r.status_code, 404)

        # assert not allowed move for alice
        url = join_urls(self.pithos_path, 'alice', cname, oname)
        r = self.put(url, data='', user='alice',
                     HTTP_X_OBJECT_META_TEST='testcopy',
                     HTTP_X_MOVE_FROM='/%s/%s' % (
                         self.container, self.object),
                     HTTP_X_SOURCE_ACCOUNT='user')
        self.assertEqual(r.status_code, 403)

        # assert no new object was created
        r = self.head(url, user='alice')
        self.assertEqual(r.status_code, 404)

        # share object for write with dan
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.post(url, content_type='', HTTP_CONTENT_RANGE='bytes */*',
                      HTTP_X_OBJECT_SHARING='write=dan')
        self.assertEqual(r.status_code, 202)

        # assert not allowed move for alice
        url = join_urls(self.pithos_path, 'alice', cname, oname)
        r = self.put(url, data='', user='alice',
                     HTTP_X_OBJECT_META_TEST='testcopy',
                     HTTP_X_MOVE_FROM='/%s/%s' % (
                         self.container, self.object),
                     HTTP_X_SOURCE_ACCOUNT='user')
        self.assertEqual(r.status_code, 403)

        # assert no new object was created
        r = self.head(url, user='alice')
        self.assertEqual(r.status_code, 404)

        # assert not allowed move for dan
        self.create_container(cname, user='dan')
        url = join_urls(self.pithos_path, 'dan', cname, oname)
        r = self.put(url, data='', user='dan',
                     HTTP_X_OBJECT_META_TEST='testcopy',
                     HTTP_X_MOVE_FROM='/%s/%s' % (
                         self.container, self.object),
                     HTTP_X_SOURCE_ACCOUNT='user')
        self.assertEqual(r.status_code, 403)

        # assert no new object was created
        r = self.head(url, user='dan')
        self.assertEqual(r.status_code, 404)


class ObjectCopy(PithosAPITest):
    def setUp(self):
        PithosAPITest.setUp(self)
        self.container = 'c1'
        self.create_container(self.container)
        self.object, self.data = self.upload_object(self.container)[:-1]

        url = join_urls(
            self.pithos_path, self.user, self.container, self.object)
        r = self.head(url)
        self.etag = r['X-Object-Hash']

    def test_copy(self):
        with AssertMappingInvariant(self.get_object_info, self.container,
                                    self.object):
            oname = get_random_name()
            # copy object
            url = join_urls(self.pithos_path, self.user, self.container,
                            self.object)
            r = self.copy(url, HTTP_X_OBJECT_META_TEST='testcopy',
                          HTTP_DESTINATION='/%s/%s' % (self.container,
                                                       oname))
            # assert copy success
            url = join_urls(self.pithos_path, self.user, self.container,
                            oname)
            self.assertEqual(r.status_code, 201)

            # assert access the new object
            r = self.head(url)
            self.assertEqual(r.status_code, 200)
            self.assertTrue('X-Object-Meta-Test' in r)
            self.assertEqual(r['X-Object-Meta-Test'], 'testcopy')

            # assert etag is the same
            self.assertTrue('X-Object-Hash' in r)
            self.assertEqual(r['X-Object-Hash'], self.etag)

            # assert source object still exists
            url = join_urls(self.pithos_path, self.user, self.container,
                            self.object)
            r = self.head(url)
            self.assertEqual(r.status_code, 200)

            # assert etag is the same
            self.assertTrue('X-Object-Hash' in r)
            self.assertEqual(r['X-Object-Hash'], self.etag)

            r = self.get(url)
            self.assertEqual(r.status_code, 200)

            # assert etag is the same
            self.assertTrue('X-Object-Hash' in r)
            self.assertEqual(r['X-Object-Hash'], self.etag)

            # copy object to other container (not existing)
            cname = get_random_name()
            url = join_urls(self.pithos_path, self.user, self.container,
                            self.object)
            r = self.copy(url, HTTP_X_OBJECT_META_TEST='testcopy',
                          HTTP_DESTINATION='/%s/%s' % (cname, self.object))

            # assert destination container does not exist
            url = join_urls(self.pithos_path, self.user, cname,
                            self.object)
            self.assertEqual(r.status_code, 404)

            # create container
            self.create_container(cname)

            # copy object to other container (existing)
            url = join_urls(self.pithos_path, self.user, self.container,
                            self.object)
            r = self.copy(url, HTTP_X_OBJECT_META_TEST='testcopy',
                          HTTP_DESTINATION='/%s/%s' % (cname, self.object))

            # assert copy success
            url = join_urls(self.pithos_path, self.user, cname,
                            self.object)
            self.assertEqual(r.status_code, 201)

            # assert access the new object
            r = self.head(url)
            self.assertEqual(r.status_code, 200)
            self.assertTrue('X-Object-Meta-Test' in r)
            self.assertEqual(r['X-Object-Meta-Test'], 'testcopy')

            # assert etag is the same
            self.assertTrue('X-Object-Hash' in r)
            self.assertEqual(r['X-Object-Hash'], self.etag)

                        # assert source object still exists
            url = join_urls(self.pithos_path, self.user, self.container,
                            self.object)
            r = self.head(url)
            self.assertEqual(r.status_code, 200)

            # assert etag is the same
            self.assertTrue('X-Object-Hash' in r)
            self.assertEqual(r['X-Object-Hash'], self.etag)

            r = self.get(url)
            self.assertEqual(r.status_code, 200)

            # assert etag is the same
            self.assertTrue('X-Object-Hash' in r)
            self.assertEqual(r['X-Object-Hash'], self.etag)

    def test_copy_to_other_account(self):
        # create a container under alice account
        cname = self.create_container(user='alice')[0]

        # create a folder under this container
        folder = self.create_folder(cname, user='alice')[0]

        oname = get_random_name()

        # copy object to other account container
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.copy(url, HTTP_X_OBJECT_META_TEST='testcopy',
                      HTTP_DESTINATION='/%s/%s/%s' % (cname, folder, oname),
                      HTTP_DESTINATION_ACCOUNT='alice')
        self.assertEqual(r.status_code, 403)

        # share object for read with user
        url = join_urls(self.pithos_path, 'alice', cname, folder)
        r = self.post(url, user='alice', content_type='',
                      HTTP_CONTENT_RANGE='bytes */*',
                      HTTP_X_OBJECT_SHARING='read=%s' % self.user)
        self.assertEqual(r.status_code, 202)

        # assert copy object still is not allowed
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.copy(url, HTTP_X_OBJECT_META_TEST='testcopy',
                      HTTP_DESTINATION='/%s/%s/%s' % (cname, folder, oname),
                      HTTP_DESTINATION_ACCOUNT='alice')
        self.assertEqual(r.status_code, 403)

        # share object for write with user
        url = join_urls(self.pithos_path, 'alice', cname, folder)
        r = self.post(url, user='alice',  content_type='',
                      HTTP_CONTENT_RANGE='bytes */*',
                      HTTP_X_OBJECT_SHARING='write=%s' % self.user)
        self.assertEqual(r.status_code, 202)

        # assert copy object now is allowed
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.copy(url, HTTP_X_OBJECT_META_TEST='testcopy',
                      HTTP_DESTINATION='/%s/%s/%s' % (cname, folder, oname),
                      HTTP_DESTINATION_ACCOUNT='alice')
        self.assertEqual(r.status_code, 201)

        # assert access the new object
        url = join_urls(self.pithos_path, 'alice', cname, folder, oname)
        r = self.head(url, user='alice')
        self.assertEqual(r.status_code, 200)
        self.assertTrue('X-Object-Meta-Test' in r)
        self.assertEqual(r['X-Object-Meta-Test'], 'testcopy')

        # assert etag is the same
        self.assertTrue('X-Object-Hash' in r)
        self.assertEqual(r['X-Object-Hash'], self.etag)

        # assert source object still exists
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.head(url)
        self.assertEqual(r.status_code, 200)

        # assert etag is the same
        self.assertTrue('X-Object-Hash' in r)
        self.assertEqual(r['X-Object-Hash'], self.etag)

        r = self.get(url)
        self.assertEqual(r.status_code, 200)

        # assert etag is the same
        self.assertTrue('X-Object-Hash' in r)
        self.assertEqual(r['X-Object-Hash'], self.etag)


class ObjectMove(PithosAPITest):
    def setUp(self):
        PithosAPITest.setUp(self)
        self.container = 'c1'
        self.create_container(self.container)
        self.object, self.data = self.upload_object(self.container)[:-1]

        url = join_urls(
            self.pithos_path, self.user, self.container, self.object)
        r = self.head(url)
        self.etag = r['X-Object-Hash']

    def test_move(self):
        oname = get_random_name()

        # move object
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.move(url, HTTP_X_OBJECT_META_TEST='testmove',
                      HTTP_DESTINATION='/%s/%s' % (self.container,
                                                   oname))
        # assert move success
        url = join_urls(self.pithos_path, self.user, self.container,
                        oname)
        self.assertEqual(r.status_code, 201)

        # assert access the new object
        r = self.head(url)
        self.assertEqual(r.status_code, 200)
        self.assertTrue('X-Object-Meta-Test' in r)
        self.assertEqual(r['X-Object-Meta-Test'], 'testmove')

        # assert etag is the same
        self.assertTrue('X-Object-Hash' in r)
        self.assertEqual(r['X-Object-Hash'], self.etag)

        # assert source object does not exist
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.head(url)
        self.assertEqual(r.status_code, 404)

    def test_move_to_other_container(self):
        # move object to other container (not existing)
        cname = get_random_name()
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.move(url, HTTP_X_OBJECT_META_TEST='testmove',
                      HTTP_DESTINATION='/%s/%s' % (cname, self.object))

        # assert destination container does not exist
        url = join_urls(self.pithos_path, self.user, cname,
                        self.object)
        self.assertEqual(r.status_code, 404)

        # create container
        self.create_container(cname)

        # move object to other container (existing)
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.move(url, HTTP_X_OBJECT_META_TEST='testmove',
                      HTTP_DESTINATION='/%s/%s' % (cname, self.object))

        # assert move success
        url = join_urls(self.pithos_path, self.user, cname,
                        self.object)
        self.assertEqual(r.status_code, 201)

        # assert access the new object
        r = self.head(url)
        self.assertEqual(r.status_code, 200)
        self.assertTrue('X-Object-Meta-Test' in r)
        self.assertEqual(r['X-Object-Meta-Test'], 'testmove')

        # assert etag is the same
        self.assertTrue('X-Object-Hash' in r)
        self.assertEqual(r['X-Object-Hash'], self.etag)

        # assert source object does not exist
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.head(url)
        self.assertEqual(r.status_code, 404)

    def test_move_to_other_account(self):
        # create a container under alice account
        cname = self.create_container(user='alice')[0]

        # create a folder under this container
        folder = self.create_folder(cname, user='alice')[0]

        oname = get_random_name()

        # move object to other account container
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.move(url, HTTP_X_OBJECT_META_TEST='testmove',
                      HTTP_DESTINATION='/%s/%s/%s' % (cname, folder, oname),
                      HTTP_DESTINATION_ACCOUNT='alice')
        self.assertEqual(r.status_code, 403)

        # share object for read with user
        url = join_urls(self.pithos_path, 'alice', cname, folder)
        r = self.post(url, user='alice', content_type='',
                      HTTP_CONTENT_RANGE='bytes */*',
                      HTTP_X_OBJECT_SHARING='read=%s' % self.user)
        self.assertEqual(r.status_code, 202)

        # assert move object still is not allowed
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.move(url, HTTP_X_OBJECT_META_TEST='testmove',
                      HTTP_DESTINATION='/%s/%s/%s' % (cname, folder, oname),
                      HTTP_DESTINATION_ACCOUNT='alice')
        self.assertEqual(r.status_code, 403)

        # share object for write with user
        url = join_urls(self.pithos_path, 'alice', cname, folder)
        r = self.post(url, user='alice',  content_type='',
                      HTTP_CONTENT_RANGE='bytes */*',
                      HTTP_X_OBJECT_SHARING='write=%s' % self.user)
        self.assertEqual(r.status_code, 202)

        # assert move object now is allowed
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.move(url, HTTP_X_OBJECT_META_TEST='testmove',
                      HTTP_DESTINATION='/%s/%s/%s' % (cname, folder, oname),
                      HTTP_DESTINATION_ACCOUNT='alice')
        self.assertEqual(r.status_code, 201)

        # assert source object does not exist
        url = join_urls(self.pithos_path, self.user, self.container,
                        self.object)
        r = self.head(url)
        self.assertEqual(r.status_code, 404)

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488

class ObjectPost(PithosAPITest):
    def setUp(self):
        PithosAPITest.setUp(self)
        self.container = 'c1'
        self.create_container(self.container)
        self.object, self.object_data = self.upload_object(self.container)[:2]

    def test_update_meta(self):
        with AssertUUidInvariant(self.get_object_info,
                                 self.container,
                                 self.object):
            # update metadata
            d = {'a' * 114: 'b' * 256}
            kwargs = dict(('HTTP_X_OBJECT_META_%s' % k, v) for
                          k, v in d.items())
            url = join_urls(self.pithos_path, self.user, self.container,
                            self.object)
            r = self.post(url, content_type='', **kwargs)
            self.assertEqual(r.status_code, 202)

            # assert metadata have been updated
            meta = self.get_object_meta(self.container, self.object)

            for k, v in d.items():
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1489 1490
                self.assertTrue(k.title() in meta)
                self.assertTrue(meta[k.title()], v)
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540

            # Header key too large
            d = {'a' * 115: 'b' * 256}
            kwargs = dict(('HTTP_X_OBJECT_META_%s' % k, v) for
                          k, v in d.items())
            r = self.post(url, content_type='', **kwargs)
            self.assertEqual(r.status_code, 400)

            # Header value too large
            d = {'a' * 114: 'b' * 257}
            kwargs = dict(('HTTP_X_OBJECT_META_%s' % k, v) for
                          k, v in d.items())
            r = self.post(url, content_type='', **kwargs)
            self.assertEqual(r.status_code, 400)

#            # Check utf-8 meta
#            d = {'α' * (114 / 2): 'β' * (256 / 2)}
#            kwargs = dict(('HTTP_X_OBJECT_META_%s' % quote(k), quote(v)) for
#                          k, v in d.items())
#            url = join_urls(self.pithos_path, self.user, self.container,
#                            self.object)
#            r = self.post(url, content_type='', **kwargs)
#            self.assertEqual(r.status_code, 202)
#
#            # assert metadata have been updated
#            meta = self.get_object_meta(self.container, self.object)
#
#            for k, v in d.items():
#                key = 'X-Object-Meta-%s' % k.title()
#                self.assertTrue(key in meta)
#                self.assertTrue(meta[key], v)
#
#            # Header key too large
#            d = {'α' * 114: 'β' * (256 / 2)}
#            kwargs = dict(('HTTP_X_OBJECT_META_%s' % quote(k), quote(v)) for
#                          k, v in d.items())
#            r = self.post(url, content_type='', **kwargs)
#            self.assertEqual(r.status_code, 400)
#
#            # Header value too large
#            d = {'α' * 114: 'β' * 256}
#            kwargs = dict(('HTTP_X_OBJECT_META_%s' % quote(k), quote(v)) for
#                          k, v in d.items())
#            r = self.udpate(url, content_type='', **kwargs)
#            self.assertEqual(r.status_code, 400)

    def test_update_object(self):
        block_size = pithos_settings.BACKEND_BLOCK_SIZE
        oname, odata = self.upload_object(
            self.container, length=random.randint(
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1541
                block_size + 2, 2 * block_size))[:2]
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559

        length = len(odata)
        first_byte_pos = random.randint(1, block_size)
        last_byte_pos = random.randint(block_size + 1, length - 1)
        range = 'bytes %s-%s/%s' % (first_byte_pos, last_byte_pos, length)
        kwargs = {'content_type': 'application/octet-stream',
                  'HTTP_CONTENT_RANGE': range}

        url = join_urls(self.pithos_path, self.user, self.container, oname)
        partial = last_byte_pos - first_byte_pos + 1
        data = get_random_data(partial)
        r = self.post(url, data=data, **kwargs)

        self.assertEqual(r.status_code, 204)
        self.assertTrue('ETag' in r)
        updated_data = odata.replace(odata[first_byte_pos: last_byte_pos + 1],
                                     data)
        if pithos_settings.UPDATE_MD5:
1560
            etag = md5_hash(updated_data)
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593
        else:
            etag = merkle(updated_data)
        #self.assertEqual(r['ETag'], etag)

        # check modified object
        r = self.get(url)

        self.assertEqual(r.status_code, 200)
        self.assertEqual(r.content, updated_data)
        self.assertEqual(etag, r['ETag'])

    def test_update_object_divided_by_blocksize(self):
        block_size = pithos_settings.BACKEND_BLOCK_SIZE
        oname, odata = self.upload_object(self.container,
                                          length=2 * block_size)[:2]

        length = len(odata)
        first_byte_pos = block_size
        last_byte_pos = 2 * block_size - 1
        range = 'bytes %s-%s/%s' % (first_byte_pos, last_byte_pos, length)
        kwargs = {'content_type': 'application/octet-stream',
                  'HTTP_CONTENT_RANGE': range}

        url = join_urls(self.pithos_path, self.user, self.container, oname)
        partial = last_byte_pos - first_byte_pos + 1
        data = get_random_data(partial)
        r = self.post(url, data=data, **kwargs)

        self.assertEqual(r.status_code, 204)
        self.assertTrue('ETag' in r)
        updated_data = odata.replace(odata[first_byte_pos: last_byte_pos + 1],
                                     data)
        if pithos_settings.UPDATE_MD5:
1594
            etag = md5_hash(updated_data)
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607