Statistics
| Branch: | Tag: | Revision:

root / kamaki / clients / livetest / pithos.py @ 776b275c

History | View | Annotate | Download (46.4 kB)

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

    
34
import time
35
import datetime
36
from os import urandom
37
from tempfile import NamedTemporaryFile
38
from string import ascii_letters
39

    
40
from kamaki.clients import livetest, ClientError
41
from kamaki.clients.pithos import PithosClient
42
from kamaki.clients.astakos import AstakosClient
43

    
44

    
45
def chargen():
46
    """10 + 2 * 26 + 26 = 88"""
47
    while True:
48
        for CH in xrange(10):
49
            yield '%s' % CH
50
        for CH in ascii_letters:
51
            yield CH
52
        for CH in '~!@#$%^&*()_+`-=:";|<>?,./':
53
            yield CH
54

    
55

    
56
def sample_block(f, block):
57
    block_size = 4 * 1024 * 1024
58
    f.seek(block * block_size)
59
    ch = [f.read(1)]
60
    f.seek(block_size / 2, 1)
61
    ch.append(f.read(1))
62
    f.seek((block + 1) * block_size - 1)
63
    ch.append(f.read(1))
64
    return ch
65

    
66

    
67
class Pithos(livetest.Generic):
68

    
69
    files = []
70

    
71
    def setUp(self):
72
        self.cloud = 'cloud.%s' % self['testcloud']
73
        aurl, self.token = self[self.cloud, 'url'], self[self.cloud, 'token']
74
        self.auth_base = AstakosClient(aurl, self.token)
75
        purl = self.auth_base.get_service_endpoints(
76
            'object-store')['publicURL']
77
        self.uuid = self.auth_base.user_term('id')
78
        self.client = PithosClient(purl, self.token, self.uuid)
79

    
80
        self.now = time.mktime(time.gmtime())
81
        self.now_unformated = datetime.datetime.utcnow()
82
        self._init_data()
83

    
84
        """Prepare an object to be shared - also its container"""
85
        self.client.container = self.c1
86
        self.client.object_post(
87
            'test',
88
            update=True,
89
            permissions={'read': [self.client.account]})
90

    
91
        self.create_remote_object(self.c1, 'another.test')
92

    
93
    def _init_data(self):
94
        self.c1 = 'c1_' + unicode(self.now)
95
        self.c2 = 'c2_' + unicode(self.now)
96
        self.c3 = 'c3_' + unicode(self.now)
97
        try:
98
            self.client.create_container(self.c2)
99
        except ClientError:
100
            pass
101
        try:
102
            self.client.create_container(self.c1)
103
        except ClientError:
104
            pass
105
        try:
106
            self.client.create_container(self.c3)
107
        except ClientError:
108
            pass
109

    
110
        self.create_remote_object(self.c1, 'test')
111
        self.create_remote_object(self.c2, 'test')
112
        self.create_remote_object(self.c1, 'test1')
113
        self.create_remote_object(self.c2, 'test1')
114

    
115
    def create_remote_object(self, container, obj):
116
        self.client.container = container
117
        self.client.object_put(
118
            obj,
119
            content_type='application/octet-stream',
120
            data='file %s that lives in %s' % (obj, container),
121
            metadata={'incontainer': container})
122

    
123
    def forceDeleteContainer(self, container):
124
        self.client.container = container
125
        try:
126
            r = self.client.list_objects()
127
        except ClientError:
128
            return
129
        for obj in r:
130
            name = obj['name']
131
            self.client.del_object(name)
132
        r = self.client.container_delete()
133
        self.container = ''
134

    
135
    def tearDown(self):
136
        """Destroy test cases"""
137
        for f in self.files:
138
            f.close()
139
        self.forceDeleteContainer(self.c1)
140
        self.forceDeleteContainer(self.c2)
141
        try:
142
            self.forceDeleteContainer(self.c3)
143
        except ClientError:
144
            pass
145
        self.client.container = ''
146

    
147
    def test_000(self):
148
        """Prepare a full Pithos+ test"""
149
        print('')
150
        super(self.__class__, self).test_000()
151

    
152
    def test_account_head(self):
153
        """Test account_HEAD"""
154
        self._test_0010_account_head()
155

    
156
    def _test_0010_account_head(self):
157
        r = self.client.account_head()
158
        self.assertEqual(r.status_code, 204)
159

    
160
        r = self.client.account_head(until='1000000000')
161
        self.assertEqual(r.status_code, 204)
162

    
163
        r = self.client.get_account_info(until='1000000000')
164
        datestring = unicode(r['x-account-until-timestamp'])
165
        self.assertEqual(u'Sun, 09 Sep 2001 01:46:40 GMT', datestring)
166

    
167
        r = self.client.get_account_quota()
168
        self.assertTrue('x-account-policy-quota' in r)
169

    
170
        #r = self.client.get_account_versioning()
171
        #self.assertTrue('x-account-policy-versioning' in r)
172

    
173
        """Check if(un)modified_since"""
174
        for format in self.client.DATE_FORMATS:
175
            now_formated = self.now_unformated.strftime(format)
176
            r1 = self.client.account_head(
177
                if_modified_since=now_formated, success=(204, 304, 412))
178
            sc1 = r1.status_code
179
            r2 = self.client.account_head(
180
                if_unmodified_since=now_formated, success=(204, 304, 412))
181
            sc2 = r2.status_code
182
            self.assertNotEqual(sc1, sc2)
183

    
184
    def test_account_get(self):
185
        """Test account_GET"""
186
        self._test_0020_account_get()
187

    
188
    def _test_0020_account_get(self):
189
        #r = self.client.account_get()
190
        #self.assertEqual(r.status_code, 200)
191
        r = self.client.list_containers()
192
        fullLen = len(r)
193
        self.assertTrue(fullLen > 2)
194

    
195
        r = self.client.account_get(limit=1)
196
        self.assertEqual(len(r.json), 1)
197

    
198
        r = self.client.account_get(marker='c2_')
199
        temp_c0 = r.json[0]['name']
200
        temp_c2 = r.json[2]['name']
201

    
202
        r = self.client.account_get(limit=2, marker='c2_')
203
        conames = [container['name'] for container in r.json if (
204
            container['name'].lower().startswith('c2_'))]
205
        self.assertTrue(temp_c0 in conames)
206
        self.assertFalse(temp_c2 in conames)
207

    
208
        r = self.client.account_get(show_only_shared=True)
209
        self.assertTrue(self.c1 in [c['name'] for c in r.json])
210

    
211
        r = self.client.account_get(until=1342609206.0)
212
        self.assertTrue(len(r.json) <= fullLen)
213

    
214
        """Check if(un)modified_since"""
215
        for format in self.client.DATE_FORMATS:
216
            now_formated = self.now_unformated.strftime(format)
217
            r1 = self.client.account_get(
218
                if_modified_since=now_formated, success=(200, 304, 412))
219
            sc1 = r1.status_code
220
            r2 = self.client.account_get(
221
                if_unmodified_since=now_formated, success=(200, 304, 412))
222
            sc2 = r2.status_code
223
            self.assertNotEqual(sc1, sc2)
224

    
225
        """Check sharing_accounts"""
226
        r = self.client.get_sharing_accounts()
227
        self.assertTrue(len(r) > 0)
228

    
229
    def test_account_post(self):
230
        """Test account_POST"""
231
        self._test_0030_account_post()
232

    
233
    def _test_0030_account_post(self):
234
        r = self.client.account_post()
235
        self.assertEqual(r.status_code, 202)
236
        grpName = 'grp' + unicode(self.now)
237

    
238
        """Method set/del_account_meta and set_account_groupcall use
239
            account_post internally
240
        """
241
        u1 = self.client.account
242
        #  Invalid display name
243
        u2 = '1nc0r3c7-d15p14y-n4m3'
244
        #  valid display name
245
        u3 = '6488c1b2-cb06-40a8-a02a-d474b8d29c59'
246
        self.assertRaises(
247
            ClientError,
248
            self.client.set_account_group,
249
            grpName, [u1, u2])
250
        self.client.set_account_group(grpName, [u1])
251
        r = self.client.get_account_group()
252
        self.assertEqual(r['x-account-group-' + grpName], '%s' % u1)
253
        try:
254
            self.client.set_account_group(grpName, [u1, u3])
255
            r = self.client.get_account_group()
256
            self.assertEqual(
257
                r['x-account-group-' + grpName], '%s,%s' % (u1, u3))
258
        except:
259
            print('\tInvalid user id %s (it is ok, though)' % u3)
260
        self.client.del_account_group(grpName)
261
        r = self.client.get_account_group()
262
        self.assertTrue('x-account-group-' + grpName not in r)
263

    
264
        mprefix = 'meta' + unicode(self.now)
265
        self.client.set_account_meta({
266
            mprefix + '1': 'v1', mprefix + '2': 'v2'})
267
        r = self.client.get_account_meta()
268
        self.assertEqual(r['x-account-meta-' + mprefix + '1'], 'v1')
269
        self.assertEqual(r['x-account-meta-' + mprefix + '2'], 'v2')
270

    
271
        self.client.del_account_meta(mprefix + '1')
272
        r = self.client.get_account_meta()
273
        self.assertTrue('x-account-meta-' + mprefix + '1' not in r)
274

    
275
        self.client.del_account_meta(mprefix + '2')
276
        r = self.client.get_account_meta()
277
        self.assertTrue('x-account-meta-' + mprefix + '2' not in r)
278

    
279
        """Missing testing for quota, versioning, because normally
280
        you don't have permissions to modify those at account level
281
        """
282

    
283
        #newquota = 1000000
284
        #self.client.set_account_quota(newquota)
285
        #r = self.client.get_account_info()
286
        #print(unicode(r))
287
        #r = self.client.get_account_quota()
288
        #self.assertEqual(r['x-account-policy-quota'], newquota)
289
        #self.client.set_account_versioning('auto')
290

    
291
    def test_container_head(self):
292
        """Test container_HEAD"""
293
        self._test_0040_container_head()
294

    
295
    def _test_0040_container_head(self):
296
        self.client.container = self.c1
297

    
298
        r = self.client.container_head()
299
        self.assertEqual(r.status_code, 204)
300

    
301
        """Check until"""
302
        r = self.client.container_head(until=1000000, success=(204, 404))
303
        self.assertEqual(r.status_code, 404)
304

    
305
        """Check and if(un)modified_since"""
306
        for format in self.client.DATE_FORMATS:
307
            now_formated = self.now_unformated.strftime(format)
308
            r1 = self.client.container_head(
309
                if_modified_since=now_formated, success=(204, 304, 412))
310
            sc1 = r1.status_code
311
            r2 = self.client.container_head(
312
                if_unmodified_since=now_formated, success=(204, 304, 412))
313
            sc2 = r2.status_code
314
            self.assertNotEqual(sc1, sc2)
315

    
316
        """Check container object meta"""
317
        r = self.client.get_container_object_meta()
318
        self.assertEqual(r['x-container-object-meta'], 'Incontainer')
319

    
320
    def test_container_get(self):
321
        """Test container_GET"""
322
        self._test_0050_container_get()
323

    
324
    def _test_0050_container_get(self):
325
        self.client.container = self.c1
326

    
327
        r = self.client.container_get()
328
        self.assertEqual(r.status_code, 200)
329
        fullLen = len(r.json)
330

    
331
        r = self.client.container_get(prefix='test')
332
        lalobjects = [obj for obj in r.json if obj['name'].startswith('test')]
333
        self.assertTrue(len(r.json) > 1)
334
        self.assertEqual(len(r.json), len(lalobjects))
335

    
336
        r = self.client.container_get(limit=1)
337
        self.assertEqual(len(r.json), 1)
338

    
339
        r = self.client.container_get(marker='another')
340
        self.assertTrue(len(r.json) > 1)
341
        neobjects = [obj for obj in r.json if obj['name'] > 'another']
342
        self.assertEqual(len(r.json), len(neobjects))
343

    
344
        r = self.client.container_get(prefix='another.test', delimiter='.')
345
        self.assertTrue(fullLen > len(r.json))
346

    
347
        r = self.client.container_get(path='/')
348
        self.assertEqual(fullLen, len(r.json))
349

    
350
        r = self.client.container_get(format='xml')
351
        self.assertEqual(r.text.split()[4], 'name="' + self.c1 + '">')
352

    
353
        r = self.client.container_get(meta=['incontainer'])
354
        self.assertTrue(len(r.json) > 0)
355

    
356
        r = self.client.container_get(show_only_shared=True)
