Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (5.8 kB)

1
# Copyright 2011-2012 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
from pithos.api.test import PithosAPITest
35

    
36
from synnefo.lib import join_urls
37

    
38
import django.utils.simplejson as json
39

    
40
class ListSharing(PithosAPITest):
41
    def _build_structure(self, user=None):
42
        user = user or self.user
43
        for i in range(2):
44
            cname = 'c%d' % i
45
            self.create_container(cname, user=user)
46
            self.upload_object(cname, 'obj', user=user)
47
            self.create_folder(cname, 'f1', user=user)
48
            self.create_folder(cname, 'f1/f2', user=user)
49
            self.upload_object(cname, 'f1/f2/obj', user=user)
50

    
51
        # share /c0/f1 path
52
        url = join_urls(self.pithos_path, user, 'c0', 'f1')
53
        r = self.post(url, user=user, content_type='',
54
                      HTTP_CONTENT_RANGE='bytes */*',
55
                      HTTP_X_OBJECT_SHARING='read=*')
56
        self.assertEqual(r.status_code, 202)
57
        r = self.get(url)
58

    
59
    def test_list_share_with_me(self):
60
        self._build_structure('alice')
61
        url = join_urls(self.pithos_path)
62
        r = self.get(url)
63
        self.assertEqual(r.status_code, 200)
64
        allowed_accounts = r.content.split('\n')
65
        if '' in allowed_accounts:
66
            allowed_accounts.remove('')
67
        self.assertEqual(allowed_accounts, ['alice'])
68

    
69
        r = self.get('%s?format=json' % url)
70
        self.assertEqual(r.status_code, 200)
71
        allowed_accounts = json.loads(r.content)
72
        self.assertEqual([i['name'] for i in allowed_accounts], ['alice'])
73

    
74
        url = join_urls(url, 'alice')
75
        r = self.get(url)
76
        self.assertEqual(r.status_code, 200)
77
        allowed_containers = r.content.split('\n')
78
        if '' in allowed_containers:
79
            allowed_containers.remove('')
80
        self.assertEqual(allowed_containers, ['c0'])
81

    
82
        r = self.get('%s?format=json' % url)
83
        self.assertEqual(r.status_code, 200)
84
        allowed_containers = json.loads(r.content)
85
        self.assertEqual([i['name'] for i in allowed_containers], ['c0'])
86

    
87
        url = join_urls(url, 'c0')
88
        r = self.get('%s?delimiter=/&shared=&format=json' % url)
89
        self.assertEqual(r.status_code, 200)
90
        shared_objects = [i.get('name', i.get('subdir')) for i in
91
                          json.loads(r.content)]
92
        self.assertEqual(shared_objects, ['f1', 'f1/'])
93

    
94
        r = self.get('%s?delimiter=/&prefix=f1&shared=&format=json' % url)
95
        self.assertEqual(r.status_code, 200)
96
        shared_objects = [i.get('name', i.get('subdir')) for i in
97
                          json.loads(r.content)]
98
        self.assertEqual(shared_objects, ['f1/f2', 'f1/f2/'])
99

    
100
        r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&format=json' % url)
101
        self.assertEqual(r.status_code, 200)
102
        shared_objects = [i.get('name', i.get('subdir')) for i in
103
                          json.loads(r.content)]
104
        self.assertEqual(shared_objects, ['f1/f2/obj'])
105

    
106
    def test_list_shared_by_me(self):
107
        self._build_structure()
108
        url = join_urls(self.pithos_path, self.user)
109
        r = self.get('%s?shared=' % url)
110
        self.assertEqual(r.status_code, 200)
111
        shared_containers = r.content.split('\n')
112
        if '' in shared_containers:
113
            shared_containers.remove('')
114
        self.assertEqual(shared_containers, ['c0'])
115

    
116
        r = self.get('%s?shared=&format=json' % url)
117
        self.assertEqual(r.status_code, 200)
118
        shared_containers = json.loads(r.content)
119
        self.assertEqual([i['name'] for i in shared_containers], ['c0'])
120

    
121
        url = join_urls(url, 'c0')
122
        r = self.get('%s?delimiter=/&shared=&format=json' % url)
123
        self.assertEqual(r.status_code, 200)
124
        shared_objects = [i.get('name', i.get('subdir')) for i in
125
                          json.loads(r.content)]
126
        self.assertEqual(shared_objects, ['f1', 'f1/'])
127

    
128
        r = self.get('%s?delimiter=/&prefix=f1&shared=&format=json' % url)
129
        self.assertEqual(r.status_code, 200)
130
        shared_objects = [i.get('name', i.get('subdir')) for i in
131
                          json.loads(r.content)]
132
        self.assertEqual(shared_objects, ['f1/f2', 'f1/f2/'])
133

    
134
        r = self.get('%s?delimiter=/&prefix=f1/f2&shared=&format=json' % url)
135
        self.assertEqual(r.status_code, 200)
136
        shared_objects = [i.get('name', i.get('subdir')) for i in
137
                          json.loads(r.content)]
138
        self.assertEqual(shared_objects, ['f1/f2/obj'])