@@ -204,10 +204,10 @@ def test_adds_STATIC_and_MEDIA_config_to_settings(self, virtualenvs_folder):
204204 f .write (
205205 dedent (
206206 """
207- # settings file
208- STATIC_URL = '/static/'
209- ALLOWED_HOSTS = []
210- """
207+ # settings file
208+ STATIC_URL = '/static/'
209+ ALLOWED_HOSTS = []
210+ """
211211 )
212212 )
213213
@@ -229,10 +229,10 @@ def test_adds_domain_to_ALLOWED_HOSTS(self, virtualenvs_folder):
229229 f .write (
230230 dedent (
231231 """
232- # settings file
233- STATIC_URL = '/static/'
234- ALLOWED_HOSTS = []
235- """
232+ # settings file
233+ STATIC_URL = '/static/'
234+ ALLOWED_HOSTS = []
235+ """
236236 )
237237 )
238238
@@ -243,6 +243,78 @@ def test_adds_domain_to_ALLOWED_HOSTS(self, virtualenvs_folder):
243243
244244 assert "ALLOWED_HOSTS = ['mydomain.com']" in lines
245245
246+ def test_only_adds_MEDIA_URL_if_its_not_already_there (self , virtualenvs_folder ):
247+ project = DjangoProject ("mydomain.com" , "python.version" )
248+ project .settings_path = Path (tempfile .NamedTemporaryFile ().name )
249+
250+ with project .settings_path .open ("w" ) as f :
251+ f .write (
252+ dedent (
253+ """
254+ # settings file
255+ STATIC_URL = '/static/'
256+ ALLOWED_HOSTS = []
257+ MEDIA_ROOT = media_root
258+ """
259+ )
260+ )
261+
262+ project .update_settings_file ()
263+
264+ with project .settings_path .open () as f :
265+ lines = f .read ().split ("\n " )
266+
267+ assert "MEDIA_ROOT = media_root" in lines
268+ assert "MEDIA_ROOT = os.path.join(BASE_DIR, 'media')" not in lines
269+
270+ def test_only_adds_STATIC_ROOT_if_its_not_already_there (self , virtualenvs_folder ):
271+ project = DjangoProject ("mydomain.com" , "python.version" )
272+ project .settings_path = Path (tempfile .NamedTemporaryFile ().name )
273+
274+ with project .settings_path .open ("w" ) as f :
275+ f .write (
276+ dedent (
277+ """
278+ # settings file
279+ STATIC_URL = '/static/'
280+ ALLOWED_HOSTS = []
281+ STATIC_ROOT = static_root
282+ """
283+ )
284+ )
285+
286+ project .update_settings_file ()
287+
288+ with project .settings_path .open () as f :
289+ lines = f .read ().split ("\n " )
290+
291+ assert "STATIC_ROOT = '/static/'" not in lines
292+ assert "STATIC_ROOT = static_root" in lines
293+
294+ def test_only_adds_MEDIA_ROOT_if_its_not_already_there (self , virtualenvs_folder ):
295+ project = DjangoProject ("mydomain.com" , "python.version" )
296+ project .settings_path = Path (tempfile .NamedTemporaryFile ().name )
297+
298+ with project .settings_path .open ("w" ) as f :
299+ f .write (
300+ dedent (
301+ """
302+ # settings file
303+ STATIC_URL = '/static/'
304+ ALLOWED_HOSTS = []
305+ MEDIA_ROOT = media_root
306+ """
307+ )
308+ )
309+
310+ project .update_settings_file ()
311+
312+ with project .settings_path .open () as f :
313+ lines = f .read ().split ("\n " )
314+
315+ assert "MEDIA_ROOT = media_root" in lines
316+ assert "MEDIA_ROOT = os.path.join(BASE_DIR, 'media')" not in lines
317+
246318
247319class TestRunCollectStatic :
248320 def test_runs_manage_py_in_correct_virtualenv (self , mock_subprocess , fake_home , virtualenvs_folder ):
@@ -275,6 +347,7 @@ def test_updates_wsgi_file_from_template(self, virtualenvs_folder):
275347
276348 with project .wsgi_file_path .open () as f :
277349 contents = f .read ()
350+
278351 print (contents )
279352 assert contents == template .format (project = project )
280353
@@ -289,6 +362,7 @@ def test_actually_produces_wsgi_file_that_can_import_project_non_nested(
289362 project .create_virtualenv (django_version = "latest" )
290363 else :
291364 project .create_virtualenv ()
365+
292366 project .find_django_files ()
293367 project .wsgi_file_path = Path (tempfile .NamedTemporaryFile ().name )
294368
@@ -308,6 +382,7 @@ def test_actually_produces_wsgi_file_that_can_import_nested_project(
308382 project .create_virtualenv (django_version = "latest" )
309383 else :
310384 project .create_virtualenv ()
385+
311386 project .find_django_files ()
312387 project .wsgi_file_path = Path (tempfile .NamedTemporaryFile ().name )
313388
0 commit comments