def post_test(self, conf): self.stop_app_threat() # flush database with django execute_from_command_line(['scriptname', 'flush', '--noinput']) dutils.teardown_databases(conf, 1) dutils.teardown_test_environment() subprocess.run(['/sbin/iptables', '-F', 'INPUT']) subprocess.run(['/sbin/iptables', '-F', 'OUTPUT'])
def AssembleApp(self, data, basedir, options): # Fixup Django settings. Turn DEBUG off. This might speed up # program execution if e.g. database queries are not logged. settings.DEBUG = False # Switch to the throw-away test database so no database records # we create in this command are persistent. from django.test.utils import setup_databases, teardown_databases dbinfo = setup_databases(True, False) try: # Read the customized organization name, which substitutes in for # {{organization}} in templates.. organization_name = "<Organization Name>" if isinstance(data.get("organization"), dict) \ and isinstance(data["organization"].get("name"), str): organization_name = data["organization"]["name"] # Create stub data structures that are required to do module logic # but that have mostly no end-user-visible presence. The only thing # visible here is the organization's name, which gets substituted # in {{organization}} variables in document templates. self.dummy_org = Organization.objects.create( name=organization_name, subdomain=get_random_string(12)) self.dummy_user = User.objects.create( username=get_random_string(12)) # Cache app sources and app instances as we load app data into the # database so that when sources and apps occur multiple times we # reuse the existing instances in the database. self.app_sources = {} self.app_instances = {} # Start the app. project = self.start_app(data.get("app"), basedir) if project: # no error # Fill in the answers. self.set_answers(project.root_task, data.setdefault("questions", []), basedir, options) # Generate outputs if outdir was given on the command line. if options["outdir"]: self.save_outputs(project, options["outdir"]) finally: # Clean up the throw-away test database. teardown_databases(dbinfo, 1) for level in ("WARN", "ERROR"): print( termcolor.colored( "{} {}(s)".format( self.logcounts.get(level, 0), LOG_NAMES[level], ), LOG_COLORS[level]))
def teardown_database(): with django_db_blocker.unblock(): try: teardown_databases(db_cfg, verbosity=request.config.option.verbose) except Exception as exc: request.node.warn( pytest.PytestWarning( "Error when trying to teardown test databases: %r" % exc))
def handle(self, *accessors, **options): old_config = setup_databases(0, False) try: for fixture in get_fixtures(*accessors): fixture.create(), call_command('flush', verbosity=0, interactive=False) self.stdout.write(f'Fixture {fixture.name} has been created.') except Exception as exception: self.stderr.write(str(exception)) finally: teardown_databases(old_config, 0)
def main(): # type: (...) -> None """ Wraps :func:`unittest.main` with the necessary Django setup. If your test code also requires importing Django models, call :func:setup before making those imports. """ import django.test.utils as d_t_utils try: d_t_utils.setup_test_environment() old_config = d_t_utils.setup_databases(verbosity=1, interactive=False) unittest.main() finally: d_t_utils.teardown_databases(old_config, verbosity=1) d_t_utils.teardown_test_environment()
def handle(self, *, verbosity, session_config_name, num_participants, export_path, **options): self.prepare_global_state() setup_test_environment() old_config = setup_databases(interactive=False, verbosity=verbosity, aliases={'default'}) try: run_all_bots_for_session_config( session_config_name=session_config_name, num_participants=num_participants, export_path=export_path, ) finally: teardown_databases(old_config, verbosity=verbosity) teardown_test_environment()
def handle(self, *args, **options): # Fix up some settings. self.fixup_django_settings() # Start the headless browser. self.start_headless_browser(options['size']) self.mouse_speed = options["mouse_speed"] # Prepare for taking screenshots. if options['path']: self.init_screenshots(options) # Switch to the throw-away test database so no database records # we create in this command are persistent. from django.test.utils import setup_databases, teardown_databases dbinfo = setup_databases(True, False) # Initialize the database. from guidedmodules.management.commands.load_modules import Command as load_modules load_modules().handle() try: # Create a user and organization. self.init_user_organization(options) # Run a script on the headless browser, generating # a bunch of screenshots. if options['app']: self.screenshot_app(options) if options['author_new_app']: self.screenshot_author_new_app(options) # Combine images into a PDF. if getattr(self, 'write_pdf_filename', None): self.write_pdf() finally: # Clean up the throw-away test database. teardown_databases(dbinfo, 1) # Close selenium. self.stop_headless_browser()
def handle(self, *args, **options): # Fix up some settings. self.fixup_django_settings() # Start the headless browser. self.start_headless_browser(options['size']) # Prepare for taking screenshots. self.init_screenshots(options) # Switch to the throw-away database. from django.test.utils import setup_databases, teardown_databases dbinfo = setup_databases(True, False) # Initialize the database. from guidedmodules.management.commands.load_modules import Command as load_modules load_modules().handle() try: # Create a user and organization. self.init_user_organization(options) # Run a script on the headless browser, generating # a bunch of screenshots. if options['app']: self.screenshot_app(options) if options['author_new_app']: self.screenshot_author_new_app(options) # Combine images into a PDF. if self.write_pdf_filename: self.write_pdf() finally: teardown_databases(dbinfo, 1) self.stop_headless_browser()
def pytest_sessionfinish(session, exitstatus): db_cfg = getattr(session, 'django_db_cfg') if db_cfg: from django.test import utils utils.teardown_databases(db_cfg, verbosity=session.config.option.verbose)
def tearDown(self): teardown_databases(self.old_config, False)
def tearDownClass(cls): super().tearDownClass() teardown_databases(cls._old_db_conf, verbosity=1)
def _teardown_environment(self, old_config): teardown_databases(old_config=old_config, verbosity=1, parallel=0, keepdb=self.keepdb) teardown_test_environment()
def tearDownClass(cls) -> None: teardown_databases([(connection, 'default', True)], verbosity=0)
args=[data.project.id]), HTTP_HOST=host) write_test_html("apps", "refund_editor", refund_create.content) sticky_header = client.get( reverse("job.editor", args=[data.big_project.id, data.big_job.id]), HTTP_HOST=host, ) write_test_html("editor", "sticky_header", sticky_header.content) activate("de") write_test_html("inputs", "amount", generate_amount_test_html(data)) if __name__ == "__main__": class DisableMigrations: def __contains__(self, item): return True def __getitem__(self, item): return None settings.MIGRATION_MODULES = DisableMigrations() print("Creating test database.") config = setup_databases(verbosity=0, interactive=False) print("Generating scaffolds.") generate_pages() print("Done.") teardown_databases(config, verbosity=0)
def _teardown_database(): with django_db_blocker.unblock(): teardown_databases(db_cfg, verbosity=request.config.option.verbose)
def tearDownModule(): django_test_utils.teardown_databases(test_state['runner_state'], verbosity=0) django_test_utils.teardown_test_environment()
def teardown(self, keepdb=settings.KEEP_DATABASE): teardown_databases(self.old_config, 1, keepdb=keepdb)
def post_test(self, conf): self.stop_app_threat() dutils.teardown_databases(conf, 1) dutils.teardown_test_environment() subprocess.run(['/sbin/iptables', '-F', 'INPUT']) subprocess.run(['/sbin/iptables', '-F', 'OUTPUT'])