357
        self.assertTrue(len(r.json) < fullLen)
358

    
359
        try:
360
            r = self.client.container_get(until=1000000000)
361
            datestring = unicode(r.headers['x-account-until-timestamp'])
362
            self.assertEqual(u'Sun, 09 Sep 2001 01:46:40 GMT', datestring)
363

    
364
        except ClientError:
365

    
366
            pass
367

    
368
        """Check and if un/modified_since"""
369
        for format in self.client.DATE_FORMATS:
370
            now_formated = self.now_unformated.strftime(format)
371
            r1 = self.client.container_get(
372
                if_modified_since=now_formated, success=(200, 304, 412))
373
            sc1 = r1.status_code
374
            r2 = self.client.container_get(
375
                if_unmodified_since=now_formated, success=(200, 304, 412))
376
            sc2 = r2.status_code
377
            self.assertNotEqual(sc1, sc2)
378

    
379
    def test_container_put(self):
380
        """Test container_PUT"""
381
        self._test_0050_container_put()
382

    
383
    def _test_0050_container_put(self):
384
        self.client.container = self.c2
385

    
386
        r = self.client.create_container()
387
        self.assertTrue(isinstance(r, dict))
388

    
389
        r = self.client.get_container_limit(self.client.container)
390
        cquota = r.values()[0]
391
        newquota = 2 * int(cquota)
392

    
393
        r = self.client.create_container(sizelimit=newquota)
394
        self.assertTrue(isinstance(r, dict))
395

    
396
        r = self.client.get_container_limit(self.client.container)
397
        xquota = int(r.values()[0])
398
        self.assertEqual(newquota, xquota)
399

    
400
        r = self.client.create_container(versioning='auto')
401
        self.assertTrue(isinstance(r, dict))
402

    
403
        r = self.client.get_container_versioning(self.client.container)
404
        nvers = r.values()[0]
405
        self.assertEqual('auto', nvers)
406

    
407
        r = self.client.container_put(versioning='none')
408
        self.assertEqual(r.status_code, 202)
409

    
410
        r = self.client.get_container_versioning(self.client.container)
411
        nvers = r.values()[0]
412
        self.assertEqual('none', nvers)
413

    
414
        r = self.client.create_container(metadata={'m1': 'v1', 'm2': 'v2'})
415
        self.assertTrue(isinstance(r, dict))
416

    
417
        r = self.client.get_container_meta(self.client.container)
418
        self.assertTrue('x-container-meta-m1' in r)
419
        self.assertEqual(r['x-container-meta-m1'], 'v1')
420
        self.assertTrue('x-container-meta-m2' in r)
421
        self.assertEqual(r['x-container-meta-m2'], 'v2')
422

    
423
        r = self.client.container_put(metadata={'m1': '', 'm2': 'v2a'})
424
        self.assertEqual(r.status_code, 202)
425

    
426
        r = self.client.get_container_meta(self.client.container)
427
        self.assertTrue('x-container-meta-m1' not in r)
428
        self.assertTrue('x-container-meta-m2' in r)
429
        self.assertEqual(r['x-container-meta-m2'], 'v2a')
430

    
431
        self.client.del_container_meta(self.client.container)
432

    
433
    def test_container_post(self):
434
        """Test container_POST"""
435
        self._test_0060_container_post()
436

    
437
    def _test_0060_container_post(self):
438
        self.client.container = self.c2
439

    
440
        """Simple post"""
441
        r = self.client.container_post()
442
        self.assertEqual(r.status_code, 202)
443

    
444
        """post meta"""
445
        self.client.set_container_meta({'m1': 'v1', 'm2': 'v2'})
446
        r = self.client.get_container_meta(self.client.container)
447
        self.assertTrue('x-container-meta-m1' in r)
448
        self.assertEqual(r['x-container-meta-m1'], 'v1')
449
        self.assertTrue('x-container-meta-m2' in r)
450
        self.assertEqual(r['x-container-meta-m2'], 'v2')
451

    
452
        """post/2del meta"""
453
        r = self.client.del_container_meta('m1')
454
        r = self.client.set_container_meta({'m2': 'v2a'})
455
        r = self.client.get_container_meta(self.client.container)
456
        self.assertTrue('x-container-meta-m1' not in r)
457
        self.assertTrue('x-container-meta-m2' in r)
458
        self.assertEqual(r['x-container-meta-m2'], 'v2a')
459

    
460
        """check quota"""
461
        r = self.client.get_container_limit(self.client.container)
462
        cquota = r.values()[0]
463
        newquota = 2 * int(cquota)
464
        r = self.client.set_container_limit(newquota)
465
        r = self.client.get_container_limit(self.client.container)
466
        xquota = int(r.values()[0])
467
        self.assertEqual(newquota, xquota)
468
        r = self.client.set_container_limit(cquota)
469
        r = self.client.get_container_limit(self.client.container)
470
        xquota = r.values()[0]
471
        self.assertEqual(cquota, xquota)
472

    
473
        """Check versioning"""
474
        self.client.set_container_versioning('auto')
475
        r = self.client.get_container_versioning(self.client.container)
476
        nvers = r.values()[0]
477
        self.assertEqual('auto', nvers)
478
        self.client.set_container_versioning('none')
479
        r = self.client.get_container_versioning(self.client.container)
480
        nvers = r.values()[0]
481
        self.assertEqual('none', nvers)
482

    
483
        """put_block uses content_type and content_length to
484
        post blocks of data 2 container. All that in upload_object"""
485
        """Change a file at fs"""
486
        f = self.create_large_file(1024 * 1024 * 100)
487
        """Upload it at a directory in container"""
488
        self.client.create_directory('dir')
489
        r = self.client.upload_object('/dir/sample.file', f)
490
        for term in ('content-length', 'content-type', 'x-object-version'):
491
            self.assertTrue(term in r)
492
        """Check if file has been uploaded"""
493
        r = self.client.get_object_info('/dir/sample.file')
494
        self.assertTrue(int(r['content-length']) > 100000000)
495

    
496
        """What is tranfer_encoding? What should I check about it? """
497
        #TODO
498

    
499
        """Check update=False"""
500
        r = self.client.object_post(
501
            'test',
502
            update=False,
503
            metadata={'newmeta': 'newval'})
504

    
505
        r = self.client.get_object_info('test')
506
        self.assertTrue('x-object-meta-newmeta' in r)
