Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-app / pithos / api / test / listing.py @ e161c24f

History | View | Annotate | Download (9.9 kB)

1 6e0f3e65 Sofia Papagiannaki
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2 6e0f3e65 Sofia Papagiannaki
#
3 6e0f3e65 Sofia Papagiannaki
# Redistribution and use in source and binary forms, with or
4 6e0f3e65 Sofia Papagiannaki
# without modification, are permitted provided that the following
5 6e0f3e65 Sofia Papagiannaki
# conditions are met:
6 6e0f3e65 Sofia Papagiannaki
#
7 6e0f3e65 Sofia Papagiannaki
#   1. Redistributions of source code must retain the above
8 6e0f3e65 Sofia Papagiannaki
#      copyright notice, this list of conditions and the following
9 6e0f3e65 Sofia Papagiannaki
#      disclaimer.
10 6e0f3e65 Sofia Papagiannaki
#
11 6e0f3e65 Sofia Papagiannaki
#   2. Redistributions in binary form must reproduce the above
12 6e0f3e65 Sofia Papagiannaki
#      copyright notice, this list of conditions and the following
13 6e0f3e65 Sofia Papagiannaki
#      disclaimer in the documentation and/or other materials
14 6e0f3e65 Sofia Papagiannaki
#      provided with the distribution.
15 6e0f3e65 Sofia Papagiannaki
#
16 6e0f3e65 Sofia Papagiannaki
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 6e0f3e65 Sofia Papagiannaki
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 6e0f3e65 Sofia Papagiannaki
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 6e0f3e65 Sofia Papagiannaki
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 6e0f3e65 Sofia Papagiannaki
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 6e0f3e65 Sofia Papagiannaki
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 6e0f3e65 Sofia Papagiannaki
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 6e0f3e65 Sofia Papagiannaki
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 6e0f3e65 Sofia Papagiannaki
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 6e0f3e65 Sofia Papagiannaki
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 6e0f3e65 Sofia Papagiannaki
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 6e0f3e65 Sofia Papagiannaki
# POSSIBILITY OF SUCH DAMAGE.
28 6e0f3e65 Sofia Papagiannaki
#
29 6e0f3e65 Sofia Papagiannaki
# The views and conclusions contained in the software and
30 6e0f3e65 Sofia Papagiannaki
# documentation are those of the authors and should not be
31 6e0f3e65 Sofia Papagiannaki
# interpreted as representing official policies, either expressed
32 6e0f3e65 Sofia Papagiannaki
# or implied, of GRNET S.A.
33 6e0f3e65 Sofia Papagiannaki
34 6e0f3e65 Sofia Papagiannaki
from pithos.api.test import PithosAPITest
35 6e0f3e65 Sofia Papagiannaki
36 6e0f3e65 Sofia Papagiannaki
from synnefo.lib import join_urls
37 6e0f3e65 Sofia Papagiannaki
38 6e0f3e65 Sofia Papagiannaki
import django.utils.simplejson as json
39 6e0f3e65 Sofia Papagiannaki
40 f53483d8 Sofia Papagiannaki
41 6e0f3e65 Sofia Papagiannaki
class ListSharing(PithosAPITest):
42 6e0f3e65 Sofia Papagiannaki
    def _build_structure(self, user=None):
43 6e0f3e65 Sofia Papagiannaki
        user = user or self.user
44 6e0f3e65 Sofia Papagiannaki
        for i in range(2):
45 6e0f3e65 Sofia Papagiannaki
            cname = 'c%d' % i
46 6e0f3e65 Sofia Papagiannaki
            self.create_container(cname, user=user)
47 6e0f3e65 Sofia Papagiannaki
            self.upload_object(cname, 'obj', user=user)
48 6e0f3e65 Sofia Papagiannaki
            self.create_folder(cname, 'f1', user=user)
49 6e0f3e65 Sofia Papagiannaki
            self.create_folder(cname, 'f1/f2', user=user)
50 e161c24f Sofia Papagiannaki
            self.create_folder(cname, 'f1/f2/f3', user=user)
51 e161c24f Sofia Papagiannaki
            self.upload_object(cname, 'f1/f2/f3/obj', user=user)
52 6e0f3e65 Sofia Papagiannaki
53 84c67d8e Sofia Papagiannaki
        # share /c0/f1 path for read
54 6e0f3e65 Sofia Papagiannaki
        url = join_urls(self.pithos_path, user, 'c0', 'f1')
55 6e0f3e65 Sofia Papagiannaki
        r = self.post(url, user=user, content_type='',
56 6e0f3e65 Sofia Papagiannaki
                      HTTP_CONTENT_RANGE='bytes */*',
57 6e0f3e65 Sofia Papagiannaki
                      HTTP_X_OBJECT_SHARING='read=*')
