Revision 3c216009

b/kamaki/clients/pithos/__init__.py
112 112
            'write':[usr and/or grp names]}
113 113

  
114 114
        :param public: (bool)
115

  
116
        :returns: (dict) created object metadata
115 117
        """
116 118
        self._assert_container()
117 119

  
......
128 130
            f = StringIO(data)
129 131
        else:
130 132
            data = f.read(size) if size else f.read()
131
        self.object_put(
133
        r = self.object_put(
132 134
            obj,
133 135
            data=data,
134 136
            etag=etag,
......
138 140
            permissions=sharing,
139 141
            public=public,
140 142
            success=201)
143
        return r.headers
141 144

  
142 145
    def create_object_by_manifestation(
143 146
            self, obj,
......
162 165
            'write':[usr and/or grp names]}
163 166

  
164 167
        :param public: (bool)
168

  
169
        :returns: (dict) created object metadata
165 170
        """
166 171
        self._assert_container()
167
        self.object_put(
172
        r = self.object_put(
168 173
            obj,
169 174
            content_length=0,
170 175
            etag=etag,
......
174 179
            permissions=sharing,
175 180
            public=public,
176 181
            manifest='%s/%s' % (self.container, obj))
182
        return r.headers
177 183

  
178 184
    # upload_* auxiliary methods
179 185
    def _put_block_async(self, data, hash, upload_gen=None):
......
224 230
            permissions=permissions,
225 231
            public=public,
226 232
            success=success)
227
        return None if r.status_code == 201 else r.json
233
        return (None if r.status_code == 201 else r.json), r.headers
228 234

  
229 235
    def _calculate_blocks_for_upload(
230 236
            self, blocksize, blockhash, size, nblocks, hashes, hmap, fileobj,
......
350 356
            hash_cb=hash_cb)
351 357

  
352 358
        hashmap = dict(bytes=size, hashes=hashes)
353
        missing = self._create_or_get_missing_hashes(
359
        missing, obj_headers = self._create_or_get_missing_hashes(
354 360
            obj, hashmap,
355 361
            content_type=content_type,
356 362
            size=size,
......
362 368
            public=public)
363 369

  
364 370
        if missing is None:
365
            return
371
            return obj_headers
366 372

  
367 373
        if upload_cb:
368 374
            upload_gen = upload_cb(len(missing))
......
401 407
                thread.join()
402 408
            raise
403 409

  
404
        self.object_put(
410
        r = self.object_put(
405 411
            obj,
406 412
            format='json',
407 413
            hashmap=True,
......
413 419
            permissions=sharing,
414 420
            public=public,
415 421
            success=201)
422
        return r.headers
416 423

  
417 424
    # download_* auxiliary methods
418 425
    def _get_remote_blocks_info(self, obj, **restargs):
b/kamaki/clients/pithos/test.py
821 821
        tmpFile = self._create_temp_file(num_of_blocks)
822 822

  
823 823
        # Without kwargs
824
        self.client.upload_object(obj, tmpFile)
824
        exp_headers = dict(id='container id', name='container name')
825
        FR.headers = dict(exp_headers)
826
        r = self.client.upload_object(obj, tmpFile)
827
        self.assert_dicts_are_equal(r, exp_headers)
825 828
        self.assertEqual(GCI.mock_calls[-1], call())
826 829
        [call1, call2] = OP.mock_calls
827 830

  
......
888 891
                yield
889 892

  
890 893
            tmpFile.seek(0)
891
            self.client.upload_object(
894
            r = self.client.upload_object(
892 895
                obj, tmpFile,
893 896
                hash_cb=blck_gen, upload_cb=upld_gen)
897
            self.assert_dicts_are_equal(r, exp_headers)
894 898

  
895 899
            for i, c in enumerate(OP.mock_calls[-mock_offset:]):
896 900
                self.assertEqual(OP.mock_calls[i], c)
......
899 903
        tmpFile.seek(0)
900 904
        ctype = 'video/mpeg'
901 905
        sharing = dict(read=['u1', 'g1', 'u2'], write=['u1'])
902
        self.client.upload_object(obj, tmpFile,
906
        r = self.client.upload_object(obj, tmpFile,
903 907
            content_type=ctype, sharing=sharing)
908
        self.assert_dicts_are_equal(r, exp_headers)
904 909
        self.assertEqual(OP.mock_calls[-1][2]['content_type'], ctype)
905 910
        self.assert_dicts_are_equal(
906 911
            OP.mock_calls[-2][2]['permissions'],
......
916 921
            content_disposition=ctype + 'd15p051710n',
917 922
            public=True,
918 923
            content_encoding='802.11')
919
        self.client.upload_object(obj, tmpFile, **kwargs)
924
        r = self.client.upload_object(obj, tmpFile, **kwargs)
925
        self.assert_dicts_are_equal(r, exp_headers)
926

  
920 927
        kwargs.pop('if_not_exist')
921 928
        ematch = kwargs.pop('if_etag_match')
922 929
        etag = kwargs.pop('etag')
......
1044 1051
                content_disposition='some content_disposition',
1045 1052
                public=True,
1046 1053
                permissions=dict(read=['u1', 'g1', 'u2'], write=['u1']))
1047
        self.client.upload_object_unchunked(obj, tmpFile)
1054
        r = self.client.upload_object_unchunked(obj, tmpFile)
1055
        self.assert_dicts_are_equal(r, FR.headers)
1048 1056
        self.assertEqual(put.mock_calls[-1][1], (obj,))
1049 1057
        self.assertEqual(
1050 1058
            sorted(put.mock_calls[-1][2].keys()),
......
1054 1062
        kwargs['size'] = kwargs.pop('data')
1055 1063
        kwargs['sharing'] = kwargs.pop('permissions')
1056 1064
        tmpFile.seek(0)
1057
        self.client.upload_object_unchunked(obj, tmpFile, **kwargs)
1065
        r = self.client.upload_object_unchunked(obj, tmpFile, **kwargs)
1066
        self.assert_dicts_are_equal(r, FR.headers)
1058 1067
        pmc = put.mock_calls[-1][2]
1059 1068
        for k, v in expected.items():
1060 1069
            if k == 'data':
......
1076 1085
                content_disposition='some content_disposition',
1077 1086
                public=True,
1078 1087
                sharing=dict(read=['u1', 'g1', 'u2'], write=['u1']))
1079
        self.client.create_object_by_manifestation(obj)
1088
        r = self.client.create_object_by_manifestation(obj)
1089
        self.assert_dicts_are_equal(r, FR.headers)
1080 1090
        expected = dict(content_length=0, manifest=manifest)
1081 1091
        for k in kwargs:
1082 1092
            expected['permissions' if k == 'sharing' else k] = None
1083 1093
        self.assertEqual(put.mock_calls[-1], call(obj, **expected))
1084
        self.client.create_object_by_manifestation(obj, **kwargs)
1094
        r = self.client.create_object_by_manifestation(obj, **kwargs)
1095
        self.assert_dicts_are_equal(r, FR.headers)
1085 1096
        expected.update(kwargs)
1086 1097
        expected['permissions'] = expected.pop('sharing')
1087 1098
        self.assertEqual(put.mock_calls[-1], call(obj, **expected))

Also available in: Unified diff