507
        self.assertFalse('x-object-meta-incontainer' in r)
508

    
509
        r = self.client.del_container_meta('m2')
510

    
511
    def test_container_delete(self):
512
        """Test container_DELETE"""
513
        self._test_0070_container_delete()
514

    
515
    def _test_0070_container_delete(self):
516

    
517
        """Fail to delete a non-empty container"""
518
        self.client.container = self.c2
519
        r = self.client.container_delete(success=409)
520
        self.assertEqual(r.status_code, 409)
521

    
522
        """Fail to delete c3 (empty) container"""
523
        self.client.container = self.c3
524
        r = self.client.container_delete(until='1000000000')
525
        self.assertEqual(r.status_code, 204)
526

    
527
        """Delete c3 (empty) container"""
528
        r = self.client.container_delete()
529
        self.assertEqual(r.status_code, 204)
530

    
531
        """Purge container(empty a container), check versionlist"""
532
        self.client.container = self.c1
533
        r = self.client.object_head('test', success=(200, 404))
534
        self.assertEqual(r.status_code, 200)
535
        self.client.del_container(delimiter='/')
536
        r = self.client.object_head('test', success=(200, 404))
537
        self.assertEqual(r.status_code, 404)
538
        r = self.client.get_object_versionlist('test')
539
        self.assertTrue(len(r) > 0)
540
        self.assertTrue(len(r[0]) > 1)
541
        self.client.purge_container()
542
        self.assertRaises(
543
            ClientError, self.client.get_object_versionlist, 'test')
544

    
545
    def _test_0080_recreate_deleted_data(self):
546
        self._init_data()
547

    
548
    def test_object_head(self):
549
        """Test object_HEAD"""
550
        self._test_0090_object_head()
551

    
552
    def _test_0090_object_head(self):
553
        self.client.container = self.c2
554
        obj = 'test'
555

    
556
        r = self.client.object_head(obj)
557
        self.assertEqual(r.status_code, 200)
558
        etag = r.headers['etag']
559
        real_version = r.headers['x-object-version']
560

    
561
        self.assertRaises(
562
            ClientError, self.client.object_head, obj, version=-10)
563
        r = self.client.object_head(obj, version=real_version)
564
        self.assertEqual(r.headers['x-object-version'], real_version)
565

    
566
        r = self.client.object_head(obj, if_etag_match=etag)
567
        self.assertEqual(r.status_code, 200)
568

    
569
        r = self.client.object_head(
570
            obj, if_etag_not_match=etag, success=(200, 412, 304))
571
        self.assertNotEqual(r.status_code, 200)
572

    
573
        r = self.client.object_head(
574
            obj, version=real_version, if_etag_match=etag, success=200)
575
        self.assertEqual(r.status_code, 200)
576

    
577
        """Check and if(un)modified_since"""
578
        for format in self.client.DATE_FORMATS:
579
            now_formated = self.now_unformated.strftime(format)
580
            r1 = self.client.object_head(
581
                obj, if_modified_since=now_formated, success=(200, 304, 412))
582
            sc1 = r1.status_code
583
            r2 = self.client.object_head(
584
                obj, if_unmodified_since=now_formated, success=(200, 304, 412))
585
            sc2 = r2.status_code
586
            self.assertNotEqual(sc1, sc2)
587

    
588
    def test_object_get(self):
589
        """Test object_GET"""
590
        self._test_0100_object_get()
591

    
592
    def _test_0100_object_get(self):
593
        self.client.container = self.c1
594
        obj = 'test'
595

    
596
        r = self.client.object_get(obj)
597
        self.assertEqual(r.status_code, 200)
598

    
599
        osize = int(r.headers['content-length'])
600
        etag = r.headers['etag']
601

    
602
        r = self.client.object_get(obj, hashmap=True)
603
        for term in ('hashes', 'block_hash', 'block_hash', 'bytes'):
604
            self.assertTrue(term in r.json)
605

    
606
        r = self.client.object_get(obj, format='xml', hashmap=True)
607
        self.assertEqual(len(r.text.split('hash>')), 3)
608

    
609
        rangestr = 'bytes=%s-%s' % (osize / 3, osize / 2)
610
        r = self.client.object_get(
611
            obj, data_range=rangestr, success=(200, 206))
612
        partsize = int(r.headers['content-length'])
613
        self.assertTrue(0 < partsize and partsize <= 1 + osize / 3)
614

    
615
        rangestr = 'bytes=%s-%s' % (osize / 3, osize / 2)
616
        r = self.client.object_get(
617
            obj, data_range=rangestr, if_range=True, success=(200, 206))
618
        partsize = int(r.headers['content-length'])
619
        self.assertTrue(0 < partsize and partsize <= 1 + osize / 3)
620

    
621
        r = self.client.object_get(obj, if_etag_match=etag)
622
        self.assertEqual(r.status_code, 200)
623

    
624
        r = self.client.object_get(obj, if_etag_not_match=etag + 'LALALA')
625
        self.assertEqual(r.status_code, 200)
626

    
627
        """Check and if(un)modified_since"""
628
        for format in self.client.DATE_FORMATS:
629
            now_formated = self.now_unformated.strftime(format)
630
            r1 = self.client.object_get(
631
                obj, if_modified_since=now_formated, success=(200, 304, 412))
632
            sc1 = r1.status_code
633
            r2 = self.client.object_get(
634
                obj, if_unmodified_since=now_formated, success=(200, 304, 412))
635
            sc2 = r2.status_code
636
            self.assertNotEqual(sc1, sc2)
637

    
638
        """Upload an object to download"""
639
        container_info_cache = dict()
640
        trg_fname = 'remotefile_%s' % self.now
641
        f_size = 59247824
642
        src_f = self.create_large_file(f_size)
643
        print('\tUploading...')
644
        r = self.client.upload_object(
645
            trg_fname, src_f, container_info_cache=container_info_cache)
646
        print('\tDownloading...')
647
        self.files.append(NamedTemporaryFile())
648
        dnl_f = self.files[-1]
649
        self.client.download_object(trg_fname, dnl_f)
650

    
651
        print('\tCheck if files match...')
652
        for pos in (0, f_size / 2, f_size - 128):
653
            src_f.seek(pos)
654
            dnl_f.seek(pos)
655
            self.assertEqual(src_f.read(64), dnl_f.read(64))
656

    
657
        print('\tDownload KiBs to string and check again...')
658
        for pos in (0, f_size / 2, f_size - 256):
659
            src_f.seek(pos)
660
            tmp_s = self.client.download_to_string(
661
                trg_fname, range_str='%s-%s' % (pos, (pos + 128)))
662
            self.assertEqual(tmp_s, src_f.read(len(tmp_s)))
663
        print('\tUploading KiBs as strings...')
664
        trg_fname = 'fromString_%s' % self.now
665
        src_size = 2 * 1024
666
        src_f.seek(0)
667
        src_str = src_f.read(src_size)
668
        self.client.upload_from_string(trg_fname, src_str)
669
        print('\tDownload as string and check...')
670
        tmp_s = self.client.download_to_string(trg_fname)
671
        self.assertEqual(tmp_s, src_str)
672

    
673
        """Upload a boring file"""
674
        trg_fname = 'boringfile_%s' % self.now
675
        src_f = self.create_boring_file(42)
676
        print('\tUploading boring file...')
677
        self.client.upload_object(
678
            trg_fname, src_f, container_info_cache=container_info_cache)
679
        print('\tDownloading boring file...')
680
        self.files.append(NamedTemporaryFile())
681
        dnl_f = self.files[-1]
682
        self.client.download_object(trg_fname, dnl_f)
683

    
684
        print('\tCheck if files match...')
685
        for i in range(42):
686
            self.assertEqual(sample_block(src_f, i), sample_block(dnl_f, i))
687

    
688
    def test_object_put(self):
689
        """Test object_PUT"""
690
        self._test_object_put()
691

    
692
    def _test_object_put(self):
693
        self.client.container = self.c2
694
        obj = 'another.test'
695

    
696
        self.client.create_object(obj + '.FAKE')
697
        r = self.client.get_object_info(obj + '.FAKE')
698
        self.assertEqual(r['content-type'], 'application/octet-stream')
699

    
700
        """create the object"""
701
        r = self.client.object_put(
702
            obj,
703
            data='a',
704
            content_type='application/octer-stream',
705
            permissions=dict(
706
                read=['accX:groupA', 'u1', 'u2'],
707
                write=['u2', 'u3']),
708
            metadata=dict(key1='val1', key2='val2'),
709
            content_encoding='UTF-8',
710
            content_disposition='attachment; filename="fname.ext"')
711
        self.assertEqual(r.status_code, 201)
712
        etag = r.headers['etag']
713

    
714
        """Check content-disposition"""
715
        r = self.client.get_object_info(obj)
716
        self.assertTrue('content-disposition' in r)
717

    
718
        """Check permissions"""
719
        r = self.client.get_object_sharing(obj)
720
        self.assertTrue('accx:groupa' in r['read'])
721
        self.assertTrue('u1' in r['read'])
722
        self.assertTrue('u2' in r['write'])
723
        self.assertTrue('u3' in r['write'])
724

    
725
        """Check metadata"""
726
        r = self.client.get_object_meta(obj)
727
        self.assertEqual(r['x-object-meta-key1'], 'val1')
728
        self.assertEqual(r['x-object-meta-key2'], 'val2')
729

    
730
        """Check public and if_etag_match"""
731
        r = self.client.object_put(
732
            obj,
733
            if_etag_match=etag,
734
            data='b',
735
            content_type='application/octet-stream',
736
            public=True)
737

    
738
        r = self.client.object_get(obj)
739
        self.assertTrue('x-object-public' in r.headers)
740
        vers2 = int(r.headers['x-object-version'])
741
        etag = r.headers['etag']
742
        self.assertEqual(r.text, 'b')
743

    
744
        """Check if_etag_not_match"""
745
        r = self.client.object_put(
746
            obj,
747
            if_etag_not_match=etag,
748
            data='c',
749
            content_type='application/octet-stream',
750
            success=(201, 412))
751
        self.assertEqual(r.status_code, 412)
752

    
753
        """Check content_type and content_length"""
754
        tmpdir = 'dir' + unicode(self.now)
755
        r = self.client.object_put(
756
            tmpdir, content_type='application/directory', content_length=0)
757

    
758
        r = self.client.get_object_info(tmpdir)
759
        self.assertEqual(r['content-type'], 'application/directory')
760

    
761
        """Check copy_from, content_encoding"""
762
        r = self.client.object_put(
763
            '%s/%s' % (tmpdir, obj),
764
            format=None,
765
            copy_from='/%s/%s' % (self.client.container, obj),
766
            content_encoding='application/octet-stream',
767
            source_account=self.client.account,
768
            content_length=0,
769
            success=201)
770
        self.assertEqual(r.status_code, 201)
771

    
772
        """Test copy_object for cross-conctainer copy"""
773
        self.client.copy_object(
774
            src_container=self.c2,
775
            src_object='%s/%s' % (tmpdir, obj),
776
            dst_container=self.c1,
777
            dst_object=obj)
778
        self.client.container = self.c1
779
        r1 = self.client.get_object_info(obj)
780
        self.client.container = self.c2
781
        r2 = self.client.get_object_info('%s/%s' % (tmpdir, obj))
782
        self.assertEqual(r1['x-object-hash'], r2['x-object-hash'])
783

    
784
        """Check cross-container copy_from, content_encoding"""
785
        self.client.container = self.c1
786
        fromstr = '/%s/%s/%s' % (self.c2, tmpdir, obj)
787
        r = self.client.object_put(
788
            obj,
789
            format=None,
790
            copy_from=fromstr,
791
            content_encoding='application/octet-stream',
792
            source_account=self.client.account,
793
            content_length=0,
794
            success=201)
795

    
796
        self.assertEqual(r.status_code, 201)
797
        r = self.client.get_object_info(obj)
798
        self.assertEqual(r['etag'], etag)
799

    
800
        """Check source_account"""
801
        self.client.container = self.c2
802
        fromstr = '/%s/%s' % (self.c1, obj)
803
        r = self.client.object_put(
804
            '%sv2' % obj,
805
            format=None,
806
            move_from=fromstr,
807
            content_encoding='application/octet-stream',
808
            source_account='nonExistendAddress@NeverLand.com',
809
            content_length=0,
810
            success=(201, 403))
811
        self.assertEqual(r.status_code, 403)
812

    
813
        """Check cross-container move_from"""
814
        self.client.container = self.c1
815
        r1 = self.client.get_object_info(obj)
816
        self.client.container = self.c2
817
        self.client.move_object(
818
            src_container=self.c1,
819
            src_object=obj,
820
            dst_container=self.c2,
821
            dst_object=obj + 'v0')
822
        r0 = self.client.get_object_info(obj + 'v0')
823
        self.assertEqual(r1['x-object-hash'], r0['x-object-hash'])
824

    
825
        """Check move_from"""
826
        r = self.client.object_put(
827
            '%sv1' % obj,
828
            format=None,
829
            move_from='/%s/%s' % (self.c2, obj),
830
            source_version=vers2,
831
            content_encoding='application/octet-stream',
832
            content_length=0, success=201)
833

    
834
        """Check manifest"""
835
        mobj = 'manifest.test'
836
        txt = ''
837
        for i in range(10):
838
            txt += '%s' % i
839
            r = self.client.object_put(
840
                '%s/%s' % (mobj, i),
841
                data='%s' % i,
842
                content_length=1,
843
                success=201,
844
                content_type='application/octet-stream',
845
                content_encoding='application/octet-stream')
846

    
847
        r = self.client.object_put(
848
            mobj,
849
            content_length=0,
850
            content_type='application/octet-stream',
851
            manifest='%s/%s' % (self.client.container, mobj))
852

    
853
        r = self.client.object_get(mobj)
854
        self.assertEqual(r.text, txt)
855

    
856
        """Upload a local file with one request"""
857
        newf = self.create_large_file(1024 * 10)
858
        self.client.upload_object('sample.file', newf)
859
        """Check if file has been uploaded"""
860
        r = self.client.get_object_info('sample.file')
861
        self.assertEqual(int(r['content-length']), 10240)
862

    
863
        """Some problems with transfer-encoding?"""
864

    
865
    def test_object_copy(self):
866
        """Test object_COPY"""
867
        self._test_0110_object_copy()
868

    
869
    def _test_0110_object_copy(self):
870
        #  TODO: check with source_account option
871
        self.client.container = self.c2
872
        obj = 'test2'
873

    
874
        data = '{"key1":"val1", "key2":"val2"}'
875
        r = self.client.object_put(
876
            '%sorig' % obj,
877
            content_type='application/octet-stream',
878
            data=data,
879
            metadata=dict(mkey1='mval1', mkey2='mval2'),
880
            permissions=dict(
881
                read=['accX:groupA', 'u1', 'u2'],
882
                write=['u2', 'u3']),
883
            content_disposition='attachment; filename="fname.ext"')
884

    
885
        r = self.client.object_copy(
886
            '%sorig' % obj,
887
            destination='/%s/%s' % (self.client.container, obj),
888
            ignore_content_type=False, content_type='application/json',
889
            metadata={'mkey2': 'mval2a', 'mkey3': 'mval3'},
890
            permissions={'write': ['u5', 'accX:groupB']})
891
        self.assertEqual(r.status_code, 201)
892

    
893
        """Check content-disposition"""
894
        r = self.client.get_object_info(obj)
895
        self.assertTrue('content-disposition' in r)
896

    
897
        """Check Metadata"""
898
        r = self.client.get_object_meta(obj)
899
        self.assertEqual(r['x-object-meta-mkey1'], 'mval1')
900
        self.assertEqual(r['x-object-meta-mkey2'], 'mval2a')
901
        self.assertEqual(r['x-object-meta-mkey3'], 'mval3')
902

    
903
        """Check permissions"""
904
        r = self.client.get_object_sharing(obj)
905
        self.assertFalse('read' in r or 'u2' in r['write'])
906
        self.assertTrue('accx:groupb' in r['write'])
907

    
908
        """Check destination account"""
909
        r = self.client.object_copy(
910
            obj,
911
            destination='/%s/%s' % (self.c1, obj),
912
            content_encoding='utf8',
913
            content_type='application/json',
914
            destination_account='nonExistendAddress@NeverLand.com',
915
            success=(201, 403))
916
        self.assertEqual(r.status_code, 403)
917

    
918
        """Check destination being another container
919
        and also content_type and content encoding"""
920
        r = self.client.object_copy(
921
            obj,
922
            destination='/%s/%s' % (self.c1, obj),
923
            content_encoding='utf8',
924
            content_type='application/json')
925
        self.assertEqual(r.status_code, 201)
926
        self.assertEqual(
927
            r.headers['content-type'],
928
            'application/json; charset=UTF-8')
929

    
930
        """Check ignore_content_type and content_type"""
931
        r = self.client.object_get(obj)
932
        etag = r.headers['etag']
933
        ctype = r.headers['content-type']
934
        self.assertEqual(ctype, 'application/json')
935

    
936
        r = self.client.object_copy(
937
            '%sorig' % obj,
938
            destination='/%s/%s0' % (self.client.container, obj),
939
            ignore_content_type=True,
940
            content_type='application/json')
941
        self.assertEqual(r.status_code, 201)
942
        self.assertNotEqual(r.headers['content-type'], 'application/json')
943

    
944
        """Check if_etag_(not_)match"""
945
        r = self.client.object_copy(
946
            obj,
947
            destination='/%s/%s1' % (self.client.container, obj),
948
            if_etag_match=etag)
949
        self.assertEqual(r.status_code, 201)
950

    
951
        r = self.client.object_copy(
952
            obj,
953
            destination='/%s/%s2' % (self.client.container, obj),
954
            if_etag_not_match='lalala')
955
        self.assertEqual(r.status_code, 201)
956
        vers2 = r.headers['x-object-version']
957

    
958
        """Check source_version, public and format """
959
        r = self.client.object_copy(
960
            '%s2' % obj,
961
            destination='/%s/%s3' % (self.client.container, obj),
962
            source_version=vers2,
963
            format='xml',
964
            public=True)
965
        self.assertEqual(r.status_code, 201)
966
        self.assertTrue(r.headers['content-type'].index('xml') > 0)
967

    
968
        r = self.client.get_object_info(obj + '3')
969
        self.assertTrue('x-object-public' in r)
970

    
971
    def test_object_move(self):
972
        """Test object_MOVE"""
973
        self._test_0120_object_move()
974

    
975
    def _test_0120_object_move(self):
976
        self.client.container = self.c2
977
        obj = 'test2'
978

    
979
        data = '{"key1": "val1", "key2": "val2"}'
