diff --git a/letterpress/firstrun.py b/letterpress/firstrun.py index 0d0c1df..b8528d7 100644 --- a/letterpress/firstrun.py +++ b/letterpress/firstrun.py @@ -1,4 +1,5 @@ -import importlib, uuid +import importlib +import uuid def import_settings_secret(): @@ -7,17 +8,19 @@ def import_settings_secret(): This is in its own method to accommodate unit testing """ - import letterpress.settings_secret as settings_secret + import letterpress.settings_secret as settings_secret # noqa def create_settings_secret(): """ Create new settings_secret.py with dummy values """ - print('settings_secret module not found, creating a dummy letterpress/settings_secret.py. You will want to edit this.') + print( + 'settings_secret module not found, creating a dummy letterpress/settings_secret.py. You will want to edit this.' + ) secret = '''# Generated by letterpress.firstrun - # You should edit this file. If it is missing, it will be recreated. + # You should edit this file. If it is missing, it will be recreated. SECRET_KEY="very very secret %s" ALLOWED_HOSTS=["0.0.0.0", "127.0.0.1", "localhost"] ''' % uuid.uuid4() @@ -32,7 +35,7 @@ def main(): """ try: import_settings_secret() - except ImportError as e: + except ImportError: create_settings_secret() diff --git a/letterpress/settings.py b/letterpress/settings.py index 84ed58c..af58dc4 100644 --- a/letterpress/settings.py +++ b/letterpress/settings.py @@ -78,8 +78,7 @@ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates'), - 'django/forms/templates'] - , + 'django/forms/templates'], 'APP_DIRS': False, 'OPTIONS': { 'context_processors': [ @@ -93,7 +92,7 @@ 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ], - 'debug': True, + 'debug': True, }, }, ] @@ -107,7 +106,7 @@ SPATIALITE_LIBRARY_PATH = 'mod_spatialite' # For Windows, set the location of the GDAL DLL and add the GDAL directory to your PATH for the other DLLs # Under Linux it doesn't seem to be necessary - GDAL_LIBRARY_PATH = 'C:\Program Files\GDAL\gdal201.dll' + GDAL_LIBRARY_PATH = 'C:\Program Files\GDAL\gdal201.dll' # noqa # A Fallback DB_DIR = BASE_DIR else: diff --git a/letterpress/tests/test_firstrun.py b/letterpress/tests/test_firstrun.py index d686b6f..e62f3cb 100644 --- a/letterpress/tests/test_firstrun.py +++ b/letterpress/tests/test_firstrun.py @@ -1,6 +1,5 @@ -from unittest.mock import Mock, patch +from unittest.mock import patch -from django.conf import settings from django.test import SimpleTestCase from letterpress.firstrun import create_settings_secret, import_settings_secret, main @@ -46,12 +45,16 @@ def test_main(self, mock_create_settings_secret, mock_import_settings_secret): # create_settings_secret() should not be called mock_import_settings_secret.side_effect = None main() - self.assertEqual(mock_create_settings_secret.call_count, 0, - "If there's no ImportError from import_settings_secret(), create_settings_secret() shouldn't be called") + self.assertEqual( + mock_create_settings_secret.call_count, 0, + "If there's no ImportError from import_settings_secret(), create_settings_secret() shouldn't be called" + ) # If there's an ImportError when calling import_settings_secret(), # create_settings_secret() should be called mock_import_settings_secret.side_effect = ImportError main() - self.assertEqual(mock_create_settings_secret.call_count, 1, - "If there's an ImportError from import_settings_secret(), create_settings_secret() should be called") + self.assertEqual( + mock_create_settings_secret.call_count, 1, + "If there's an ImportError from import_settings_secret(), create_settings_secret() should be called" + ) diff --git a/letterpress/tests/test_settings.py b/letterpress/tests/test_settings.py index 61b7d78..40c0415 100644 --- a/letterpress/tests/test_settings.py +++ b/letterpress/tests/test_settings.py @@ -3,7 +3,6 @@ from unittest.mock import patch -from django.conf import settings from django.test import SimpleTestCase # Normally Django settings should be imported as "from django.conf import settings" @@ -34,8 +33,10 @@ def test_circleci_settings(self): importlib.reload(letterpress.settings) # SECRET_KEY should NOT be 'super-duper-secret-key-for-circleci' - self.assertNotEqual(letterpress.settings.SECRET_KEY, 'super-duper-secret-key-for-circleci', - "When setting CIRCLECI isn't True, SECRET_KEY shouldn't be 'super-duper-secret-key-for-circleci'") + self.assertNotEqual( + letterpress.settings.SECRET_KEY, 'super-duper-secret-key-for-circleci', + "When setting CIRCLECI isn't True, SECRET_KEY shouldn't be 'super-duper-secret-key-for-circleci'" + ) # ALLOWED_HOSTS should NOT be [] self.assertNotEqual(letterpress.settings.ALLOWED_HOSTS, [], "When setting CIRCLECI isn't True, ALLOWED_HOSTS shouldn't be []") @@ -49,8 +50,10 @@ def test_circleci_settings(self): importlib.reload(letterpress.settings) # SECRET_KEY should be 'super-duper-secret-key-for-circleci' - self.assertEqual(letterpress.settings.SECRET_KEY, 'super-duper-secret-key-for-circleci', - "When setting CIRCLECI is True, SECRET_KEY should be 'super-duper-secret-key-for-circleci'") + self.assertEqual( + letterpress.settings.SECRET_KEY, 'super-duper-secret-key-for-circleci', + "When setting CIRCLECI is True, SECRET_KEY should be 'super-duper-secret-key-for-circleci'" + ) # ALLOWED_HOSTS should be [] self.assertEqual(letterpress.settings.ALLOWED_HOSTS, [], 'When setting CIRCLECI is True, ALLOWED_HOSTS should be []') @@ -100,5 +103,5 @@ def test_settings_for_windows(self, mock_system): self.assertFalse(letterpress.settings.SPATIALITE_LIBRARY_PATH.endswith('.so'), "On Windows, SPATIALITE_LIBRARY_PATH should not end with '.so'") - self.assertFalse(letterpress.settings.GDAL_LIBRARY_PATH == None, + self.assertFalse(letterpress.settings.GDAL_LIBRARY_PATH is None, 'On Windows, GDAL_LIBRARY_PATH should be set') diff --git a/letterpress/tests/test_views.py b/letterpress/tests/test_views.py index 3639e6d..3154cf5 100644 --- a/letterpress/tests/test_views.py +++ b/letterpress/tests/test_views.py @@ -47,4 +47,3 @@ def test_template_used(self): response = self.client.get(reverse('elasticsearch_error', kwargs={'error': 'Something went wrong', 'status': 406}), follow=True) self.assertTemplateUsed(response, 'elasticsearch_error.html') - diff --git a/letterpress/urls.py b/letterpress/urls.py index c837900..6b9c20a 100644 --- a/letterpress/urls.py +++ b/letterpress/urls.py @@ -17,7 +17,8 @@ path('admin/', admin.site.urls), path('accounts/', include('django.contrib.auth.urls')), path('', HomeView.as_view(), name='home'), - path('elasticsearch_error///', ElasticsearchErrorView.as_view(), name='elasticsearch_error'), + path('elasticsearch_error///', + ElasticsearchErrorView.as_view(), name='elasticsearch_error'), path('letters//sentiment//', LetterSentimentView.as_view(), name='letter_sentiment_view'), path('letters//', LetterDetailView.as_view(), name='letter_detail'),