Skip to content

Commit

Permalink
Fix misc. flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
clairempr committed Feb 5, 2023
1 parent 7dd2fef commit 3f5962b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
13 changes: 8 additions & 5 deletions letterpress/firstrun.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib, uuid
import importlib
import uuid


def import_settings_secret():
Expand All @@ -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()
Expand All @@ -32,7 +35,7 @@ def main():
"""
try:
import_settings_secret()
except ImportError as e:
except ImportError:
create_settings_secret()


Expand Down
7 changes: 3 additions & 4 deletions letterpress/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand All @@ -93,7 +92,7 @@
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
'debug': True,
'debug': True,
},
},
]
Expand All @@ -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:
Expand Down
15 changes: 9 additions & 6 deletions letterpress/tests/test_firstrun.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
)
15 changes: 9 additions & 6 deletions letterpress/tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 []")
Expand All @@ -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 []')
Expand Down Expand Up @@ -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')
1 change: 0 additions & 1 deletion letterpress/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

3 changes: 2 additions & 1 deletion letterpress/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<str:error>/<int:status>/', ElasticsearchErrorView.as_view(), name='elasticsearch_error'),
path('elasticsearch_error/<str:error>/<int:status>/',
ElasticsearchErrorView.as_view(), name='elasticsearch_error'),
path('letters/<letter_id>/sentiment/<sentiment_id>/',
LetterSentimentView.as_view(), name='letter_sentiment_view'),
path('letters/<pk>/', LetterDetailView.as_view(), name='letter_detail'),
Expand Down

0 comments on commit 3f5962b

Please sign in to comment.