980
        r = self.client.object_put(
981
            '%sorig' % obj,
982
            content_type='application/octet-stream',
983
            data=data,
984
            metadata=dict(mkey1='mval1', mkey2='mval2'),
985
            permissions=dict(
986
                read=['accX:groupA', 'u1', 'u2'],
987
                write=['u2', 'u3']))
988

    
989
        r = self.client.object_move(
990
            '%sorig' % obj,
991
            destination='/%s/%s' % (self.client.container, obj),
992
            ignore_content_type=False,
993
            content_type='application/json',
994
            metadata=dict(mkey2='mval2a', mkey3='mval3'),
995
            permissions=dict(write=['u5', 'accX:groupB']))
996
        self.assertEqual(r.status_code, 201)
997

    
998
        """Check Metadata"""
999
        r = self.client.get_object_meta(obj)
1000
        self.assertEqual(r['x-object-meta-mkey1'], 'mval1')
1001
        self.assertEqual(r['x-object-meta-mkey2'], 'mval2a')
1002
        self.assertEqual(r['x-object-meta-mkey3'], 'mval3')
1003

    
1004
        """Check permissions"""
1005
        r = self.client.get_object_sharing(obj)
1006
        self.assertFalse('read' in r)
1007
        self.assertTrue('u5' in r['write'])
1008
        self.assertTrue('accx:groupb' in r['write'])
1009

    
1010
        """Check destination account"""
1011
        r = self.client.object_move(
1012
            obj,
1013
            destination='/%s/%s' % (self.c1, obj),
1014
            content_encoding='utf8',
1015
            content_type='application/json',
1016
            destination_account='nonExistendAddress@NeverLand.com',
1017
            success=(201, 403))
1018
        self.assertEqual(r.status_code, 403)
1019

    
1020
        """Check destination being another container and also
1021
        content_type, content_disposition and content encoding"""
1022
        r = self.client.object_move(
1023
            obj,
1024
            destination='/%s/%s' % (self.c1, obj),
1025
            content_encoding='utf8',
1026
            content_type='application/json',
1027
            content_disposition='attachment; filename="fname.ext"')
1028
        self.assertEqual(r.status_code, 201)
1029
        self.assertEqual(
1030
            r.headers['content-type'],
1031
            'application/json; charset=UTF-8')
1032
        self.client.container = self.c1
1033
        r = self.client.get_object_info(obj)
1034
        self.assertTrue('content-disposition' in r)
1035
        self.assertTrue('fname.ext' in r['content-disposition'])
1036
        etag = r['etag']
1037
        ctype = r['content-type']
1038
        self.assertEqual(ctype, 'application/json')
1039

    
1040
        """Check ignore_content_type and content_type"""
1041
        r = self.client.object_move(
1042
            obj,
1043
            destination='/%s/%s' % (self.c2, obj),
1044
            ignore_content_type=True,
1045
            content_type='application/json')
1046
        self.assertEqual(r.status_code, 201)
1047
        self.assertNotEqual(r.headers['content-type'], 'application/json')
1048

    
1049
        """Check if_etag_(not_)match"""
1050
        self.client.container = self.c2
1051
        r = self.client.object_move(
1052
            obj,
1053
            destination='/%s/%s0' % (self.client.container, obj),
1054
            if_etag_match=etag)
1055
        self.assertEqual(r.status_code, 201)
1056

    
1057
        r = self.client.object_move(
1058
            '%s0' % obj,
1059
            destination='/%s/%s1' % (self.client.container, obj),
1060
            if_etag_not_match='lalala')
1061
        self.assertEqual(r.status_code, 201)
1062

    
1063
        """Check public and format """
1064
        r = self.client.object_move(
1065
            '%s1' % obj,
1066
            destination='/%s/%s2' % (self.client.container, obj),
1067
            format='xml',
1068
            public=True)
1069
        self.assertEqual(r.status_code, 201)
1070
        self.assertTrue(r.headers['content-type'].index('xml') > 0)
1071

    
1072
        r = self.client.get_object_info(obj + '2')
1073
        self.assertTrue('x-object-public' in r)
1074

    
1075
    def test_object_post(self):
1076
        """Test object_POST"""
1077
        self._test_0130_object_post()
1078

    
1079
    def _test_0130_object_post(self):
1080
        self.client.container = self.c2
1081
        obj = 'test2'
1082

    
1083
        """create a filesystem file"""
1084
        self.files.append(NamedTemporaryFile())
1085
        newf = self.files[-1]
1086
        newf.writelines([
1087
            'ello!\n',
1088
            'This is a test line\n',
1089
            'inside a test file\n'])
1090

    
1091
        """create a file on container"""
1092
        r = self.client.object_put(
1093
            obj,
1094
            content_type='application/octet-stream',
1095
            data='H',
1096
            metadata=dict(mkey1='mval1', mkey2='mval2'),
1097
            permissions=dict(
1098
                read=['accX:groupA', 'u1', 'u2'],
1099
                write=['u2', 'u3']))
1100

    
1101
        """Append livetest update, content_[range|type|length]"""
1102
        newf.seek(0)
1103
        self.client.append_object(obj, newf)
1104
        r = self.client.object_get(obj)
1105
        self.assertTrue(r.text.startswith('Hello!'))
1106

    
1107
        """Overwrite livetest update,
1108
            content_type, content_length, content_range
1109
        """
1110
        newf.seek(0)
1111
        r = self.client.overwrite_object(obj, 0, 10, newf)
1112
        r = self.client.object_get(obj)
1113
        self.assertTrue(r.text.startswith('ello!'))
1114

    
1115
        """Truncate livetest update,
1116
            content_range, content_type, object_bytes and source_object"""
1117
        r = self.client.truncate_object(obj, 5)
1118
        r = self.client.object_get(obj)
1119
        self.assertEqual(r.text, 'ello!')
1120

    
1121
        """Check metadata"""
1122
        self.client.set_object_meta(obj, {'mkey2': 'mval2a', 'mkey3': 'mval3'})
1123
        r = self.client.get_object_meta(obj)
1124
        self.assertEqual(r['x-object-meta-mkey1'], 'mval1')
1125
        self.assertEqual(r['x-object-meta-mkey2'], 'mval2a')
1126
        self.assertEqual(r['x-object-meta-mkey3'], 'mval3')
1127
        self.client.del_object_meta(obj, 'mkey1')
1128
        r = self.client.get_object_meta(obj)