58 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 202)
59 84c67d8e Sofia Papagiannaki
60 84c67d8e Sofia Papagiannaki
        # share /c0/f1/f2 path for write
61 84c67d8e Sofia Papagiannaki
        url = join_urls(self.pithos_path, user, 'c0', 'f1/f2')
62 84c67d8e Sofia Papagiannaki
        r = self.post(url, user=user, content_type='',
63 84c67d8e Sofia Papagiannaki
                      HTTP_CONTENT_RANGE='bytes */*',
64 84c67d8e Sofia Papagiannaki
                      HTTP_X_OBJECT_SHARING='write=*')
65 84c67d8e Sofia Papagiannaki
        self.assertEqual(r.status_code, 202)
66 6e0f3e65 Sofia Papagiannaki
67 6e0f3e65 Sofia Papagiannaki
    def test_list_share_with_me(self):
68 6e0f3e65 Sofia Papagiannaki
        self._build_structure('alice')
69 5775b7fb Sofia Papagiannaki
        url = join_urls(self.pithos_path, '/')
70 6e0f3e65 Sofia Papagiannaki
        r = self.get(url)
71 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
72 6e0f3e65 Sofia Papagiannaki
        allowed_accounts = r.content.split('\n')
73 6e0f3e65 Sofia Papagiannaki
        if '' in allowed_accounts:
74 6e0f3e65 Sofia Papagiannaki
            allowed_accounts.remove('')
75 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(allowed_accounts, ['alice'])
76 6e0f3e65 Sofia Papagiannaki
77 6e0f3e65 Sofia Papagiannaki
        r = self.get('%s?format=json' % url)
78 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
79 6e0f3e65 Sofia Papagiannaki
        allowed_accounts = json.loads(r.content)
80 6e0f3e65 Sofia Papagiannaki
        self.assertEqual([i['name'] for i in allowed_accounts], ['alice'])
81 6e0f3e65 Sofia Papagiannaki
82 6e0f3e65 Sofia Papagiannaki
        url = join_urls(url, 'alice')
83 6e0f3e65 Sofia Papagiannaki
        r = self.get(url)
84 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
85 6e0f3e65 Sofia Papagiannaki
        allowed_containers = r.content.split('\n')
86 6e0f3e65 Sofia Papagiannaki
        if '' in allowed_containers:
87 6e0f3e65 Sofia Papagiannaki
            allowed_containers.remove('')
88 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(allowed_containers, ['c0'])
89 6e0f3e65 Sofia Papagiannaki
90 6e0f3e65 Sofia Papagiannaki
        r = self.get('%s?format=json' % url)
91 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
92 6e0f3e65 Sofia Papagiannaki
        allowed_containers = json.loads(r.content)
93 6e0f3e65 Sofia Papagiannaki
        self.assertEqual([i['name'] for i in allowed_containers], ['c0'])
94 6e0f3e65 Sofia Papagiannaki
95 6e0f3e65 Sofia Papagiannaki
        url = join_urls(url, 'c0')
96 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&shared=&' % url)
97 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
98 e161c24f Sofia Papagiannaki
        shared_objects = r.content.split('\n')
99 e161c24f Sofia Papagiannaki
        if '' in shared_objects:
100 e161c24f Sofia Papagiannaki
            shared_objects.remove('')
101 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(shared_objects, ['f1', 'f1/'])
102 6e0f3e65 Sofia Papagiannaki
103 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&shared=&format=json' % url)
104 e161c24f Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
105 e161c24f Sofia Papagiannaki
        shared_objects = json.loads(r.content)
106 e161c24f Sofia Papagiannaki
        self.assertEqual([o.get('name', o.get('subdir')) for
107 e161c24f Sofia Papagiannaki
                          o in shared_objects],
108 e161c24f Sofia Papagiannaki
                         ['f1', 'f1/'])
109 e161c24f Sofia Papagiannaki
        folder = (o for o in shared_objects if o['name'] == 'f1').next()
110 e161c24f Sofia Papagiannaki
        self.assertTrue('x_object_sharing' in folder)
111 e161c24f Sofia Papagiannaki
        self.assertTrue(folder['x_object_sharing'] == 'read=*')
112 e161c24f Sofia Papagiannaki
113 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&prefix=f1&shared=&' % url)
114 e161c24f Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
115 e161c24f Sofia Papagiannaki
        shared_objects = r.content.split('\n')
116 e161c24f Sofia Papagiannaki
        if '' in shared_objects:
