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
def app_pre_save(instance, **kwargs):
    instance['consumer_key'] = instance['consumer_key'] or get_random_string(32)
    instance['consumer_secret'] = instance['consumer_secret'] or get_random_string(32)
Esempio n. 3
0
    def execute(self, *args, **kwargs):
        load_apps()

        from london.apps.auth.models import User

        if kwargs.get('username', None):
            if User.query().filter(username=kwargs['username']).count():
                sys.exit('User "%s" already exists.'%kwargs['username'])
        elif kwargs.get('email', None):
            if User.query().filter(email=kwargs['email']).count():
                sys.exit('User with e-mail "%s" already exists.'%kwargs['email'])
            kwargs['username'] = slugify(kwargs['email'])

        fields = {}

        # Username
        if kwargs.get('username', None):
            fields['username'] = kwargs['username']
        else:
            fields['username'] = raw_input('Username: '******'username'].strip():
                print('Invalid username.')
                sys.exit(1)

        # Password
        if kwargs.get('password', None):
            fields['password'] = kwargs['password']
        else:
            fields['password'] = raw_input('Password (empty for random generation): ')
            if not fields['password']:
                fields['password'] = get_random_string()
                print('The password "%s" was generated.'%fields['password'])
            elif fields['password'] != raw_input('... again, for confirmation: '):
                print('Password not apropriately confirmed.')
                sys.exit(1)

        # E-mail address
        if kwargs.get('email', None):
            fields['email'] = kwargs['email']
        else:
            fields['email'] = raw_input('E-mail address: ')
            if not fields['email'].strip():
                print('Invalid e-mail address.')
                sys.exit(1)

        # Is staff?
        if kwargs['is_staff']:
            fields['is_staff'] = kwargs['is_staff']
        else:
            fields['is_staff'] = raw_input('Can access admin (staff)?: ').lower() == 'yes'

        # Is superuser?
        if kwargs['is_superuser']:
            fields['is_superuser'] = kwargs['is_superuser']
        else:
            fields['is_superuser'] = raw_input('Superuser?: ').lower() == 'yes'

        # Checks if a user with that username already exists.
        if User.query().filter(username=fields['username']).count():
            print('Another user exists with the username "%s".'%fields['username'])
            sys.exit(1)
        
        user = User.query().create(**fields)
        print('The user "%s" was created with password "%s"'%(fields['username'], fields['password']))