Revision e161c24f snf-pithos-app/pithos/api/test/listing.py

b/snf-pithos-app/pithos/api/test/listing.py
47 47
            self.upload_object(cname, 'obj', user=user)
48 48
            self.create_folder(cname, 'f1', user=user)
49 49
            self.create_folder(cname, 'f1/f2', user=user)
50
            self.upload_object(cname, 'f1/f2/obj', user=user)
50
            self.create_folder(cname, 'f1/f2/f3', user=user)
51
            self.upload_object(cname, 'f1/f2/f3/obj', user=user)
51 52

  
52 53
        # share /c0/f1 path for read
53 54
        url = join_urls(self.pithos_path, user, 'c0', 'f1')
......
92 93
        self.assertEqual([i['name'] for i in allowed_containers], ['c0'])
93 94

  
94 95
        url = join_urls(url, 'c0')
95
        r = self.get('%s?delimiter=/&shared=&format=json' % url)
96
        r = self.get('%s?delimiter=/&shared=&' % url)
96 97
        self.assertEqual(r.status_code, 200)
97
        shared_objects = [i.get('name', i.get('subdir')) for i in
98
                          json.loads(r.content)]
98
        shared_objects = r.content.split('\n')
99
        if '' in shared_objects:
100
            shared_objects.remove('')
99 101
        self.assertEqual(shared_objects, ['f1', 'f1/'])
100 102

  
103
        r = self.get('%s?delimiter=/&shared=&format=json' % url)
104
        self.assertEqual(r.status_code, 200)
105
        shared_objects = json.loads(r.content)
106
        self.assertEqual([o.get('name', o.get('subdir')) for
107
                          o in shared_objects],
108
                         ['f1', 'f1/'])
109
        folder = (o for o in shared_objects if o['name'] == 'f1').next()
110
        self.assertTrue('x_object_sharing' in folder)
111
        self.assertTrue(folder['x_object_sharing'] == 'read=*')
112

  
113
        r = self.get('%s?delimiter=/&prefix=f1&shared=&' % url)
114
        self.assertEqual(r.status_code, 200)
115
        shared_objects = r.content.split('\n')
116
        if '' in shared_objects:
117
            shared_objects.remove('')
118
        self.assertEqual(shared_objects, ['f1/f2', 'f1/f2/'])
119

  
101 120
        r = self.get('%s?delimiter=/&prefix=f1&shared=&format=json' % url)
102 121
        self.assertEqual(r.status_code, 200)
122
        shared_objects = json.loads(r.content)
123
        self.assertEqual([o.get('name', o.get('subdir')) for
124
                          o in shared_objects],
125
                         ['f1/f2', 'f1/f2/'])
126
        folder = (o for o in shared_objects if o['name'] == 'f1/f2').next()
127
        self.assertTrue('x_object_sharing' in folder)
128
        self.assertTrue(folder['x_object_sharing'] == 'write=*')
129

  
130
        r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&' % url)
131
        self.assertEqual(r.status_code, 200)
132
        shared_objects = r.content.split('\n')
133
        if '' in shared_objects:
134
            shared_objects.remove('')
135
        self.assertEqual(shared_objects, ['f1/f2/f3', 'f1/f2/f3/'])
136

  
137
        r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&format=json' % url)
138
        self.assertEqual(r.status_code, 200)
103 139
        shared_objects = [i.get('name', i.get('subdir')) for i in
104 140
                          json.loads(r.content)]
105
        self.assertEqual(shared_objects, ['f1/f2', 'f1/f2/'])
141
        self.assertEqual(shared_objects, ['f1/f2/f3', 'f1/f2/f3/'])
106 142

  
107
        r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&format=json' % url)
143
        r = self.get('%s?delimiter=/&prefix=f1/f2/f3&shared=&' % url)
144
        self.assertEqual(r.status_code, 200)
145
        shared_objects = r.content.split('\n')
146
        if '' in shared_objects:
147
            shared_objects.remove('')
148
        self.assertEqual(shared_objects, ['f1/f2/f3/obj'])
149

  
150
        r = self.get('%s?delimiter=/&prefix=f1/f2/f3&shared=&format=json' %
151
                     url)
108 152
        self.assertEqual(r.status_code, 200)
109 153
        shared_objects = [i.get('name', i.get('subdir')) for i in
110 154
                          json.loads(r.content)]
111
        self.assertEqual(shared_objects, ['f1/f2/obj'])
155
        self.assertEqual(shared_objects, ['f1/f2/f3/obj'])
112 156

  
113 157
    def test_list_shared_by_me(self):
114 158
        self._build_structure()
......
126 170
        self.assertEqual([i['name'] for i in shared_containers], ['c0'])
127 171

  
128 172
        url = join_urls(url, 'c0')
129
        r = self.get('%s?delimiter=/&shared=&format=json' % url)
173
        r = self.get('%s?delimiter=/&shared=&' % url)
130 174
        self.assertEqual(r.status_code, 200)
131
        shared_objects = [i.get('name', i.get('subdir')) for i in
132
                          json.loads(r.content)]
175
        shared_objects = r.content.split('\n')
176
        if '' in shared_objects:
177
            shared_objects.remove('')
133 178
        self.assertEqual(shared_objects, ['f1', 'f1/'])
134 179

  
180
        r = self.get('%s?delimiter=/&shared=&format=json' % url)
181
        self.assertEqual(r.status_code, 200)
182
        shared_objects = json.loads(r.content)
183
        self.assertEqual([o.get('name', o.get('subdir')) for
184
                          o in shared_objects],
185
                         ['f1', 'f1/'])
186
        folder = (o for o in shared_objects if o['name'] == 'f1').next()
187
        self.assertTrue('x_object_sharing' in folder)
188
        self.assertTrue(folder['x_object_sharing'] == 'read=*')
189

  
190
        r = self.get('%s?delimiter=/&prefix=f1&shared=&' % url)
191
        self.assertEqual(r.status_code, 200)
192
        shared_objects = r.content.split('\n')
193
        if '' in shared_objects:
194
            shared_objects.remove('')
195
        self.assertEqual(shared_objects, ['f1/f2', 'f1/f2/'])
196

  
135 197
        r = self.get('%s?delimiter=/&prefix=f1&shared=&format=json' % url)
136 198
        self.assertEqual(r.status_code, 200)
199
        shared_objects = json.loads(r.content)
200
        self.assertEqual([o.get('name', o.get('subdir')) for
201
                          o in shared_objects],
202
                         ['f1/f2', 'f1/f2/'])
203
        folder = (o for o in shared_objects if o['name'] == 'f1/f2').next()
204
        self.assertTrue('x_object_sharing' in folder)
205
        self.assertTrue(folder['x_object_sharing'] == 'write=*')
206

  
207
        r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&' % url)
208
        self.assertEqual(r.status_code, 200)
209
        shared_objects = r.content.split('\n')
210
        if '' in shared_objects:
211
            shared_objects.remove('')
212
        self.assertEqual(shared_objects, ['f1/f2/f3', 'f1/f2/f3/'])
213

  
214
        r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&format=json' % url)
215
        self.assertEqual(r.status_code, 200)
137 216
        shared_objects = [i.get('name', i.get('subdir')) for i in
138 217
                          json.loads(r.content)]
139
        self.assertEqual(shared_objects, ['f1/f2', 'f1/f2/'])
218
        self.assertEqual(shared_objects, ['f1/f2/f3', 'f1/f2/f3/'])
140 219

  
141
        r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&format=json' % url)
220
        r = self.get('%s?delimiter=/&prefix=f1/f2/f3&shared=&' % url)
221
        self.assertEqual(r.status_code, 200)
222
        shared_objects = r.content.split('\n')
223
        if '' in shared_objects:
224
            shared_objects.remove('')
225
        self.assertEqual(shared_objects, ['f1/f2/f3/obj'])
226

  
227
        r = self.get('%s?delimiter=/&prefix=f1/f2/f3&shared=&format=json' %
228
                     url)
142 229
        self.assertEqual(r.status_code, 200)
143 230
        shared_objects = [i.get('name', i.get('subdir')) for i in
144 231
                          json.loads(r.content)]
145
        self.assertEqual(shared_objects, ['f1/f2/obj'])
232
        self.assertEqual(shared_objects, ['f1/f2/f3/obj'])

Also available in: Unified diff