Example #1
0
def runtests(*test_args, **kwargs):
    if not test_args:
        test_args = ['fktree']

    test_runner = NoseTestSuiteRunner(**kwargs)
    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
def run_tests(verbosity, *test_args):
    if not test_args:
        test_args = ['url_tracker']
    test_runner = NoseTestSuiteRunner(verbosity=verbosity)
    num_failures = test_runner.run_tests(test_args)
    if num_failures:
        sys.exit(num_failures)
Example #3
0
def run_tests(options, *test_args):
    test_runner = NoseTestSuiteRunner(verbosity=options.verbosity, pdb=options.pdb)
    if not test_args:
        test_args = ["tests"]
    num_failures = test_runner.run_tests(test_args)
    if num_failures:
        sys.exit(num_failures)
Example #4
0
def run_tests(verbosity, *test_args):
    test_runner = NoseTestSuiteRunner(verbosity=verbosity)
    if not test_args:
        test_args = ['tests']
    num_failures = test_runner.run_tests(test_args)
    if num_failures:
        sys.exit(num_failures)
Example #5
0
    def run_tests(self):
        from django.conf import settings

        db_engine = os.environ.get('DJANGO_DB_ENGINE', 'sqlite')
        if db_engine == 'mysql':
            db_settings = {
                'ENGINE': 'django.db.backends.mysql',
                'NAME': os.environ['DJANGO_DB_NAME'],
                'USER': os.environ['DJANGO_DB_USER'],
            }
        elif db_engine == 'postgres':
            db_settings = {
                'ENGINE': 'django.db.backends.postgresql_psycopg2',
                'NAME': os.environ['DJANGO_DB_NAME'],
                'USER': os.environ['DJANGO_DB_USER'],
            }
        elif db_engine == 'sqlite':
            db_settings = {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': os.path.join(self.DIRNAME, 'database.db'),
            }
        else:
            raise ValueError("Unknown DB engine: %s" % db_engine)

        # Common settings.
        settings.configure(
            DEBUG=True,
            DATABASES={'default': db_settings},
            CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}},
            INSTALLED_APPS=('django_nose',) + self.APPS)

        from django_nose import NoseTestSuiteRunner
        runner = NoseTestSuiteRunner(failfast=False, interactive=False)
        sys.exit(runner.run_tests(self.APPS))
Example #6
0
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    test_runner = NoseTestSuiteRunner(verbosity=1)
    num_failures = test_runner.run_tests(test_args)
    if num_failures > 0:
        sys.exit(num_failures)
Example #7
0
def run_tests(*test_args, **kwargs):
    if not test_args:
        test_args = ['django_kittens']

    kwargs.setdefault('interactive', False)
    test_runner = NoseTestSuiteRunner(**kwargs)
    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
def runtests(*test_args, **kwargs):
    if StrictVersion(django.get_version()) >= StrictVersion('1.7'):
        django.setup()

    kwargs.setdefault('interactive', False)
    test_runner = NoseTestSuiteRunner(**kwargs)
    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
def runtests(*test_args, **kwargs):
    if django.VERSION >= (1, 7):
        django.setup()

    kwargs.setdefault('interactive', False)
    test_runner = NoseTestSuiteRunner(**kwargs)
    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
Example #10
0
def run_tests(*test_args):
    from django_nose import NoseTestSuiteRunner
    test_runner = NoseTestSuiteRunner()
    if not test_args:
        test_args = ['tests']
    num_failures = test_runner.run_tests(test_args)
    if num_failures:
        sys.exit(num_failures)
Example #11
0
def run(verbosity, *args):
    from django_nose import NoseTestSuiteRunner
    runner = NoseTestSuiteRunner(verbosity=verbosity)
    if not args:
        args = ['tests']
    num_failures = runner.run_tests(args)
    if num_failures:
        sys.exit(num_failures)
Example #12
0
def runtests(*test_args, **kwargs):
    if 'south' in settings.INSTALLED_APPS:
        from south.management.commands import patch_for_test_db_setup
        patch_for_test_db_setup()

    test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    # Run tests
    test_runner = NoseTestSuiteRunner(verbosity=1)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
def runtests(*test_args, **kwargs):
    # Slice to avoid StrictVersion errors with versions like 1.8c1
    if StrictVersion(django.get_version()[0:3]) >= StrictVersion('1.7'):
        django.setup()

    kwargs.setdefault('interactive', False)
    test_runner = NoseTestSuiteRunner(**kwargs)
    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
Example #15
0
def run_tests(verbosity, *test_args):
    from django_nose import NoseTestSuiteRunner

    test_runner = NoseTestSuiteRunner(verbosity=verbosity)
    if not test_args:
        test_args = ["tests"]
    num_failures = test_runner.run_tests(test_args)
    if num_failures:
        sys.exit(num_failures)
Example #16
0
def run_nose_tests(*test_args):
    from django_nose import NoseTestSuiteRunner

    test_runner = NoseTestSuiteRunner(test_args)

    failures = test_runner.run_tests(test_args)

    if failures:
        sys.exit(failures)