117 e161c24f Sofia Papagiannaki
            shared_objects.remove('')
118 e161c24f Sofia Papagiannaki
        self.assertEqual(shared_objects, ['f1/f2', 'f1/f2/'])
119 e161c24f Sofia Papagiannaki
120 6e0f3e65 Sofia Papagiannaki
        r = self.get('%s?delimiter=/&prefix=f1&shared=&format=json' % url)
121 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
122 e161c24f Sofia Papagiannaki
        shared_objects = json.loads(r.content)
123 e161c24f Sofia Papagiannaki
        self.assertEqual([o.get('name', o.get('subdir')) for
124 e161c24f Sofia Papagiannaki
                          o in shared_objects],
125 e161c24f Sofia Papagiannaki
                         ['f1/f2', 'f1/f2/'])
126 e161c24f Sofia Papagiannaki
        folder = (o for o in shared_objects if o['name'] == 'f1/f2').next()
127 e161c24f Sofia Papagiannaki
        self.assertTrue('x_object_sharing' in folder)
128 e161c24f Sofia Papagiannaki
        self.assertTrue(folder['x_object_sharing'] == 'write=*')
129 e161c24f Sofia Papagiannaki
130 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&' % url)
131 e161c24f Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
132 e161c24f Sofia Papagiannaki
        shared_objects = r.content.split('\n')
133 e161c24f Sofia Papagiannaki
        if '' in shared_objects:
134 e161c24f Sofia Papagiannaki
            shared_objects.remove('')
135 e161c24f Sofia Papagiannaki
        self.assertEqual(shared_objects, ['f1/f2/f3', 'f1/f2/f3/'])
136 e161c24f Sofia Papagiannaki
137 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&format=json' % url)
138 e161c24f Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
139 6e0f3e65 Sofia Papagiannaki
        shared_objects = [i.get('name', i.get('subdir')) for i in
140 6e0f3e65 Sofia Papagiannaki
                          json.loads(r.content)]
141 e161c24f Sofia Papagiannaki
        self.assertEqual(shared_objects, ['f1/f2/f3', 'f1/f2/f3/'])
142 6e0f3e65 Sofia Papagiannaki
143 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&prefix=f1/f2/f3&shared=&' % url)
144 e161c24f Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
145 e161c24f Sofia Papagiannaki
        shared_objects = r.content.split('\n')
146 e161c24f Sofia Papagiannaki
        if '' in shared_objects:
147 e161c24f Sofia Papagiannaki
            shared_objects.remove('')
148 e161c24f Sofia Papagiannaki
        self.assertEqual(shared_objects, ['f1/f2/f3/obj'])
149 e161c24f Sofia Papagiannaki
150 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&prefix=f1/f2/f3&shared=&format=json' %
151 e161c24f Sofia Papagiannaki
                     url)
152 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
153 6e0f3e65 Sofia Papagiannaki
        shared_objects = [i.get('name', i.get('subdir')) for i in
154 6e0f3e65 Sofia Papagiannaki
                          json.loads(r.content)]
155 e161c24f Sofia Papagiannaki
        self.assertEqual(shared_objects, ['f1/f2/f3/obj'])
156 6e0f3e65 Sofia Papagiannaki
157 6e0f3e65 Sofia Papagiannaki
    def test_list_shared_by_me(self):
158 6e0f3e65 Sofia Papagiannaki
        self._build_structure()
159 6e0f3e65 Sofia Papagiannaki
        url = join_urls(self.pithos_path, self.user)
160 6e0f3e65 Sofia Papagiannaki
        r = self.get('%s?shared=' % url)
161 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
162 6e0f3e65 Sofia Papagiannaki
        shared_containers = r.content.split('\n')
163 6e0f3e65 Sofia Papagiannaki
        if '' in shared_containers:
164 6e0f3e65 Sofia Papagiannaki
            shared_containers.remove('')
165 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(shared_containers, ['c0'])
166 6e0f3e65 Sofia Papagiannaki
167 6e0f3e65 Sofia Papagiannaki
        r = self.get('%s?shared=&format=json' % url)
168 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
169 6e0f3e65 Sofia Papagiannaki
        shared_containers = json.loads(r.content)
170 6e0f3e65 Sofia Papagiannaki
        self.assertEqual([i['name'] for i in shared_containers], ['c0'])
171 6e0f3e65 Sofia Papagiannaki
172 6e0f3e65 Sofia Papagiannaki
        url = join_urls(url, 'c0')
173 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&shared=&' % url)
174 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
175 e161c24f Sofia Papagiannaki
        shared_objects = r.content.split('\n')
