本文整理匯總了Python中django.setup方法的典型用法代碼示例。如果您正苦於以下問題:Python django.setup方法的具體用法?Python django.setup怎麽用?Python django.setup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django
的用法示例。
在下文中一共展示了django.setup方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def run(self, arguments, *args, **kwargs):
try:
os.environ.setdefault(
'DJANGO_SETTINGS_MODULE', arguments.django_settings)
import django
if hasattr(django, 'setup'):
django.setup()
except ImportError:
raise Py2SwaggerPluginException('Invalid django settings module')
from .introspectors.api import ApiIntrospector
from .urlparser import UrlParser
# Patch Djago REST Framework, to make inspection process slightly easier
from . import injection
apis = UrlParser().get_apis(filter_path=arguments.filter)
a = ApiIntrospector(apis)
return a.inspect()
示例2: _tests
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def _tests(self):
settings.configure(
DEBUG=True,
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(self.DIRNAME, 'database.db'),
}
},
INSTALLED_APPS=self.INSTALLED_APPS + self.apps,
MIDDLEWARE=self.MIDDLEWARE,
ROOT_URLCONF='django_classified.tests.urls',
STATIC_URL='/static/',
TEMPLATES=self.TEMPLATES,
SITE_ID=1
)
from django.test.runner import DiscoverRunner
test_runner = DiscoverRunner()
django.setup()
failures = test_runner.run_tests(self.apps)
if failures:
sys.exit(failures)
示例3: runtests
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def runtests(*test_args):
if not settings.configured:
settings.configure(**DEFAULT_SETTINGS)
# Compatibility with Django 1.7's stricter initialization
if hasattr(django, "setup"):
django.setup()
parent = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, parent)
try:
from django.test.runner import DiscoverRunner
runner_class = DiscoverRunner
test_args = ["pinax.documents.tests"]
except ImportError:
from django.test.simple import DjangoTestSuiteRunner
runner_class = DjangoTestSuiteRunner
test_args = ["tests"]
failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args)
sys.exit(failures)
示例4: test_log_error
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def test_log_error(self):
"""Tests an error trace telemetry is properly sent"""
django.setup()
logger = logging.getLogger(__name__)
msg = "An error log message"
logger.error(msg)
event = self.get_events(1)
data = event["data"]["baseData"]
props = data["properties"]
self.assertEqual(
event["name"], "Microsoft.ApplicationInsights.Message", "Event type"
)
self.assertEqual(event["iKey"], TEST_IKEY)
self.assertEqual(data["message"], msg, "Log message")
self.assertEqual(data["severityLevel"], 3, "Severity level")
self.assertEqual(props["fileName"], "tests.py", "Filename property")
self.assertEqual(props["level"], "ERROR", "Level property")
self.assertEqual(props["module"], "tests", "Module property")
示例5: test_log_info
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def test_log_info(self):
"""Tests an info trace telemetry is properly sent"""
django.setup()
logger = logging.getLogger(__name__)
msg = "An info message"
logger.info(msg)
event = self.get_events(1)
data = event["data"]["baseData"]
props = data["properties"]
self.assertEqual(
event["name"], "Microsoft.ApplicationInsights.Message", "Event type"
)
self.assertEqual(event["iKey"], TEST_IKEY)
self.assertEqual(data["message"], msg, "Log message")
self.assertEqual(data["severityLevel"], 1, "Severity level")
self.assertEqual(props["fileName"], "tests.py", "Filename property")
self.assertEqual(props["level"], "INFO", "Level property")
self.assertEqual(props["module"], "tests", "Module property")
示例6: runtests
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def runtests():
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings'
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner()
# By default, run all of the tests
tests = ['tests']
# Allow running a subset of tests via the command line.
if len(sys.argv) > 1:
tests = sys.argv[1:]
failures = test_runner.run_tests(tests, verbosity=3)
if failures:
sys.exit(failures)
示例7: run_tests
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def run_tests(self):
import django
django.setup()
from django.conf import settings
from django.test.utils import get_runner
TestRunner = get_runner(settings, self.testrunner)
test_runner = TestRunner(
pattern=self.pattern,
top_level=self.top_level_directory,
verbosity=self.verbose,
interactive=(not self.noinput),
failfast=self.failfast,
keepdb=self.keepdb,
reverse=self.reverse,
debug_sql=self.debug_sql,
output_dir=self.output_dir)
failures = test_runner.run_tests(self.test_labels)
sys.exit(bool(failures))
示例8: run_tests_coverage
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def run_tests_coverage():
if __name__ == "__main__":
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner()
# Setup Coverage
cov = coverage(source=["rest_framework_docs"], omit=["rest_framework_docs/__init__.py"])
cov.start()
failures = test_runner.run_tests(["tests"])
if bool(failures):
cov.erase()
sys.exit("Tests Failed. Coverage Cancelled.")
# If success show coverage results
cov.stop()
cov.save()
cov.report()
cov.html_report(directory='covhtml')
示例9: run_tests
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def run_tests():
# Making Django run this way is a two-step process. First, call
# settings.configure() to give Django settings to work with:
from django.conf import settings
settings.configure(**SETTINGS_DICT)
# Then, call django.setup() to initialize the application registry
# and other bits:
import django
django.setup()
# Now we instantiate a test runner...
from django.test.utils import get_runner
TestRunner = get_runner(settings)
# And then we run tests and return the results.
test_runner = TestRunner(verbosity=2, interactive=True)
failures = test_runner.run_tests(["tests"])
sys.exit(failures)
示例10: main
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def main():
"""Link credentials to devices"""
django.setup()
net_devices = NetworkDevice.objects.all()
creds = Credentials.objects.all()
std_creds = creds[0]
arista_creds = creds[1]
for a_device in net_devices:
if 'arista' in a_device.device_type:
a_device.credentials = arista_creds
else:
a_device.credentials = std_creds
a_device.save()
for a_device in net_devices:
print a_device, a_device.credentials
示例11: main
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def main():
'''
Remove the two objects created in exercise #3 from the database.
'''
django.setup()
try:
test_rtr1 = NetworkDevice.objects.get(device_name='test-rtr1')
test_rtr2 = NetworkDevice.objects.get(device_name='test-rtr2')
test_rtr1.delete()
test_rtr2.delete()
except NetworkDevice.DoesNotExist:
pass
# Verify devices that currently exist
print
devices = NetworkDevice.objects.all()
for a_device in devices:
print a_device
print
示例12: main
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def main():
'''
Set the vendor field for each NetworkDevice to the appropriate vendor. Save
this field to the database.
'''
django.setup()
devices = NetworkDevice.objects.all()
for a_device in devices:
if 'cisco' in a_device.device_type:
a_device.vendor = 'Cisco'
elif 'juniper' in a_device.device_type:
a_device.vendor = 'Juniper'
elif 'arista' in a_device.device_type:
a_device.vendor = 'Arista'
a_device.save()
for a_device in devices:
print a_device, a_device.vendor
示例13: main
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def main():
'''
Use threads and Netmiko to connect to each of the devices in the database. Execute
'show version' on each device. Record the amount of time required to do this.
'''
django.setup()
start_time = datetime.now()
devices = NetworkDevice.objects.all()
for a_device in devices:
my_thread = threading.Thread(target=show_version, args=(a_device,))
my_thread.start()
main_thread = threading.currentThread()
for some_thread in threading.enumerate():
if some_thread != main_thread:
print some_thread
some_thread.join()
print "\nElapsed time: " + str(datetime.now() - start_time)
示例14: main
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def main():
default_cass = import_module('settings.default_cassandra')
default_only_cass = import_module('settings.default_only_cassandra')
secondary_cassandra = import_module('settings.secondary_cassandra')
multi_cassandra = import_module('settings.multi_cassandra')
metadata_disabled = import_module('settings.metadata_disabled')
django.setup()
run_tests(default_cass)
run_tests(default_only_cass)
run_tests(secondary_cassandra)
run_tests(multi_cassandra)
run_tests(metadata_disabled)
sys.exit(0)
示例15: generate_integration_bots_avatars
# 需要導入模塊: import django [as 別名]
# 或者: from django import setup [as 別名]
def generate_integration_bots_avatars(check_missing: bool=False) -> None:
missing = set()
for webhook in WEBHOOK_INTEGRATIONS:
if not webhook.logo_path:
continue
bot_avatar_path = webhook.get_bot_avatar_path()
if bot_avatar_path is None:
continue
bot_avatar_path = os.path.join(ZULIP_PATH, 'static', bot_avatar_path)
if check_missing:
if not os.path.isfile(bot_avatar_path):
missing.add(webhook.name)
else:
create_integration_bot_avatar(static_path(webhook.logo_path), bot_avatar_path)
if missing:
print('ERROR: Bot avatars are missing for these webhooks: {}.\n'
'ERROR: Run ./tools/setup/generate_integration_bots_avatars.py '
'to generate them.\nERROR: Commit the newly generated avatars to '
'the repository.'.format(', '.join(missing)))
sys.exit(1)