1 # Copyright 2011 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
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.
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.
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.
36 from kamaki.clients import pithos
37 from kamaki.clients import cyclades
39 class testPithos(unittest.TestCase):
41 url = 'http://127.0.0.1:8000/v1'
42 token = 'C/yBXmz3XjTFBnujc2biAg=='
43 token = 'ac0yH8cQMEZu3M3Mp1MWGA=='
44 account = 'admin@adminland.com'
46 self.client = pithos(url, token, account, container)
48 def test_account_head(self):
49 r = self.client.account_head()
50 self.assertEqual(r.status_code, 204)
51 r = self.client.account_head(until='1000000000')
52 self.assertEqual(r.status_code, 204)
53 datestring = unicode(r.headers['x-account-until-timestamp'])
54 self.assertEqual(u'Sun, 09 Sep 2001 01:46:40 GMT', datestring)
56 now = time.mktime(time.gmtime())
57 r = self.client.account_head(if_modified_since=now)
58 r = self.client.account_head(if_unmodified_since=10000)
60 def test_account_get(self):
61 r = self.client.account_get()
62 self.assertEqual(r.status_code, 200)
64 self.assertEqual(fullLen, 3)
65 r = self.client.account_get(limit=1)
66 self.assertEqual(len(r.json), 1)
67 #Assume there exist at least two containers prefixed 'test'
68 r = self.client.account_get(limit=3, marker='test')
69 self.assertNotEqual(len(r.json), 0)
70 conames = [container['name'] for container in r.json if container['name'].lower().startswith('test')]
71 self.assertEqual(len(conames), len(r.json))
72 r = self.client.account_get(show_only_shared=True)
73 self.assertEqual(len(r.json), 2)
74 r = self.client.account_get(until=1342609206)
75 self.assertEqual(len(r.json), 2)
77 def test_account_post(self):
78 r = self.client.account_post()
79 self.assertEqual(r.status_code, 202)
81 self.client.set_account_group(grpName, ['u1', 'u2'])
82 r = self.client.get_account_group()
83 self.assertEqual(r['x-account-group-'+grpName], 'u1,u2')
84 self.client.del_account_group(grpName)
85 r = self.client.get_account_group()
86 self.assertTrue(not r.has_key('x-account-group-grpName'))
87 self.client.set_account_meta({'metatest1':'v1', 'metatest2':'v2'})
88 r = self.client.get_account_meta()
89 self.assertEqual(r['x-account-meta-metatest1'], 'v1')
90 self.assertEqual(r['x-account-meta-metatest2'], 'v2')
91 self.client.del_account_meta('metatest1')
92 r = self.client.get_account_meta()
93 self.assertTrue(not r.has_key('x-account-meta-metatest1'))
94 self.client.del_account_meta('metatest2')
95 r = self.client.get_account_meta()
96 self.assertTrue(not r.has_key('x-account-meta-metatest2'))
98 def test_container_head(self):
99 self.client.container = 'testCo'
100 r = self.client.account_head()
101 self.assertEqual(r.status_code, 204)
102 r = self.client.account_head(until=1000000000)
103 datestring = unicode(r.headers['x-account-until-timestamp'])
104 self.assertEqual(u'Sun, 09 Sep 2001 01:46:40 GMT', datestring)
105 r = self.client.account_head(if_modified_since=1342609206)
106 r = self.client.account_head(if_unmodified_since=1342609206)
107 self.client.container = ''
109 def test_container_get(self):
110 self.client.container = 'testCo'
111 r = self.client.container_get()
112 self.assertEqual(r.status_code, 200)
113 fullLen = len(r.json)
114 r = self.client.container_get(prefix='lal')
115 lalobjects = [obj for obj in r.json if obj['name'].startswith('lal')]
116 self.assertTrue(len(r.json) > 1)
117 self.assertEqual(len(r.json), len(lalobjects))
118 r = self.client.container_get(limit=1)
119 self.assertEqual(len(r.json), 1)
120 r = self.client.container_get(marker='neo')
121 self.assertTrue(len(r.json) > 1)
122 neobjects = [obj for obj in r.json if obj['name'] > 'neo']
123 self.assertEqual(len(r.json), len(neobjects))
124 r = self.client.container_get(prefix='testDir/testDir', delimiter='2')
125 self.assertTrue(fullLen > len(r.json))
126 r = self.client.container_get(format='xml')
127 self.assertEqual(r.text.split()[4], 'name="testCo">')
128 #meta-check is not that obvious...
129 self.client.set_container_meta({'m1':'v1', 'm2':'v2'}
130 r = self.client.container_get(meta=[])
133 class testCyclades(unittest.TestCase):
137 def test_list_servers(self):
141 suite = unittest.TestSuite()
142 suite.addTest(unittest.makeSuite(testPithos))
143 #suite.addTest(unittest.makeSuite(testCyclades))
146 if __name__ == '__main__':
147 suiteFew = unittest.TestSuite()
150 suiteFew.addTest(testPithos('test_account_head'))
151 suiteFew.addTest(testPithos('test_account_get'))
152 suiteFew.addTest(testPithos('test_account_post'))
153 suiteFew.addTest(testPithos('test_container_head'))
154 suiteFew.addTest(testPithos('test_container_get'))
157 #suiteFew.addTest(testCyclades('test_list_servers'))
159 unittest.TextTestRunner(verbosity = 2).run(suite())