@@ -196,9 +196,10 @@ def test_raises_if_manage_py_not_found(self, fake_home, non_nested_submodule, vi
196196
197197
198198class TestUpdateSettingsFile :
199- def test_adds_STATIC_and_MEDIA_config_to_settings (self , virtualenvs_folder ):
199+ def test_adds_STATIC_and_MEDIA_config_to_settings_with_old_django (self , virtualenvs_folder ):
200200 project = DjangoProject ("mydomain.com" , "python.version" )
201201 project .settings_path = Path (tempfile .NamedTemporaryFile ().name )
202+ project .virtualenv .get_version = Mock (return_value = "1.0" )
202203
203204 with project .settings_path .open ("w" ) as f :
204205 f .write (
@@ -221,9 +222,36 @@ def test_adds_STATIC_and_MEDIA_config_to_settings(self, virtualenvs_folder):
221222 assert "STATIC_ROOT = os.path.join(BASE_DIR, 'static')" in lines
222223 assert "MEDIA_ROOT = os.path.join(BASE_DIR, 'media')" in lines
223224
225+ def test_adds_STATIC_and_MEDIA_config_to_settings_with_new_django (self , virtualenvs_folder ):
226+ project = DjangoProject ("mydomain.com" , "python.version" )
227+ project .settings_path = Path (tempfile .NamedTemporaryFile ().name )
228+ project .virtualenv .get_version = Mock (return_value = "3.1.1" )
229+
230+ with project .settings_path .open ("w" ) as f :
231+ f .write (
232+ dedent (
233+ """
234+ # settings file
235+ STATIC_URL = '/static/'
236+ ALLOWED_HOSTS = []
237+ """
238+ )
239+ )
240+
241+ project .update_settings_file ()
242+
243+ with project .settings_path .open () as f :
244+ lines = f .read ().split ("\n " )
245+
246+ assert "STATIC_URL = '/static/'" in lines
247+ assert "MEDIA_URL = '/media/'" in lines
248+ assert "STATIC_ROOT = Path(BASE_DIR / 'static')" in lines
249+ assert "MEDIA_ROOT = Path(BASE_DIR / 'media')" in lines
250+
224251 def test_adds_domain_to_ALLOWED_HOSTS (self , virtualenvs_folder ):
225252 project = DjangoProject ("mydomain.com" , "python.version" )
226253 project .settings_path = Path (tempfile .NamedTemporaryFile ().name )
254+ project .virtualenv .get_version = Mock (return_value = "1.0" )
227255
228256 with project .settings_path .open ("w" ) as f :
229257 f .write (
@@ -246,6 +274,7 @@ def test_adds_domain_to_ALLOWED_HOSTS(self, virtualenvs_folder):
246274 def test_only_adds_MEDIA_URL_if_its_not_already_there (self , virtualenvs_folder ):
247275 project = DjangoProject ("mydomain.com" , "python.version" )
248276 project .settings_path = Path (tempfile .NamedTemporaryFile ().name )
277+ project .virtualenv .get_version = Mock (return_value = "1.0" )
249278
250279 with project .settings_path .open ("w" ) as f :
251280 f .write (
@@ -270,6 +299,7 @@ def test_only_adds_MEDIA_URL_if_its_not_already_there(self, virtualenvs_folder):
270299 def test_only_adds_STATIC_ROOT_if_its_not_already_there (self , virtualenvs_folder ):
271300 project = DjangoProject ("mydomain.com" , "python.version" )
272301 project .settings_path = Path (tempfile .NamedTemporaryFile ().name )
302+ project .virtualenv .get_version = Mock (return_value = "1.0" )
273303
274304 with project .settings_path .open ("w" ) as f :
275305 f .write (
@@ -294,6 +324,7 @@ def test_only_adds_STATIC_ROOT_if_its_not_already_there(self, virtualenvs_folder
294324 def test_only_adds_MEDIA_ROOT_if_its_not_already_there (self , virtualenvs_folder ):
295325 project = DjangoProject ("mydomain.com" , "python.version" )
296326 project .settings_path = Path (tempfile .NamedTemporaryFile ().name )
327+ project .virtualenv .get_version = Mock (return_value = "1.0" )
297328
298329 with project .settings_path .open ("w" ) as f :
299330 f .write (
0 commit comments