Revision 7c36f3fb snf-pithos-app/pithos/api/test/__init__.py
b/snf-pithos-app/pithos/api/test/__init__.py | ||
---|---|---|
46 | 46 |
from synnefo.lib import join_urls |
47 | 47 |
|
48 | 48 |
from django.test import TestCase |
49 |
from django.conf import settings |
|
49 | 50 |
from django.utils.http import urlencode |
50 | 51 |
|
51 | 52 |
import django.utils.simplejson as json |
... | ... | |
90 | 91 |
|
91 | 92 |
class PithosAPITest(TestCase): |
92 | 93 |
def setUp(self): |
94 |
if (pithos_settings.BACKEND_DB_MODULE == |
|
95 |
'pithos.backends.lib.sqlalchemy'): |
|
96 |
pithos_settings.BACKEND_DB_CONNECTION = django_to_sqlalchemy() |
|
97 |
pithos_settings.BACKEND_POOL_SIZE = 1 |
|
98 |
|
|
93 | 99 |
# Override default block size to spead up tests |
94 | 100 |
pithos_settings.BACKEND_BLOCK_SIZE = TEST_BLOCK_SIZE |
95 | 101 |
pithos_settings.BACKEND_HASH_ALGORITHM = TEST_HASH_ALGORITHM |
... | ... | |
453 | 459 |
uuid = map['x-object-uuid'] |
454 | 460 |
assert(uuid == self.uuid) |
455 | 461 |
|
462 |
|
|
463 |
django_sqlalchemy_engines = { |
|
464 |
'django.db.backends.postgresql_psycopg2': 'postgresql+psycopg2', |
|
465 |
'django.db.backends.postgresql': 'postgresql', |
|
466 |
'django.db.backends.mysql': '', |
|
467 |
'django.db.backends.sqlite3': 'mssql', |
|
468 |
'django.db.backends.oracle': 'oracle'} |
|
469 |
|
|
470 |
|
|
471 |
def django_to_sqlalchemy(): |
|
472 |
"""Convert the django default database to sqlalchemy connection string""" |
|
473 |
# TODO support for more complex configuration |
|
474 |
db = settings.DATABASES['default'] |
|
475 |
name = db.get('TEST_NAME', 'test_%s' % db['NAME']) |
|
476 |
if db['ENGINE'] == 'django.db.backends.sqlite3': |
|
477 |
db.get('TEST_NAME', db['NAME']) |
|
478 |
return 'sqlite:///%s' % name |
|
479 |
else: |
|
480 |
d = dict(scheme=django_sqlalchemy_engines.get(db['ENGINE']), |
|
481 |
user=db['USER'], |
|
482 |
pwd=db['PASSWORD'], |
|
483 |
host=db['HOST'].lower(), |
|
484 |
port=int(db['PORT']) if db['PORT'] != '' else '', |
|
485 |
name=name) |
|
486 |
return '%(scheme)s://%(user)s:%(pwd)s@%(host)s:%(port)s/%(name)s' % d |
|
487 |
|
|
488 |
|
|
456 | 489 |
def test_concurrently(times=2): |
457 | 490 |
""" |
458 | 491 |
Add this decorator to small pieces of code that you want to test |
Also available in: Unified diff