Пример #1
0
 def test_missing_migrations(self):
     output = io.StringIO()
     try:
         management.call_command(makemigrations.Command(),
                                 dry_run=True,
                                 check_changes=True,
                                 verbosity=1,
                                 stdout=output)
     except SystemExit as err:
         if err.code != 0:
             raise AssertionError(output.getvalue())
Пример #2
0
def migrate_all():
    """
    Create schema migrations for all apps specified in INSTALLED_APPS,
    then run a migrate command.
    """
    if 'south' in settings.INSTALLED_APPS:
        return _south_migrate_all()
    from django.core.management.commands import makemigrations, migrate
    schema_args = [sys.executable, 'makemigrations']
    for app in settings.INSTALLED_APPS:
        if not app.startswith('django'):
            schema_args += [app]
    schema_cmd = makemigrations.Command()
    schema_cmd.run_from_argv(schema_args)

    migrate_cmd = migrate.Command()
    print "MIGRATE ALL!"
    migrate_cmd.run_from_argv([sys.executable, 'migrate'])
Пример #3
0
def run_makemigrations(module):
    """
    Run the equivalent of ./manage.py makemigrations [module]
    """
    mkmigrate_cmd = makemigrations.Command()
    args = (module,)
    options = {
        'verbosity': 1,
        'settings': None,
        'pythonpath': None,
        'traceback': False,
        'no_color': False,
        'force_color': False,
        'dry_run': False,
        'merge': False,
        'empty': False,
        'interactive': True,
        'name': None,
        'include_header': True,
        'check_changes': False
    }
    mkmigrate_cmd.handle(*args, **options)
Пример #4
0
import os
import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'serverless_micro_django.settings')
django.setup()

from django.core import management
from django.core.management.commands import makemigrations


management.call_command(makemigrations.Command())
Пример #5
0
#!/usr/bin/env python
import os
import sys

import django

if __name__ == '__main__':
    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings'
    # TODO: need to move tracker into a subfolder so this isn't necessary
    sys.path.append(
        os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
    django.setup()

    from django.core import management
    from django.core.management.commands import migrate
    from django.core.management.commands import makemigrations

    management.call_command(migrate.Command())
    management.call_command(makemigrations.Command(), check=True, dry_run=True)
Пример #6
0
    def handle(self, *args, **options):

        # initialize database
        user = options['user']
        pwd = options['password']
        email = options['email']
        tester = options['tester']
        tester_config = options['config_file']
        create_tester_config = options['create_tester_config']

        # Create tester config will return immediately without init db
        if create_tester_config:
            with open(tester_config, 'wt') as f:
                f.write(
                    os.linesep.join([
                        '# Tester configurations (tester is set in settings.py).',
                        '# Update me before run auto-unittests.',
                        '# Unittest will select the configured MQ to perform tests on.'
                    ]))
                for section, confs in ConfKeys.items():
                    for k, v in confs.items():
                        f.write('%s= %s' % (v, os.linesep))
            return 'Tester configuration file is created at %s' % tester_config

        # init db & migrate
        print('Initialize Database ...')
        call_command(makemigrations.Command(), 'pyqueuer')
        call_command(migrate.Command())

        # create admin
        print('Creating admin user "%s" ...' % user)
        try:
            if pwd:
                call_command(createsuperuser.Command(),
                             '--noinput',
                             username=user,
                             email=email)
                u = User.objects.get(username__exact=user)
                u.set_password(raw_password=pwd)
                u.save()
            else:
                call_command(createsuperuser.Command(),
                             username=user,
                             email=email)

        except IntegrityError:
            sys.stderr.write('  Admin with same name is already existed.' +
                             os.linesep)
        else:
            print('  Admin user "%s" created. Email is "%s"' % (user, email))

        # create tester
        if tester:
            name = pwd = settings.TESTER
            print('Creating test user "%s"...' % name)
            try:
                u = User.objects.create(username=name)
                u.email = email
                u.set_password(raw_password=pwd)
                u.is_active = True
                u.save()
            except IntegrityError:
                sys.stderr.write('  Tester is already existed.' + os.linesep)
            else:
                print(
                    '  Tester is created. Username and password are both "%s".'
                    % name)

            # load tester configurations from tester json
            # Use "manage.py config --import my_config.ini" to import config only.
            if tester_config:
                print('Load config for tester.')
                options = {
                    "import": tester_config,
                    "config_file": tester_config,
                    "user": settings.TESTER,
                    "password": settings.TESTER
                }
                call_command('config', **options)
            # with open(tester_config, 'rt') as f:
            #     tester_dict = json.load(f)
            #
            # user = authenticate(username=name, password=pwd)
            # ucf = UserConf(user=user)
            # for k, v in tester_dict['test_user_config'].items():
            #     ucf.set(k, v)
            # return 'Tester configuration loaded from json %s' % tester_config

        return