def run_tests(*test_args, **kwargs):
    if not test_args:
        test_args = ['entity_event_slack']

    kwargs.setdefault('interactive', False)

    test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
def runtests(*test_args, **kwargs):
    if not test_args:
        test_args = ['tests']
    # Do not prompt to destroy existing db
    kwargs.setdefault('interactive', False)

    test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
Example #19
0
def run_tests(*test_args, **kwargs):
    if not test_args:
        test_args = ["db_mutex"]

    kwargs.setdefault("interactive", False)

    test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
def run_tests(*test_args, **kwargs):
    if not test_args:
        test_args = ['deletion_side_effects']

    kwargs.setdefault('interactive', False)

    test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
Example #21
0
 def __init__(self, *test_args, **kwargs):
     super(TestsWrapper, self).__init__()
     if 'south' in settings.INSTALLED_APPS:
         from south.management.commands import patch_for_test_db_setup
         patch_for_test_db_setup()
     if not test_args:
         test_args = ['cmsroles.tests']
         kwargs.setdefault('interactive', False)
         test_runner = NoseTestSuiteRunner(**kwargs)
         self._failures = test_runner.run_tests(test_args)
def run_tests(*test_args, **kwargs):
    if not test_args:
        test_args = ['dynamic_initial_data']

    kwargs.setdefault('interactive', False)

    test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
def run_tests(*test_args, **kwargs):
    if not test_args:
        test_args = ['localized_recurrence']

    kwargs.setdefault('interactive', False)

    test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
Example #24
0
def run_tests(options, *test_args):
    from django_nose import NoseTestSuiteRunner
    test_runner = NoseTestSuiteRunner(verbosity=options.verbosity,
                                      pdb=options.pdb,
                                      )
    if not test_args:
        test_args = ['tests']
    num_failures = test_runner.run_tests(test_args)
    if num_failures:
        sys.exit(num_failures)
def runtests(*test_args, **kwargs):
    if not test_args:
        test_args = ["tests"]

    kwargs.setdefault("interactive", False)
    # kwargs.setdefault('verbosity')
    test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
Example #26
0
def run_tests(*test_args):
    if not test_args:
        test_args = ['django_twilio/tests']

    # Run tests
    test_runner = NoseTestSuiteRunner(verbosity=1)

    failures = test_runner.run_tests(test_args)

    if failures:
        sys.exit(failures)
Example #27
0
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests', '--with-coverage', '--cover-package=bank']

    # Run tests
    test_runner = NoseTestSuiteRunner(verbosity=1)

    failures = test_runner.run_tests(test_args)

    if failures:
        sys.exit(failures)
def run_tests(*test_args):
    if not test_args:
        test_args = ['emailmessagetemplates.tests']

    # Run tests
    test_runner = NoseTestSuiteRunner(verbosity=1)

    failures = test_runner.run_tests(test_args)

    if failures:
        sys.exit(failures)
def run_tests(*test_args, **kwargs):

    if not test_args:
        test_args = ['{{ project_name }}']

    kwargs.setdefault('interactive', False)

    test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
def runtests(*test_args, **kwargs):
    if django.VERSION >= (1, 7):
        django.setup()

    kwargs.setdefault('interactive', False)
    test_runner = NoseTestSuiteRunner(**kwargs)
    try:
        failures = test_runner.run_tests(test_args)
        sys.exit(failures)
    except TypeError: # Django 1.11 issue? it fails on destroying test database: test suite teardown
        sys.exit(0)
Example #31
0
def runtests(*test_args, **kwargs):
    if 'south' in settings.INSTALLED_APPS:
        from south.management.commands import patch_for_test_db_setup
        patch_for_test_db_setup()

    if not test_args:
        test_args = ['uuidfield']

    import django
    try:
        django.setup()
    except AttributeError:
        pass

    kwargs.setdefault('interactive', False)

    test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
Example #32
0
def run_tests(*test_args):
    if 'south' in settings.INSTALLED_APPS:
        from south.management.commands import patch_for_test_db_setup
        patch_for_test_db_setup()

    if not test_args:
        test_args = ['tests']

    # Run tests
    test_runner = NoseTestSuiteRunner(verbosity=1)

    c = coverage(source=['paymentexpress'], omit=['*migrations*', '*tests*'])
    c.start()
    num_failures = test_runner.run_tests(test_args)
    c.stop()

    if num_failures > 0:
        sys.exit(num_failures)
    print "Generating HTML coverage report"
    c.html_report()
Example #33
0
    def run_tests(self):
        from django.conf import settings
        settings.configure(
            DEBUG=True,
            DATABASES={
                'default': {
                    'ENGINE': 'django.db.backends.sqlite3',
                    'NAME': os.path.join(self.DIRNAME, 'database.db')
                }
            },
            CACHES={
                'default': {
                    'BACKEND': 'django.core.cache.backends.dummy.DummyCache'
                }
            },
            INSTALLED_APPS=('django_nose', ) + self.APPS)

        from django_nose import NoseTestSuiteRunner
        runner = NoseTestSuiteRunner(failfast=False, interactive=False)
        sys.exit(runner.run_tests(self.APPS))
