1 from django.conf import settings |
1 from django.conf import settings |
|
2 from django.db import DEFAULT_DB_ALIAS |
2 |
3 |
3 # function that will pass a test. |
4 # function that will pass a test. |
4 def pass_test(*args): return |
5 def pass_test(*args): return |
5 |
6 |
6 def no_backend(test_func, backend): |
7 def no_backend(test_func, backend): |
7 "Use this decorator to disable test on specified backend." |
8 "Use this decorator to disable test on specified backend." |
8 if settings.DATABASE_ENGINE == backend: |
9 if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'].rsplit('.')[-1] == backend: |
9 return pass_test |
10 return pass_test |
10 else: |
11 else: |
11 return test_func |
12 return test_func |
12 |
13 |
13 # Decorators to disable entire test functions for specific |
14 # Decorators to disable entire test functions for specific |
14 # spatial backends. |
15 # spatial backends. |
15 def no_oracle(func): return no_backend(func, 'oracle') |
16 def no_oracle(func): return no_backend(func, 'oracle') |
16 def no_postgis(func): return no_backend(func, 'postgresql_psycopg2') |
17 def no_postgis(func): return no_backend(func, 'postgis') |
17 def no_mysql(func): return no_backend(func, 'mysql') |
18 def no_mysql(func): return no_backend(func, 'mysql') |
18 def no_spatialite(func): return no_backend(func, 'sqlite3') |
19 def no_spatialite(func): return no_backend(func, 'spatialite') |
19 |
20 |
20 # Shortcut booleans to omit only portions of tests. |
21 # Shortcut booleans to omit only portions of tests. |
21 oracle = settings.DATABASE_ENGINE == 'oracle' |
22 _default_db = settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'].rsplit('.')[-1] |
22 postgis = settings.DATABASE_ENGINE == 'postgresql_psycopg2' |
23 oracle = _default_db == 'oracle' |
23 mysql = settings.DATABASE_ENGINE == 'mysql' |
24 postgis = _default_db == 'postgis' |
24 spatialite = settings.DATABASE_ENGINE == 'sqlite3' |
25 mysql = _default_db == 'mysql' |
|
26 spatialite = _default_db == 'spatialite' |