1129
        self.assertFalse('x-object-meta-mkey1' in r)
1130

    
1131
        """Check permissions"""
1132
        self.client.set_object_sharing(
1133
            obj, read_permission=['u4', 'u5'], write_permission=['u4'])
1134
        r = self.client.get_object_sharing(obj)
1135
        self.assertTrue('read' in r)
1136
        self.assertTrue('u5' in r['read'])
1137
        self.assertTrue('write' in r)
1138
        self.assertTrue('u4' in r['write'])
1139
        self.client.del_object_sharing(obj)
1140
        r = self.client.get_object_sharing(obj)
1141
        self.assertTrue(len(r) == 0)
1142

    
1143
        """Check publish"""
1144
        self.client.publish_object(obj)
1145
        r = self.client.get_object_info(obj)
1146
        self.assertTrue('x-object-public' in r)
1147
        self.client.unpublish_object(obj)
1148
        r = self.client.get_object_info(obj)
1149
        self.assertFalse('x-object-public' in r)
1150

    
1151
        """Check if_etag_(not)match"""
1152
        etag = r['etag']
1153
        r = self.client.object_post(
1154
            obj,
1155
            update=True,
1156
            public=True,
1157
            if_etag_not_match=etag,
1158
            success=(412, 202, 204))
1159
        #self.assertEqual(r.status_code, 412)
1160

    
1161
        r = self.client.object_post(
1162
            obj,
1163
            update=True,
1164
            public=True,
1165
            if_etag_match=etag,
1166
            content_encoding='application/json')
1167

    
1168
        r = self.client.get_object_info(obj)
1169
        helloVersion = r['x-object-version']
1170
        self.assertTrue('x-object-public' in r)
1171
        self.assertEqual(r['content-encoding'], 'application/json')
1172

    
1173
        """Check source_version and source_account and content_disposition"""
1174
        r = self.client.object_post(
1175
            obj,
1176
            update=True,
1177
            content_type='application/octet-srteam',
1178
            content_length=5,
1179
            content_range='bytes 1-5/*',
1180
            source_object='/%s/%s' % (self.c2, obj),
1181
            source_account='thisAccountWillNeverExist@adminland.com',
1182
            source_version=helloVersion,
1183
            data='12345',
1184
            success=(403, 202, 204))
1185
        self.assertEqual(r.status_code, 403)
1186

    
1187
        r = self.client.object_post(
1188
            obj,
1189
            update=True,
1190
            content_type='application/octet-srteam',
1191
            content_length=5,
1192
            content_range='bytes 1-5/*',
1193
            source_object='/%s/%s' % (self.c2, obj),
1194
            source_account=self.client.account,
1195
            source_version=helloVersion,
1196
            data='12345',
1197
            content_disposition='attachment; filename="fname.ext"')
1198

    
1199
        r = self.client.object_get(obj)
1200
        self.assertEqual(r.text, 'eello!')
1201
        self.assertTrue('content-disposition' in r.headers)
1202
        self.assertTrue('fname.ext' in r.headers['content-disposition'])
1203

    
1204
        """Check manifest"""
1205
        mobj = 'manifest.test'
1206
        txt = ''
1207
        for i in range(10):
1208
            txt += '%s' % i
1209
            r = self.client.object_put(
1210
                '%s/%s' % (mobj, i),
1211
                data='%s' % i,
1212
                content_length=1,
1213
                success=201,
1214
                content_encoding='application/octet-stream',
1215
                content_type='application/octet-stream')
1216

    
1217
        self.client.create_object_by_manifestation(
1218
            mobj, content_type='application/octet-stream')
1219

    
1220
        r = self.client.object_post(
1221
            mobj, manifest='%s/%s' % (self.client.container, mobj))
1222

    
1223
        r = self.client.object_get(mobj)
1224
        self.assertEqual(r.text, txt)
1225

    
1226
        """We need to check transfer_encoding """
1227

    
1228
    def test_object_delete(self):
1229
        """Test object_DELETE"""
1230
        self._test_0140_object_delete()
1231

    
1232
    def _test_0140_object_delete(self):
1233
        self.client.container = self.c2
1234
        obj = 'test2'
1235
        """create a file on container"""
1236
        r = self.client.object_put(
1237
            obj,
1238
            content_type='application/octet-stream',
1239
            data='H',
1240
            metadata=dict(mkey1='mval1', mkey2='mval2'),
1241
            permissions=dict(
1242
                read=['accX:groupA', 'u1', 'u2'],
1243
                write=['u2', 'u3']))
1244

    
1245
        """Check with false until"""
1246
        r = self.client.object_delete(obj, until=1000000)
1247

    
1248
        r = self.client.object_get(obj, success=(200, 404))
1249
        self.assertEqual(r.status_code, 200)
1250

    
1251
        """Check normal case"""
1252
        r = self.client.object_delete(obj)
1253
        self.assertEqual(r.status_code, 204)
1254

    
1255
        r = self.client.object_get(obj, success=(200, 404))
1256
        self.assertEqual(r.status_code, 404)
1257

    
1258
    def create_large_file(self, size):
1259
        """Create a large file at fs"""
1260
        print
1261
        self.files.append(NamedTemporaryFile())
1262
        f = self.files[-1]
1263
        Ki = size / 8
1264
        bytelist = [b * Ki for b in range(size / Ki)]
1265

    
1266
        def append2file(step):
1267
            f.seek(step)
1268
            f.write(urandom(Ki))
1269
            f.flush()
1270
        self.do_with_progress_bar(
1271
            append2file,
1272
            ' create rand file %s (%sB): ' % (f.name, size),
1273
            bytelist)
1274
        f.seek(0)
1275
        return f
1276

    
1277
    def create_boring_file(self, num_of_blocks):
1278
        """Create a file with some blocks being the same"""
1279
        self.files.append(NamedTemporaryFile())
1280
        tmpFile = self.files[-1]
1281
        block_size = 4 * 1024 * 1024
1282
        print('\n\tCreate boring file of %s blocks' % num_of_blocks)
1283
        chars = chargen()
1284
        while num_of_blocks:
1285
            fslice = 3 if num_of_blocks > 3 else num_of_blocks
1286
            tmpFile.write(fslice * block_size * chars.next())
1287
            num_of_blocks -= fslice
1288
        print('\t\tDone')
1289
        tmpFile.seek(0)
1290
        return tmpFile