Example #34
0
    def run_tests(self):
        from django.conf import settings

        db_engine = os.environ.get('DJANGO_DB_ENGINE', 'sqlite')
        if db_engine == 'mysql':
            db_settings = {
                'ENGINE': 'django.db.backends.mysql',
                'NAME': os.environ['DJANGO_DB_NAME'],
                'USER': os.environ['DJANGO_DB_USER'],
            }
        elif db_engine == 'postgres':
            db_settings = {
                'ENGINE': 'django.db.backends.postgresql_psycopg2',
                'NAME': os.environ['DJANGO_DB_NAME'],
                'USER': os.environ['DJANGO_DB_USER'],
            }
        elif db_engine == 'sqlite':
            db_settings = {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': os.path.join(self.DIRNAME, 'database.db'),
            }
        else:
            raise ValueError("Unknown DB engine: %s" % db_engine)

        # Common settings.
        settings.configure(
            DEBUG=True,
            DATABASES={'default': db_settings},
            CACHES={
                'default': {
                    'BACKEND': 'django.core.cache.backends.dummy.DummyCache'
                }
            },
            INSTALLED_APPS=('django_nose', ) + self.APPS)

        import django
        django.setup()  # pylint: disable=no-member

        from django_nose import NoseTestSuiteRunner
        runner = NoseTestSuiteRunner(failfast=False, interactive=False)
        sys.exit(runner.run_tests(self.APPS))
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    test_args += [
        '--nologcapture',
    ]

    # Run tests
    test_runner = NoseTestSuiteRunner(verbosity=1)

    c = coverage(source=['worldpay'],
                 omit=['*migrations*', '*tests*'],
                 auto_data=True)
    c.start()
    num_failures = test_runner.run_tests(test_args)
    c.stop()

    if num_failures > 0:
        sys.exit(num_failures)
    print("Generating HTML coverage report")
    c.html_report()
Example #36
0
def runtests(*test_args, **kwargs):
    from django_nose import NoseTestSuiteRunner
    if 'south' in settings.INSTALLED_APPS:
        from south.management.commands import patch_for_test_db_setup
        patch_for_test_db_setup()

    test_args = test_args or []

    if 'verbosity' in kwargs:
        kwargs['verbosity'] = int(kwargs['verbosity'])

    kwargs.setdefault('interactive', False)

    test_args.append('--with-coverage')
    test_args.append('--cover-package=swingers')
    test_args.append('--cover-xml')
    test_args.append('--cover-xml-file=coverage.xml')

    test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
Example #37
0
def run_tests(*test_args):
    if not test_args:
        test_args = ['cmsplugin_googleplus']

    # see:
    # https://docs.djangoproject.com/en/dev/releases/1.7/#standalone-scripts
    django.setup()
    from django.core.management import call_command
    call_command("makemigrations", "cmsplugin_googleplus", database='default')
    call_command("migrate", database='default')

    from django_nose import NoseTestSuiteRunner
    failures = NoseTestSuiteRunner().run_tests(test_args)
    if failures:  # pragma: no cover
        sys.exit(failures)
Example #38
0
def before_all(context):
    chroma_settings()

    import django

    django.setup()

    # Take a TestRunner hostage.
    # Use django_nose's runner so that we can take advantage of REUSE_DB=1.
    from django_nose import NoseTestSuiteRunner

    # We'll use these later to frog-march Django through the motions
    # of setting up and tearing down the test environment, including
    # test databases.
    context.runner = NoseTestSuiteRunner()
Example #39
0
def runtests(*test_args, **kwargs):
    if 'south' in settings.INSTALLED_APPS:
        from south.management.commands import patch_for_test_db_setup
        patch_for_test_db_setup()

    if not test_args:
        test_args = ['celery_rpc']

    if sys.version_info >= (3, 10, 0):
        from django.test.runner import DiscoverRunner
        test_runner = DiscoverRunner(**kwargs)
    else:
        test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
def before_all(context):
    settings = chroma_settings()
    from django.core.management import setup_environ
    setup_environ(settings)

    ### Take a TestRunner hostage.
    # Use django_nose's runner so that we can take advantage of REUSE_DB=1.
    from django_nose import NoseTestSuiteRunner
    # We'll use these later to frog-march Django through the motions
    # of setting up and tearing down the test environment, including
    # test databases.
    context.runner = NoseTestSuiteRunner()

    ## If you use South for migrations, uncomment this to monkeypatch
    ## syncdb to get migrations to run.
    from south.management.commands import patch_for_test_db_setup
    patch_for_test_db_setup()
Example #41
0
def runtests(*test_args):
    warnings.simplefilter('always')
    failures = NoseTestSuiteRunner(verbosity=2, interactive=True).run_tests(
        test_args)
    sys.exit(failures)
Example #42
0
import sys

from django.conf import settings

settings.configure(
    DATABASES={"default": {
        "ENGINE": "django.db.backends.sqlite3",
    }},
    ROOT_URLCONF="user_messages.urls",
    TEMPLATE_CONTEXT_PROCESSORS=[
        "user_messages.context_processors.user_messages",
    ],
    INSTALLED_APPS=[
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "django.contrib.sessions",
        "user_messages",
    ])

from django_nose import NoseTestSuiteRunner

test_runner = NoseTestSuiteRunner(verbosity=1)
failures = test_runner.run_tests(["user_messages"])

if failures:
    sys.exit(failures)
Example #43
0
    DATABASES={
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
        }
    },
    ROOT_URLCONF='testurlconf',
    INSTALLED_APPS=(
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.admin',
        'django.contrib.staticfiles',
        'emoji',
    ),
    MIDDLEWARE_CLASSES=(
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
    ),
    STATIC_URL='/static/',
    TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),),
)

if django.VERSION[0] == 1 and django.VERSION[1] >= 7:
    django.setup()

from django_nose import NoseTestSuiteRunner  # Can't be imported earlier
test_runner = NoseTestSuiteRunner()
failures = test_runner.run_tests(['emoji', ])
if failures:
    sys.exit(failures)
Example #44
0
def runtests(*test_args, **test_kwargs):
    failures = NoseTestSuiteRunner(verbosity=2, interactive=False).run_tests(
        test_args,
        test_kwargs,
    )
    sys.exit(failures)
Example #45
0
def run_test_suite(args):
    skip_utc = args.skip_utc
    enable_coverage = not args.no_coverage
    enable_pep8 = not args.no_pep8

    if enable_coverage:
        cov = Coverage(config_file=True)
        cov.erase()
        cov.start()

    settings.configure(
        DJSTRIPE_TESTS_SKIP_UTC=skip_utc,
        TIME_ZONE='America/Los_Angeles',
        DEBUG=True,
        USE_TZ=True,
        DATABASES={
            "default": {
                "ENGINE": "django.db.backends.postgresql_psycopg2",
                "NAME": "djstripe",
                "USER": "",
                "PASSWORD": "",
                "HOST": "",
                "PORT": "",
            },
        },
        ROOT_URLCONF="tests.test_urls",
        INSTALLED_APPS=[
            "django.contrib.admin", "django.contrib.auth",
            "django.contrib.contenttypes", "django.contrib.sessions",
            "django.contrib.sites", "jsonfield", "djstripe", "tests",
            "tests.apps.testapp"
        ],
        MIDDLEWARE_CLASSES=(
            "django.contrib.sessions.middleware.SessionMiddleware",
            "django.contrib.auth.middleware.AuthenticationMiddleware",
            "django.contrib.messages.middleware.MessageMiddleware"),
        SITE_ID=1,
        STRIPE_PUBLIC_KEY=os.environ.get("STRIPE_PUBLIC_KEY", ""),
        STRIPE_SECRET_KEY=os.environ.get("STRIPE_SECRET_KEY", ""),
        DJSTRIPE_PLANS={
            "test0": {
                "stripe_plan_id": "test_id_0",
                "name": "Test Plan 0",
                "description": "A test plan",
                "price": 1000,  # $10.00
                "currency": "usd",
                "interval": "month"
            },
            "test": {
                "stripe_plan_id": "test_id",
                "name": "Test Plan 1",
                "description": "Another test plan",
                "price": 2500,  # $25.00
                "currency": "usd",
                "interval": "month"
            },
            "test2": {
                "stripe_plan_id": "test_id_2",
                "name": "Test Plan 2",
                "description": "Yet Another test plan",
                "price": 5000,  # $50.00
                "currency": "usd",
                "interval": "month"
            },
            "test_deletion": {
                "stripe_plan_id": "test_id_3",
                "name": "Test Plan 3",
                "description": "Test plan for deletion.",
                "price": 5000,  # $50.00
                "currency": "usd",
                "interval": "month"
            },
            "test_trial": {
                "stripe_plan_id": "test_id_4",
                "name": "Test Plan 4",
                "description": "Test plan for trails.",
                "price": 7000,  # $70.00
                "currency": "usd",
                "interval": "month",
                "trial_period_days": 7
            },
            "unidentified_test_plan": {
                "name": "Unidentified Test Plan",
                "description": "A test plan with no ID.",
                "price": 2500,  # $25.00
                "currency": "usd",
                "interval": "month"
            }
        },
        DJSTRIPE_PLAN_HIERARCHY={
            "bronze": {
                "level": 1,
                "plans": [
                    "test0",
                    "test",
                ]
            },
            "silver": {
                "level": 2,
                "plans": [
                    "test2",
                    "test_deletion",
                ]
            },
            "gold": {
                "level": 3,
                "plans": [
                    "test_trial",
                    "unidentified_test_plan",
                ]
            },
        },
        DJSTRIPE_SUBSCRIPTION_REQUIRED_EXCEPTION_URLS=(
            "(admin)",
            "test_url_name",
            "testapp_namespaced:test_url_namespaced",
        ),
    )

    # Avoid AppRegistryNotReady exception
    # http://stackoverflow.com/questions/24793351/django-appregistrynotready
    if hasattr(django, "setup"):
        django.setup()

    # Announce the test suite
    sys.stdout.write(
        colored(text="\nWelcome to the ", color="magenta", attrs=["bold"]))
    sys.stdout.write(colored(text="dj-stripe", color="green", attrs=["bold"]))
    sys.stdout.write(
        colored(text=" test suite.\n\n", color="magenta", attrs=["bold"]))

    # Announce test run
    sys.stdout.write(
        colored(text="Step 1: Running unit tests.\n\n",
                color="yellow",
                attrs=["bold"]))

    # Hack to reset the global argv before nose has a chance to grab it
    # http://stackoverflow.com/a/1718407/1834570
    args = sys.argv[1:]
    sys.argv = sys.argv[0:1]

    from django_nose import NoseTestSuiteRunner

    test_runner = NoseTestSuiteRunner(verbosity=1)
    failures = test_runner.run_tests(["."])

    if failures:
        sys.exit(failures)

    if enable_coverage:
        # Announce coverage run
        sys.stdout.write(
            colored(text="\nStep 2: Generating coverage results.\n\n",
                    color="yellow",
                    attrs=["bold"]))

        cov.stop()
        percentage = round(cov.report(show_missing=True), 2)
        cov.html_report(directory='cover')
        cov.save()

        if percentage < TESTS_THRESHOLD:
            sys.stderr.write(
                colored(
                    text="YOUR CHANGES HAVE CAUSED TEST COVERAGE TO DROP. " +
                    "WAS {old}%, IS NOW {new}%.\n\n".format(
                        old=TESTS_THRESHOLD, new=percentage),
                    color="red",
                    attrs=["bold"]))
            sys.exit(1)
    else:
        # Announce disabled coverage run
        sys.stdout.write(
            colored(text="\nStep 2: Generating coverage results [SKIPPED].",
                    color="yellow",
                    attrs=["bold"]))

    if enable_pep8:
        # Announce flake8 run
        sys.stdout.write(
            colored(text="\nStep 3: Checking for pep8 errors.\n\n",
                    color="yellow",
                    attrs=["bold"]))

        print("pep8 errors:")
        print(
            "----------------------------------------------------------------------"
        )

        from subprocess import call
        flake_result = call(["flake8", ".", "--count"])
        if flake_result != 0:
            sys.stderr.write("pep8 errors detected.\n")
            sys.stderr.write(
                colored(text="\nYOUR CHANGES HAVE INTRODUCED PEP8 ERRORS!\n\n",
                        color="red",
                        attrs=["bold"]))
            sys.exit(flake_result)
        else:
            print("None")
    else:
        # Announce disabled coverage run
        sys.stdout.write(
            colored(text="\nStep 3: Checking for pep8 errors [SKIPPED].\n",
                    color="yellow",
                    attrs=["bold"]))

    # Announce success
    if enable_coverage and enable_pep8:
        sys.stdout.write(
            colored(
                text=
                "\nTests completed successfully with no errors. Congrats!\n",
                color="green",
                attrs=["bold"]))
    else:
        sys.stdout.write(
            colored(
                text=
                "\nTests completed successfully, but some step(s) were skipped!\n",
                color="green",
                attrs=["bold"]))
        sys.stdout.write(
            colored(text="Don't push without running the skipped step(s).\n",
                    color="red",
                    attrs=["bold"]))
Example #46
0
def run_tests(nose_options, test_args):
    if not test_args:
        test_args = ['tests']
    test_runner = NoseTestSuiteRunner(verbosity=nose_options.verbosity)
    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
Example #47
0
def runtests(*test_args, **kwargs):
    kwargs.setdefault('interactive', False)
    test_runner = NoseTestSuiteRunner(**kwargs)
    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
Example #48
0
def main(*test_args):
    sys.exit(
        NoseTestSuiteRunner(verbosity=2,
                            interactive=True).run_tests(test_args))
Example #49
0
def runtests(*test_labels):
    runner = NoseTestSuiteRunner(verbosity=1, interactive=True)
    failures = runner.run_tests(test_labels)
    sys.exit(failures)
Example #50
0
def main():
    """
    The entry point for the script. This script is fairly basic. Here is a
    quick example of how to use it::

        app_test_runner.py [path-to-app]

    You must have Django on the PYTHONPATH prior to running this script. This
    script basically will bootstrap a Django environment for you.

    By default this script with use SQLite and an in-memory database. If you
    are using Python 2.5 it will just work out of the box for you.

    TODO: show more options here.
    """
    parser = OptionParser()
    parser.add_option("--DATABASE_ENGINE",
                      dest="DATABASE_ENGINE",
                      default="sqlite3")
    parser.add_option("--DATABASE_NAME", dest="DATABASE_NAME", default="")
    parser.add_option("--DATABASE_USER", dest="DATABASE_USER", default="")
    parser.add_option("--DATABASE_PASSWORD",
                      dest="DATABASE_PASSWORD",
                      default="")
    parser.add_option("--SITE_ID", dest="SITE_ID", type="int", default=1)

    options, args = parser.parse_args()

    # check for app in args
    app_path = 'paypaladaptive'
    parent_dir, app_name = os.path.split(app_path)
    sys.path.insert(0, parent_dir)

    settings.configure(
        **{
            "PAYPAL_APPLICATION_ID":
            'fake',
            "PAYPAL_USERID":
            'fake',
            "PAYPAL_PASSWORD":
            '******',
            "PAYPAL_SIGNATURE":
            'test',
            "PAYPAL_EMAIL":
            "*****@*****.**",
            "DATABASES": {
                'default': {
                    "ENGINE": 'django.db.backends.%s' %
                    options.DATABASE_ENGINE,
                    "NAME": options.DATABASE_NAME,
                    "USER": options.DATABASE_USER,
                    "PASSWORD": options.DATABASE_PASSWORD,
                }
            },
            "SITE_ID":
            options.SITE_ID,
            "ROOT_URLCONF":
            app_name + ".urls",
            "TEMPLATE_LOADERS": (
                "django.template.loaders.filesystem.Loader",
                "django.template.loaders.app_directories.Loader",
                "django.template.loaders.eggs.Loader",
            ),
            "TEMPLATE_DIRS": (os.path.join(os.path.dirname(__file__),
                                           "paypaladaptive/templates"), ),
            "INSTALLED_APPS": (
                "django.contrib.auth",
                "django.contrib.contenttypes",
                "django.contrib.sessions",
                "django.contrib.sites",
                app_name,
            ),
            "LOGGING": {
                'version': 1,
                'disable_existing_loggers': False,
                'formatters': {
                    'verbose': {
                        'format':
                        '%(levelname)s %(asctime)s %(module)s %(process)d '
                        '%(thread)d %(message)s'
                    },
                },
                'handlers': {
                    'console': {
                        'level': 'DEBUG',
                        'class': 'logging.StreamHandler',
                        'formatter': 'verbose',
                    }
                },
                'loggers': {
                    app_name: {
                        'handlers': ['console'],
                        'level': 'DEBUG',
                        'formatter': 'verbose',
                        'propagate': True,
                    }
                }
            }
        })

    from django_nose import NoseTestSuiteRunner

    test_runner = NoseTestSuiteRunner(verbosity=1)
    failures = test_runner.run_tests(["."])

    if failures:
        sys.exit(failures)
Example #51
0
 def setUp(self):
     self.runner = NoseTestSuiteRunner()
Example #52
0
class GetModelsForConnectionTests(TestCase):
    tables = ['test_table%d' % i for i in range(5)]

    def _connection_mock(self, tables):
        class FakeIntrospection(object):
            def get_table_list(*args, **kwargs):
                return tables

        class FakeConnection(object):
            introspection = FakeIntrospection()
            cursor = lambda x: None

        return FakeConnection()

    def _model_mock(self, db_table):
        class FakeModel(object):
            _meta = type('meta', (object,), {'db_table': db_table})()

        return FakeModel()

    @contextmanager
    def _cache_mock(self, tables=[]):
        def get_models(*args, **kwargs):
            return [self._model_mock(t) for t in tables]

        old = cache.get_models
        cache.get_models = get_models
        yield
        cache.get_models = old

    def setUp(self):
        self.runner = NoseTestSuiteRunner()

    def test_no_models(self):
        """For a DB with no tables, return nothing."""
        connection = self._connection_mock([])
        with self._cache_mock(['table1', 'table2']):
            self.assertEqual(
                self.runner._get_models_for_connection(connection), [])

    def test_wrong_models(self):
        """If no tables exists for models, return nothing."""
        connection = self._connection_mock(self.tables)
        with self._cache_mock(['table1', 'table2']):
            self.assertEqual(
                self.runner._get_models_for_connection(connection), [])

    def test_some_models(self):
        """If some of the models has appropriate table in the DB, return matching models."""
        connection = self._connection_mock(self.tables)
        with self._cache_mock(self.tables[1:3]):
            result_tables = [m._meta.db_table for m in
                             self.runner._get_models_for_connection(connection)]
        self.assertEqual(result_tables, self.tables[1:3])

    def test_all_models(self):
        """If all the models have appropriate tables in the DB, return them all."""
        connection = self._connection_mock(self.tables)
        with self._cache_mock(self.tables):
            result_tables = [m._meta.db_table for m in
                             self.runner._get_models_for_connection(connection)]
        self.assertEqual(result_tables, self.tables)
    'DATABASES': {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'circle_test',
            'USER': '******',
            'PASSWORD': '******',
            'HOST': '127.0.0.1',
        }
    },
    'NOSE_ARGS': [
        '--with-coverage',
        '--cover-package=mobile_redirect.tests',
        '--cover-xml',
        '--cover-xml-file=%s/coverage.xml' % results_base_dir,
        '--with-xunit',
        '--xunit-file=%s/nosetests.xml' % results_base_dir,
    ],
    'ROOT_URLCONF': 'mobile_redirect.tests.urls',
}

settings.configure(**params)

from django_nose import NoseTestSuiteRunner

runner = NoseTestSuiteRunner()

failures = runner.run_tests(['mobile_redirect'])

if failures:
    sys.exit(failures)
Example #54
0
import sys

from django.conf import settings

settings.configure(
    DEBUG=True,
    USE_TZ=True,
    DATABASES={"default": {
        "ENGINE": "django.db.backends.sqlite3",
    }},
    ROOT_URLCONF="notification.urls",
    INSTALLED_APPS=[
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "django.contrib.sites",
        "notification",
    ],
    STRIPE_PUBLIC_KEY="",
    STRIPE_SECRET_KEY="",
    PAYMENTS_PLANS={})

from django_nose import NoseTestSuiteRunner

test_runner = NoseTestSuiteRunner(verbosity=1)
failures = test_runner.run_tests(["notification"])

if failures:
    sys.exit(failures)
# -*- coding: utf-8 -*-

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

from django_nose import NoseTestSuiteRunner

if __name__ == '__main__':
    if NoseTestSuiteRunner(verbosity=1).run_tests(['tests']) > 0:
        exit(1)
    else:
        exit(0)
Example #56
0
import sys

from django.conf import settings

settings.configure(
    DEBUG=True,
    USE_TZ=True,
    DATABASES={
        "default": {
            "ENGINE": "django.db.backends.sqlite3",
        }
    },
    ROOT_URLCONF="waitinglist.urls",
    INSTALLED_APPS=[
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "django.contrib.sites",
        "account",
        "waitinglist",
    ],
    SITE_ID=1
)

from django_nose import NoseTestSuiteRunner

test_runner = NoseTestSuiteRunner(verbosity=1)
failures = test_runner.run_tests(["waitinglist"])

if failures:
    sys.exit(failures)
Example #57
0
# Announce the test suite
sys.stdout.write(
    colored(text="\nWelcome to the ", color="magenta", attrs=["bold"]))
sys.stdout.write(colored(text="dj-stripe", color="green", attrs=["bold"]))
sys.stdout.write(
    colored(text=" test suite.\n\n", color="magenta", attrs=["bold"]))

# Announce test run
sys.stdout.write(
    colored(text="Step 1: Running unit tests.\n\n",
            color="yellow",
            attrs=["bold"]))

from django_nose import NoseTestSuiteRunner

test_runner = NoseTestSuiteRunner(verbosity=1)
failures = test_runner.run_tests(["."])

if failures:
    sys.exit(failures)

# Announce coverage run
sys.stdout.write(
    colored(text="\nStep 2: Generating coverage results.\n\n",
            color="yellow",
            attrs=["bold"]))

