Commit 8970ad2f authored by Sofia Papagiannaki's avatar Sofia Papagiannaki Committed by Chrysostomos Nanakos
Browse files

pithos: Fix/improve pithos app tests

parent 2aed7232
......@@ -43,6 +43,7 @@ import django.utils.simplejson as json
import sys
import random
import functools
import time
pithos_test_settings = functools.partial(with_settings, pithos_settings)
......@@ -124,6 +125,11 @@ def filter_headers(headers, prefix):
class PithosTestSuiteRunner(DjangoTestSuiteRunner):
def setup_test_environment(self, **kwargs):
pithos_settings.BACKEND_MAPFILE_PREFIX = \
'snf_test_pithos_app_%s_' % time.time()
super(PithosTestSuiteRunner, self).setup_test_environment(**kwargs)
def setup_databases(self, **kwargs):
old_names, mirrors = super(PithosTestSuiteRunner,
self).setup_databases(**kwargs)
......
......@@ -852,8 +852,9 @@ class ObjectPut(PithosAPITest):
r = self.put('%s?hashmap=' % url, data=hashmap)
self.assertEqual(r.status_code, 400)
length = random.randint(TEST_BLOCK_SIZE, 2 * TEST_BLOCK_SIZE)
data = get_random_data(length=length)
l = list(data)
l[-1] = chr((ord(l[-1]) + 1) % 255) # Change only the last char
data = ''.join(l)
hashes = HashMap(TEST_BLOCK_SIZE, TEST_HASH_ALGORITHM)
hashes.load(data)
hexlified = [hexlify(h) for h in hashes]
......@@ -866,7 +867,7 @@ class ObjectPut(PithosAPITest):
except:
self.fail("shouldn't happen")
else:
self.assertEqual(sorted(missing), sorted(hexlified))
self.assertEqual(sorted(missing), sorted(hexlified[-1:]))
r = self.get('%s?hashmap=&format=xml' % url)
oname = get_random_name()
......
......@@ -19,12 +19,11 @@
import re
import hashlib
import random
import string
from binascii import hexlify
from StringIO import StringIO
from pithos.backends.random_word import get_random_word
from pithos.api import settings as pithos_settings
......@@ -73,7 +72,7 @@ def get_random_data(length=None):
length = length or random.randint(
pithos_settings.BACKEND_BLOCK_SIZE,
2 * pithos_settings.BACKEND_BLOCK_SIZE)
return get_random_word(length)[:length]
return "".join([random.choice(string.letters) for i in xrange(length)])
def get_random_name(length=8):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment