コード例 #1
0
ファイル: test_manage_commands.py プロジェクト: sdc50/tethys
    def test_get_manage_path(self):
        # mock the input args with manage attribute
        args = mock.MagicMock(manage='')

        # call the method
        ret = manage_commands.get_manage_path(args=args)

        # check whether the response has manage
        self.assertIn('manage.py', ret)
コード例 #2
0
    def test_get_manage_path(self):
        # mock the input args with manage attribute
        args = mock.MagicMock(manage='')

        # call the method
        ret = manage_commands.get_manage_path(args=args)

        # check whether the response has manage
        self.assertIn('manage.py', ret)
コード例 #3
0
def uninstall_command(args):
    """
    Uninstall an app command.
    """
    # Get the path to manage.py
    manage_path = get_manage_path(args)
    item_name = args.app_or_extension
    process = ['python', manage_path, 'tethys_app_uninstall', item_name]
    if args.is_extension:
        process.append('-e')
    try:
        subprocess.call(process)
    except KeyboardInterrupt:
        pass
コード例 #4
0
ファイル: syncstores_command.py プロジェクト: john3641/tethys
def syncstores_command(args):
    """
    Sync persistent stores.
    """
    # Get the path to manage.py
    manage_path = get_manage_path(args)

    # This command is a wrapper for a custom Django manage.py method called syncstores.
    # See tethys_apps.mangement.commands.syncstores
    process = ['python', manage_path, 'syncstores']

    if args.refresh:
        valid_inputs = ('y', 'n', 'yes', 'no')
        no_inputs = ('n', 'no')
        proceed = input(
            '{1}WARNING:{2} You have specified the database refresh option. This will drop all of the '
            'databases for the following apps: {0}. This could result in significant data loss and '
            'cannot be undone. Do you wish to continue? (y/n): '.format(
                ', '.join(args.app), TC_WARNING, TC_ENDC)).lower()

        while proceed not in valid_inputs:
            proceed = input(
                'Invalid option. Do you wish to continue? (y/n): ').lower()

        if proceed not in no_inputs:
            process.extend(['-r'])
        else:
            print('Operation cancelled by user.')
            exit(0)

    if args.firsttime:
        process.extend(['-f'])

    if args.database:
        process.extend(['-d', args.database])

    if args.app:
        process.extend(args.app)

    try:
        subprocess.call(process)
    except KeyboardInterrupt:
        pass
コード例 #5
0
def syncstores_command(args):
    """
    Sync persistent stores.
    """
    # Get the path to manage.py
    manage_path = get_manage_path(args)

    # This command is a wrapper for a custom Django manage.py method called syncstores.
    # See tethys_apps.mangement.commands.syncstores
    process = ['python', manage_path, 'syncstores']

    if args.refresh:
        valid_inputs = ('y', 'n', 'yes', 'no')
        no_inputs = ('n', 'no')
        proceed = input('{1}WARNING:{2} You have specified the database refresh option. This will drop all of the '
                        'databases for the following apps: {0}. This could result in significant data loss and '
                        'cannot be undone. Do you wish to continue? (y/n): '.format(', '.join(args.app),
                                                                                    TC_WARNING,
                                                                                    TC_ENDC)).lower()

        while proceed not in valid_inputs:
            proceed = input('Invalid option. Do you wish to continue? (y/n): ').lower()

        if proceed not in no_inputs:
            process.extend(['-r'])
        else:
            print('Operation cancelled by user.')
            exit(0)

    if args.firsttime:
        process.extend(['-f'])

    if args.database:
        process.extend(['-d', args.database])

    if args.app:
        process.extend(args.app)

    try:
        subprocess.call(process)
    except KeyboardInterrupt:
        pass
コード例 #6
0
ファイル: test_command.py プロジェクト: sdc50/tethys
def test_command(args):
    args.manage = False
    # Get the path to manage.py
    manage_path = get_manage_path(args)
    tests_path = os.path.join(TETHYS_SRC_DIRECTORY, 'tests')

    # Define the process to be run
    primary_process = ['python', manage_path, 'test']

    # Tag to later check if tests are being run on a specific app or extension
    app_package_tag = 'tethys_apps.tethysapp.'
    extension_package_tag = 'tethysext.'

    if args.coverage or args.coverage_html:
        os.environ['TETHYS_TEST_DIR'] = tests_path
        if args.file and app_package_tag in args.file:
            app_package_parts = args.file.split(app_package_tag)
            app_name = app_package_parts[1].split('.')[0]
            core_app_package = '{}{}'.format(app_package_tag, app_name)
            app_package = 'tethysapp.{}'.format(app_name)
            config_opt = '--source={},{}'.format(core_app_package, app_package)
        elif args.file and extension_package_tag in args.file:
            extension_package_parts = args.file.split(extension_package_tag)
            extension_name = extension_package_parts[1].split('.')[0]
            core_extension_package = '{}{}'.format(extension_package_tag, extension_name)
            extension_package = 'tethysext.{}'.format(extension_name)
            config_opt = '--source={},{}'.format(core_extension_package, extension_package)
        else:
            config_opt = '--rcfile={0}'.format(os.path.join(tests_path, 'coverage.cfg'))
        primary_process = ['coverage', 'run', config_opt, manage_path, 'test']

    if args.file:
        primary_process.append(args.file)
    elif args.unit:
        primary_process.append(os.path.join(tests_path, 'unit_tests'))
    elif args.gui:
        primary_process.append(os.path.join(tests_path, 'gui_tests'))

    test_status = run_process(primary_process)

    if args.coverage:
        if args.file and (app_package_tag in args.file or extension_package_tag in args.file):
            run_process(['coverage', 'report'])
        else:
            run_process(['coverage', 'report', config_opt])

    if args.coverage_html:
        report_dirname = 'coverage_html_report'
        index_fname = 'index.html'

        if args.file and (app_package_tag in args.file or extension_package_tag in args.file):
            run_process(['coverage', 'html', '--directory={0}'.format(os.path.join(tests_path, report_dirname))])
        else:
            run_process(['coverage', 'html', config_opt])

        try:
            status = run_process(['open', os.path.join(tests_path, report_dirname, index_fname)])
            if status != 0:
                raise Exception
        except Exception:
            webbrowser.open_new_tab(os.path.join(tests_path, report_dirname, index_fname))

    exit(test_status)