Esempio n. 1
0
    def execute(self, *args, **kwargs):
        if not args and not settings.TEST_DEFAULT_APPS:
            sys.exit('You must inform the application name to test. It can be a list of applications separated by commas.')

        # Setting test mode to the settings
        settings._TESTING = True

        # Sets a different database setting
        old_databases = settings.DATABASES.copy()
        for k in settings.DATABASES:
            settings.DATABASES[k]['name'] = settings.DATABASES[k]['name'] + '_test_' + get_random_string()

            # Creates the test database
            conn = get_connection(k, force_reopen=True)
            conn.create_database()

        # Default nose arguments
        argv = ['nosetests','--with-doctest','--verbosity=%s'%kwargs['verbosity']]
        if kwargs.get('with_coverage',None):
            argv.append('--with-coverage')
        if settings.TEST_ADDITIONAL_ARGS:
            argv.extend(settings.TEST_ADDITIONAL_ARGS)
        #if test_case:
        #    argv.append('--testmatch=%s\.txt'%test_case) # FIXME: it's not working

        # Gets informed application
        bits = (args[0] if args else settings.TEST_DEFAULT_APPS).split(',')
        for app in load_apps():
            if not [b for b in bits if b.split(':')[0] == app._app_in_london]:
                continue

            # TODO The sign ":" is for tell a specific test file instead of whole application. But this is not yet working.

            # Finds the test directory
            tests_dir = os.path.join(app.__path__[0], 'tests')
            if not os.path.exists(tests_dir):
                sys.exit('There is no folder "tests" in the given application.')

            sys.path.insert(0, tests_dir)
            argv.append('--where=' + tests_dir)

        # Finally, running the test program
        program = TestProgram(argv=argv, exit=False)

        # Drops the test databases
        for k in settings.DATABASES:
            conn = get_connection(k)
            conn.drop_database()
Esempio n. 2
0
from london.conf import settings
from london.db.connections import get_connection
from london.db.models.fields import *
from london.db.models.querysets import QuerySet, RelatedQuerySet
from london.db.models.base import BaseModel, Model, PersistentModel, NestedModel
from london.db.models.expressions import Sum, Max, Min, Count, Average

# Starts all available connections
# FIXME: this has to better to open only needed connections
for db in settings.DATABASES:
    get_connection(db)