Revision 5d9987a5
b/snf-tools/synnefo_tools/burnin/pithos_tests.py | ||
---|---|---|
39 | 39 |
import os |
40 | 40 |
import random |
41 | 41 |
import tempfile |
42 |
from datetime import datetime |
|
42 | 43 |
|
43 | 44 |
from synnefo_tools.burnin.common import BurninTests, Proper |
44 | 45 |
|
... | ... | |
48 | 49 |
"""Test Pithos functionality""" |
49 | 50 |
containers = Proper(value=None) |
50 | 51 |
created_container = Proper(value=None) |
52 |
now_unformated = Proper(value=datetime.utcnow()) |
|
51 | 53 |
|
52 |
def test_001_list_containers(self):
|
|
53 |
"""Test container list actually returns containers"""
|
|
54 |
def test_005_account_head(self):
|
|
55 |
"""HEAD on pithos account"""
|
|
54 | 56 |
self._set_pithos_account(self._get_uuid()) |
57 |
pithos = self.clients.pithos |
|
58 |
r = pithos.account_head() |
|
59 |
self.assertEqual(r.status_code, 204) |
|
60 |
self.info('Returns 204') |
|
61 |
|
|
62 |
r = pithos.account_head(until='1000000000') |
|
63 |
self.assertEqual(r.status_code, 204) |
|
64 |
datestring = unicode(r.headers['x-account-until-timestamp']) |
|
65 |
self.assertEqual(u'Sun, 09 Sep 2001 01:46:40 GMT', datestring) |
|
66 |
self.assertTrue('x-account-policy-quota' in r.headers) |
|
67 |
self.info('Until and policy quota exist') |
|
68 |
|
|
69 |
for format in pithos.DATE_FORMATS: |
|
70 |
now_formated = self.now_unformated.strftime(format) |
|
71 |
r1 = pithos.account_head( |
|
72 |
if_modified_since=now_formated, success=(204, 304, 412)) |
|
73 |
r2 = pithos.account_head( |
|
74 |
if_unmodified_since=now_formated, success=(204, 304, 412)) |
|
75 |
self.assertNotEqual(r1.status_code, r2.status_code) |
|
76 |
self.info('If_(un)modified_since is OK') |
|
77 |
|
|
78 |
def test_010_account_get(self): |
|
79 |
"""Test account_get""" |
|
80 |
self.info('Preparation') |
|
81 |
pithos = self.clients.pithos |
|
82 |
for i in range(1, 3): |
|
83 |
cont_name = "cont%s_%s%s" % ( |
|
84 |
i, self.run_id, random.randint(1000, 9999)) |
|
85 |
self._create_pithos_container(cont_name) |
|
86 |
pithos.container, obj = cont_name, 'shared_file' |
|
87 |
pithos.create_object(obj) |
|
88 |
pithos.set_object_sharing(obj, read_permission='*') |
|
89 |
self.info('Created object /%s/%s' % (cont_name, obj)) |
|
90 |
|
|
91 |
r = pithos.list_containers() |
|
92 |
fullLen = len(r) |
|
93 |
self.assertTrue(fullLen > 2) |
|
94 |
self.info('Normal use is OK') |
|
95 |
|
|
96 |
r = pithos.account_get(limit=1) |
|
97 |
self.assertEqual(len(r.json), 1) |
|
98 |
self.info('Limit works') |
|
99 |
|
|
100 |
r = pithos.account_get(marker='cont') |
|
101 |
cont1, cont3 = r.json[0], r.json[2] |
|
102 |
self.info('Marker works') |
|
103 |
|
|
104 |
r = pithos.account_get(limit=2, marker='cont') |
|
105 |
conames = [container['name'] for container in r.json if ( |
|
106 |
container['name'].lower().startswith('cont'))] |
|
107 |
self.assertTrue(cont1['name'] in conames) |
|
108 |
self.assertFalse(cont3['name'] in conames) |
|
109 |
self.info('Marker-limit combination works') |
|
110 |
|
|
111 |
r = pithos.account_get(show_only_shared=True) |
|
112 |
self.assertTrue(cont_name in [c['name'] for c in r.json]) |
|
113 |
self.info('Show-only-shared works') |
|
114 |
|
|
115 |
r = pithos.account_get(until=1342609206.0) |
|
116 |
self.assertTrue(len(r.json) <= fullLen) |
|
117 |
self.info('Until works') |
|
118 |
|
|
119 |
for format in pithos.DATE_FORMATS: |
|
120 |
now_formated = self.now_unformated.strftime(format) |
|
121 |
r1 = pithos.account_get( |
|
122 |
if_modified_since=now_formated, success=(200, 304, 412)) |
|
123 |
r2 = pithos.account_get( |
|
124 |
if_unmodified_since=now_formated, success=(200, 304, 412)) |
|
125 |
self.assertNotEqual(r1.status_code, r2.status_code) |
|
126 |
self.info('If_(un)modified_since is OK') |
|
127 |
|
|
128 |
def test_051_list_containers(self): |
|
129 |
"""Test container list actually returns containers""" |
|
130 |
#self.assertTrue(False) # This is a stoper! |
|
55 | 131 |
self.containers = self._get_list_of_containers() |
56 | 132 |
self.assertGreater(len(self.containers), 0) |
133 |
self.lala = 1 |
|
57 | 134 |
|
58 |
def test_002_unique_containers(self):
|
|
135 |
def test_052_unique_containers(self):
|
|
59 | 136 |
"""Test if containers have unique names""" |
60 | 137 |
names = [n['name'] for n in self.containers] |
61 | 138 |
names = sorted(names) |
62 | 139 |
self.assertEqual(sorted(list(set(names))), names) |
63 | 140 |
|
64 |
def test_003_create_container(self):
|
|
141 |
def test_053_create_container(self):
|
|
65 | 142 |
"""Test creating a new container""" |
66 | 143 |
names = [n['name'] for n in self.containers] |
67 | 144 |
while True: |
... | ... | |
82 | 159 |
# at cleanup phase, if something goes wrong. |
83 | 160 |
self.created_container = rand_name |
84 | 161 |
|
85 |
def test_004_upload_file(self):
|
|
162 |
def test_054_upload_file(self):
|
|
86 | 163 |
"""Test uploading a txt file to Pithos""" |
87 | 164 |
# Create a tmp file |
88 | 165 |
with tempfile.TemporaryFile(dir=self.temp_directory) as fout: |
... | ... | |
94 | 171 |
# Verify quotas |
95 | 172 |
self._check_quotas(diskspace=+os.fstat(fout.fileno()).st_size) |
96 | 173 |
|
97 |
def test_005_download_file(self):
|
|
174 |
def test_055_download_file(self):
|
|
98 | 175 |
"""Test downloading the file from Pithos""" |
99 | 176 |
# Create a tmp directory to save the file |
100 | 177 |
with tempfile.TemporaryFile(dir=self.temp_directory) as fout: |
... | ... | |
106 | 183 |
self.info("Comparing contents with the uploaded file") |
107 | 184 |
self.assertEqual(contents, "This is a temp file") |
108 | 185 |
|
109 |
def test_006_remove(self):
|
|
186 |
def test_056_remove(self):
|
|
110 | 187 |
"""Test removing files and containers from Pithos""" |
111 | 188 |
self.info("Removing the file %s from container %s", |
112 | 189 |
"test.txt", self.created_container) |
Also available in: Unified diff