176 e161c24f Sofia Papagiannaki
        if '' in shared_objects:
177 e161c24f Sofia Papagiannaki
            shared_objects.remove('')
178 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(shared_objects, ['f1', 'f1/'])
179 6e0f3e65 Sofia Papagiannaki
180 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&shared=&format=json' % url)
181 e161c24f Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
182 e161c24f Sofia Papagiannaki
        shared_objects = json.loads(r.content)
183 e161c24f Sofia Papagiannaki
        self.assertEqual([o.get('name', o.get('subdir')) for
184 e161c24f Sofia Papagiannaki
                          o in shared_objects],
185 e161c24f Sofia Papagiannaki
                         ['f1', 'f1/'])
186 e161c24f Sofia Papagiannaki
        folder = (o for o in shared_objects if o['name'] == 'f1').next()
187 e161c24f Sofia Papagiannaki
        self.assertTrue('x_object_sharing' in folder)
188 e161c24f Sofia Papagiannaki
        self.assertTrue(folder['x_object_sharing'] == 'read=*')
189 e161c24f Sofia Papagiannaki
190 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&prefix=f1&shared=&' % url)
191 e161c24f Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
192 e161c24f Sofia Papagiannaki
        shared_objects = r.content.split('\n')
193 e161c24f Sofia Papagiannaki
        if '' in shared_objects:
194 e161c24f Sofia Papagiannaki
            shared_objects.remove('')
195 e161c24f Sofia Papagiannaki
        self.assertEqual(shared_objects, ['f1/f2', 'f1/f2/'])
196 e161c24f Sofia Papagiannaki
197 6e0f3e65 Sofia Papagiannaki
        r = self.get('%s?delimiter=/&prefix=f1&shared=&format=json' % url)
198 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
199 e161c24f Sofia Papagiannaki
        shared_objects = json.loads(r.content)
200 e161c24f Sofia Papagiannaki
        self.assertEqual([o.get('name', o.get('subdir')) for
201 e161c24f Sofia Papagiannaki
                          o in shared_objects],
202 e161c24f Sofia Papagiannaki
                         ['f1/f2', 'f1/f2/'])
203 e161c24f Sofia Papagiannaki
        folder = (o for o in shared_objects if o['name'] == 'f1/f2').next()
204 e161c24f Sofia Papagiannaki
        self.assertTrue('x_object_sharing' in folder)
205 e161c24f Sofia Papagiannaki
        self.assertTrue(folder['x_object_sharing'] == 'write=*')
206 e161c24f Sofia Papagiannaki
207 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&' % url)
208 e161c24f Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
209 e161c24f Sofia Papagiannaki
        shared_objects = r.content.split('\n')
210 e161c24f Sofia Papagiannaki
        if '' in shared_objects:
211 e161c24f Sofia Papagiannaki
            shared_objects.remove('')
212 e161c24f Sofia Papagiannaki
        self.assertEqual(shared_objects, ['f1/f2/f3', 'f1/f2/f3/'])
213 e161c24f Sofia Papagiannaki
214 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&format=json' % url)
215 e161c24f Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
216 6e0f3e65 Sofia Papagiannaki
        shared_objects = [i.get('name', i.get('subdir')) for i in
217 6e0f3e65 Sofia Papagiannaki
                          json.loads(r.content)]
218 e161c24f Sofia Papagiannaki
        self.assertEqual(shared_objects, ['f1/f2/f3', 'f1/f2/f3/'])
219 6e0f3e65 Sofia Papagiannaki
220 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&prefix=f1/f2/f3&shared=&' % url)
221 e161c24f Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
222 e161c24f Sofia Papagiannaki
        shared_objects = r.content.split('\n')
223 e161c24f Sofia Papagiannaki
        if '' in shared_objects:
224 e161c24f Sofia Papagiannaki
            shared_objects.remove('')
225 e161c24f Sofia Papagiannaki
        self.assertEqual(shared_objects, ['f1/f2/f3/obj'])
226 e161c24f Sofia Papagiannaki
227 e161c24f Sofia Papagiannaki
        r = self.get('%s?delimiter=/&prefix=f1/f2/f3&shared=&format=json' %
228 e161c24f Sofia Papagiannaki
                     url)
229 6e0f3e65 Sofia Papagiannaki
        self.assertEqual(r.status_code, 200)
230 6e0f3e65 Sofia Papagiannaki
        shared_objects = [i.get('name', i.get('subdir')) for i in
231 6e0f3e65 Sofia Papagiannaki
                          json.loads(r.content)]
232 e161c24f Sofia Papagiannaki
        self.assertEqual(shared_objects, ['f1/f2/f3/obj'])