cov.stop()
percentage = round(cov.report(show_missing=True), 2)
cov.html_report(directory='cover')
cov.save()
Example #58
0
def run_test_suite(args):
    enable_coverage = not args.no_coverage
    tests = args.tests

    if enable_coverage:
        cov = Coverage(config_file=True)
        cov.erase()
        cov.start()

    test_db_name = os.environ.get('DJSTRIPE_TEST_DB_NAME', 'djstripe')
    test_db_user = os.environ.get('DJSTRIPE_TEST_DB_USER', 'postgres')
    test_db_pass = os.environ.get('DJSTRIPE_TEST_DB_PASS', '')

    settings.configure(
        DEBUG=True,
        SECRET_KEY="djstripe",
        SITE_ID=1,
        TIME_ZONE="UTC",
        USE_TZ=True,
        DATABASES={
            "default": {
                "ENGINE": "django.db.backends.postgresql_psycopg2",
                "NAME": test_db_name,
                "USER": test_db_user,
                "PASSWORD": test_db_pass,
                "HOST": "localhost",
                "PORT": "",
            },
        },
        TEMPLATES=[
            {
                'BACKEND': 'django.template.backends.django.DjangoTemplates',
                'DIRS': [],
                'APP_DIRS': True,
                'OPTIONS': {
                    'context_processors': [
                        'django.contrib.auth.context_processors.auth',
                    ],
                },
            },
        ],
        ROOT_URLCONF="tests.test_urls",
        INSTALLED_APPS=[
            "django.contrib.admin", "django.contrib.auth",
            "django.contrib.contenttypes", "django.contrib.sessions",
            "django.contrib.sites", "jsonfield", "djstripe", "tests",
            "tests.apps.testapp"
        ],
        MIDDLEWARE=("django.contrib.sessions.middleware.SessionMiddleware",
                    "django.contrib.auth.middleware.AuthenticationMiddleware",
                    "django.contrib.messages.middleware.MessageMiddleware"),
        STRIPE_PUBLIC_KEY=os.environ.get("STRIPE_PUBLIC_KEY", ""),
        STRIPE_SECRET_KEY=os.environ.get("STRIPE_SECRET_KEY", ""),
        DJSTRIPE_PLANS={
            "test0": {
                "stripe_plan_id": "test_id_0",
                "name": "Test Plan 0",
                "description": "A test plan",
                "price": 1000,  # $10.00
                "currency": "usd",
                "interval": "month"
            },
            "test": {
                "stripe_plan_id": "test_id",
                "name": "Test Plan 1",
                "description": "Another test plan",
                "price": 2500,  # $25.00
                "currency": "usd",
                "interval": "month"
            },
            "test2": {
                "stripe_plan_id": "test_id_2",
                "name": "Test Plan 2",
                "description": "Yet Another test plan",
                "price": 5000,  # $50.00
                "currency": "usd",
                "interval": "month"
            },
            "test_deletion": {
                "stripe_plan_id": "test_id_3",
                "name": "Test Plan 3",
                "description": "Test plan for deletion.",
                "price": 5000,  # $50.00
                "currency": "usd",
                "interval": "month"
            },
            "test_trial": {
                "stripe_plan_id": "test_id_4",
                "name": "Test Plan 4",
                "description": "Test plan for trails.",
                "price": 7000,  # $70.00
                "currency": "usd",
                "interval": "month",
                "trial_period_days": 7
            },
            "unidentified_test_plan": {
                "name": "Unidentified Test Plan",
                "description": "A test plan with no ID.",
                "price": 2500,  # $25.00
                "currency": "usd",
                "interval": "month"
            }
        },
        DJSTRIPE_SUBSCRIPTION_REQUIRED_EXCEPTION_URLS=(
            "(admin)", "test_url_name",
            "testapp_namespaced:test_url_namespaced", "fn:/test_fnmatch*"),
        DJSTRIPE_USE_NATIVE_JSONFIELD=os.environ.get("USE_NATIVE_JSONFIELD",
                                                     "") == "1",
        DJSTRIPE_SUBSCRIPTION_REDIRECT="test_url_subscribe",
        DJSTRIPE_WEBHOOK_VALIDATION="retrieve_event",
    )

    # Avoid AppRegistryNotReady exception
    # http://stackoverflow.com/questions/24793351/django-appregistrynotready
    if hasattr(django, "setup"):
        django.setup()

    # Announce the test suite
    sys.stdout.write(
        colored(text="\nWelcome to the ", color="magenta", attrs=["bold"]))
    sys.stdout.write(colored(text="dj-stripe", color="green", attrs=["bold"]))
    sys.stdout.write(
        colored(text=" test suite.\n\n", color="magenta", attrs=["bold"]))

    # Announce test run
    sys.stdout.write(
        colored(text="Step 1: Running unit tests.\n\n",
                color="yellow",
                attrs=["bold"]))

    # Hack to reset the global argv before nose has a chance to grab it
    # http://stackoverflow.com/a/1718407/1834570
    args = sys.argv[1:]
    sys.argv = sys.argv[0:1]

    # Add the ability to run tests on executable files. This is important when running tests on WSL, where permissions
    # are dictated by Windows instead of Unix.
    sys.argv += ["--exe"]

    from django_nose import NoseTestSuiteRunner

    test_runner = NoseTestSuiteRunner(verbosity=1, keepdb=False, failfast=True)
    failures = test_runner.run_tests(tests)

    if failures:
        sys.exit(failures)

    if enable_coverage:
        # Announce coverage run
        sys.stdout.write(
            colored(text="\nStep 2: Generating coverage results.\n\n",
                    color="yellow",
                    attrs=["bold"]))

        cov.stop()
        percentage = round(cov.report(show_missing=True), 2)
        cov.html_report(directory='cover')
        cov.save()

        if percentage < TESTS_THRESHOLD:
            sys.stderr.write(
                colored(
                    text="YOUR CHANGES HAVE CAUSED TEST COVERAGE TO DROP. " +
                    "WAS {old}%, IS NOW {new}%.\n\n".format(
                        old=TESTS_THRESHOLD, new=percentage),
                    color="red",
                    attrs=["bold"]))
            sys.exit(1)
    else:
        # Announce disabled coverage run
        sys.stdout.write(
            colored(text="\nStep 2: Generating coverage results [SKIPPED].",
                    color="yellow",
                    attrs=["bold"]))

    # Announce success
    if enable_coverage:
        sys.stdout.write(
            colored(
                text=
                "\nTests completed successfully with no errors. Congrats!\n",
                color="green",
                attrs=["bold"]))
    else:
        sys.stdout.write(
            colored(
                text=
                "\nTests completed successfully, but some step(s) were skipped!\n",
                color="green",
                attrs=["bold"]))
        sys.stdout.write(
            colored(text="Don't push without running the skipped step(s).\n",
                    color="red",
                    attrs=["bold"]))
Example #59
0
def runtests(*test_labels):
    """Run the selected tests, or all tests if none selected."""
    from django_nose import NoseTestSuiteRunner
    runner = NoseTestSuiteRunner(verbosity=1, interactive=True)
    failures = runner.run_tests(test_labels)
    sys.exit(failures)
Example #60
0
def runtests(*test_labels):
    from django_nose import NoseTestSuiteRunner

    runner = NoseTestSuiteRunner(verbosity=1, interactive=True)
    failures = runner.run_tests(test_labels)
    sys.exit(failures)