def pytest_sessionstart(session): """ Set up the test environment. Set DJANGO_SETTINGS_MODULE, adds the vendor lib, and sets up a test database. """ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "datazilla.settings.base") add_vendor_lib() from django.conf import settings from django.test.simple import DjangoTestSuiteRunner # we don't actually let Django run the tests, but we need to use some # methods of its runner for setup/teardown of dbs and some other things session.django_runner = DjangoTestSuiteRunner() # this provides templates-rendered debugging info and locmem mail storage session.django_runner.setup_test_environment() # support custom db prefix for tests for the main datazilla datasource # as well as for the testproj and testpushlog dbs prefix = getattr(settings, "TEST_DB_PREFIX", "") settings.DATABASES["default"]["TEST_NAME"] = "{0}test_datazilla".format(prefix) # this sets up a clean test-only database session.django_db_config = session.django_runner.setup_databases() # store the name of the test project/pushlog based on user custom settings session.perftest_name = "{0}testproj".format(prefix) session.pushlog_name = "{0}testpushlog".format(prefix) increment_cache_key_prefix() from datazilla.model import PerformanceTestModel, PushLogModel ptm = PerformanceTestModel.create( session.perftest_name, cron_batch="small", ) PushLogModel.create(project=session.pushlog_name) # patch in additional test-only procs on the datasources objstore = ptm.sources["objectstore"] del objstore.dhub.procs[objstore.datasource.key] objstore.dhub.data_sources[objstore.datasource.key]["procs"].append( os.path.join( os.path.abspath(os.path.dirname(__file__)), "objectstore_test.json", ) ) objstore.dhub.load_procs(objstore.datasource.key) perftest = ptm.sources["perftest"] del perftest.dhub.procs[perftest.datasource.key] perftest.dhub.data_sources[perftest.datasource.key]["procs"].append( os.path.join( os.path.abspath(os.path.dirname(__file__)), "perftest_test.json", ) ) perftest.dhub.load_procs(perftest.datasource.key)
def pytest_sessionstart(session): """ Set up the test environment. Set DJANGO_SETTINGS_MODULE, adds the vendor lib, and sets up a test database. """ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "datazilla.settings.base") add_vendor_lib() from django.conf import settings from django.test.simple import DjangoTestSuiteRunner # we don't actually let Django run the tests, but we need to use some # methods of its runner for setup/teardown of dbs and some other things session.django_runner = DjangoTestSuiteRunner() # this provides templates-rendered debugging info and locmem mail storage session.django_runner.setup_test_environment() # support custom db prefix for tests for the main datazilla datasource # as well as for the testproj and testpushlog dbs prefix = getattr(settings, "TEST_DB_PREFIX", "") settings.DATABASES["default"]["TEST_NAME"] = "{0}test_datazilla".format( prefix) # this sets up a clean test-only database session.django_db_config = session.django_runner.setup_databases() # store the name of the test project/pushlog based on user custom settings session.perftest_name = "{0}testproj".format(prefix) session.pushlog_name = "{0}testpushlog".format(prefix) increment_cache_key_prefix() from datazilla.model import PerformanceTestModel, PushLogModel ptm = PerformanceTestModel.create( session.perftest_name, cron_batch="small", ) PushLogModel.create(project=session.pushlog_name) # patch in additional test-only procs on the datasources objstore = ptm.sources["objectstore"] del objstore.dhub.procs[objstore.datasource.key] objstore.dhub.data_sources[objstore.datasource.key]["procs"].append( os.path.join( os.path.abspath(os.path.dirname(__file__)), "objectstore_test.json", )) objstore.dhub.load_procs(objstore.datasource.key) perftest = ptm.sources["perftest"] del perftest.dhub.procs[perftest.datasource.key] perftest.dhub.data_sources[perftest.datasource.key]["procs"].append( os.path.join( os.path.abspath(os.path.dirname(__file__)), "perftest_test.json", )) perftest.dhub.load_procs(perftest.datasource.key)
def handle(self, *args, **options): """ Create databases for a new project based on the args value. """ host = options.get("host") project = options.get("project") if not host: self.println("You must supply a host name for the pushlog " + "database: --host hostname") return pl = PushLogModel.create( project=project, host=host, type=options.get("type"), ) self.println("Pushlog database created on {0}".format(host)) pl.disconnect()