MCPcopy
hub / github.com/django/django / write_settings

Method write_settings

tests/admin_scripts/tests.py:62–100  ·  view source on GitHub ↗
(self, filename, apps=None, is_dir=False, sdict=None, extra=None)

Source from the content-addressed store, hash-verified

60 os.mkdir(self.test_dir)
61
62 def write_settings(self, filename, apps=None, is_dir=False, sdict=None, extra=None):
63 if is_dir:
64 settings_dir = os.path.join(self.test_dir, filename)
65 os.mkdir(settings_dir)
66 settings_file_path = os.path.join(settings_dir, "__init__.py")
67 else:
68 settings_file_path = os.path.join(self.test_dir, filename)
69
70 with open(settings_file_path, "w") as settings_file:
71 settings_file.write(
72 "# Settings file automatically generated by admin_scripts test case\n"
73 )
74 if extra:
75 settings_file.write("%s\n" % extra)
76 exports = [
77 "DATABASES",
78 "ROOT_URLCONF",
79 "SECRET_KEY",
80 "USE_TZ",
81 ]
82 for s in exports:
83 if hasattr(settings, s):
84 o = getattr(settings, s)
85 if not isinstance(o, (dict, tuple, list)):
86 o = "'%s'" % o
87 settings_file.write("%s = %s\n" % (s, o))
88
89 if apps is None:
90 apps = [
91 "django.contrib.auth",
92 "django.contrib.contenttypes",
93 "admin_scripts",
94 ]
95
96 settings_file.write("INSTALLED_APPS = %s\n" % apps)
97
98 if sdict:
99 for k, v in sdict.items():
100 settings_file.write("%s = %s\n" % (k, v))
101
102 def _ext_backend_paths(self):
103 """

Callers 15

test_skip_checksMethod · 0.80
setUpMethod · 0.80
setUpMethod · 0.80
setUpMethod · 0.80
setUpMethod · 0.80
setUpMethod · 0.80
setUpMethod · 0.80
setUpMethod · 0.80

Calls 3

joinMethod · 0.45
writeMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected