Skip to content

Commit

Permalink
Merge PR #206 from WayneLambert/develop
Browse files Browse the repository at this point in the history
Runs Ruff Formatting Over Project
  • Loading branch information
WayneLambert authored Dec 11, 2023
2 parents 8a6e9c5 + 444014c commit b84e588
Show file tree
Hide file tree
Showing 141 changed files with 2,728 additions and 2,198 deletions.
102 changes: 55 additions & 47 deletions aa_project/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,95 +6,103 @@


class TestLoginLogoutUTLs:
""" Asserts redirection URLS are set up as intended """
"""Asserts redirection URLS are set up as intended"""

def test_login_url(self):
assert base.LOGIN_URL == 'blog:users:login'
assert base.LOGIN_URL == "blog:users:login"

def test_login_redirect_url(self):
assert base.LOGIN_REDIRECT_URL == 'blog:home'
assert base.LOGIN_REDIRECT_URL == "blog:home"

def test_logout_redirect_url(self):
assert base.LOGOUT_REDIRECT_URL == 'blog:home'
assert base.LOGOUT_REDIRECT_URL == "blog:home"


class TestThirdPartyAppsAreInstalled:
""" Asserts that required third party apps are
correctly integrated within the project. """
"""Asserts that required third party apps are
correctly integrated within the project."""

def test_whitenoise_in_installed_apps(self):
assert 'whitenoise.runserver_nostatic' in base.INSTALLED_APPS
assert "whitenoise.runserver_nostatic" in base.INSTALLED_APPS

def test_rest_framework_in_installed_apps(self):
assert 'rest_framework' in base.INSTALLED_APPS
assert "rest_framework" in base.INSTALLED_APPS

def test_guardian_in_installed_apps(self):
assert 'guardian' in base.INSTALLED_APPS
assert "guardian" in base.INSTALLED_APPS

def test_crispy_forms_in_installed_apps(self):
assert 'crispy_forms' in base.INSTALLED_APPS
assert "crispy_forms" in base.INSTALLED_APPS

def test_crispy_bootstrap4_in_installed_apps(self):
assert 'crispy_bootstrap4' in base.INSTALLED_APPS
assert "crispy_bootstrap4" in base.INSTALLED_APPS

def test_storages_in_installed_apps(self):
assert 'storages' in base.INSTALLED_APPS
assert "storages" in base.INSTALLED_APPS

def test_django_recaptcha_in_installed_apps(self):
assert 'django_recaptcha' in base.INSTALLED_APPS
assert "django_recaptcha" in base.INSTALLED_APPS

def test_widget_tweaks_in_installed_apps(self):
assert 'widget_tweaks' in base.INSTALLED_APPS
assert "widget_tweaks" in base.INSTALLED_APPS

def test_tinymce_in_installed_apps(self):
assert 'tinymce' in base.INSTALLED_APPS
assert "tinymce" in base.INSTALLED_APPS


class TestMiddlewareIsConfigured:
def test_whitenoise_is_in_middleware_config(self):
assert 'whitenoise.middleware.WhiteNoiseMiddleware' in base.MIDDLEWARE
assert "whitenoise.middleware.WhiteNoiseMiddleware" in base.MIDDLEWARE


class TestTemplatesAreConfigured:
def test_template_backend_is_configured(self):
assert base.TEMPLATES[0]['BACKEND'] == 'django.template.backends.django.DjangoTemplates'
assert base.TEMPLATES[0]["BACKEND"] == "django.template.backends.django.DjangoTemplates"

def test_template_directories_are_present(self):
temp_dirs = base.TEMPLATES[0]['DIRS']
assert os.path.join(base.BASE_DIR, 'templates') in temp_dirs
assert os.path.join(base.BASE_DIR, 'aa_project/templates/') in temp_dirs
assert os.path.join(base.BASE_DIR, 'aa_project/templates/admin/') in temp_dirs
assert os.path.join(base.APPS_DIR, 'blog/templates/blog/') in temp_dirs
assert os.path.join(base.APPS_DIR, 'cv/templates/cv/') in temp_dirs
assert os.path.join(base.APPS_DIR, 'contacts/templates/contacts/') in temp_dirs
assert os.path.join(base.APPS_DIR, 'countdown_letters/templates/countdown_letters/') in temp_dirs
assert os.path.join(base.APPS_DIR, 'countdown_numbers/templates/countdown_numbers/') in temp_dirs
assert os.path.join(base.APPS_DIR, 'pages/templates/pages/') in temp_dirs
assert os.path.join(base.APPS_DIR, 'roulette/templates/roulette/') in temp_dirs
assert os.path.join(base.APPS_DIR, 'scraping/templates/scraping/') in temp_dirs
assert os.path.join(base.APPS_DIR, 'text_analysis/templates/text_analysis/') in temp_dirs
assert os.path.join(base.APPS_DIR, 'users/templates/users/') in temp_dirs
assert os.path.join(base.APPS_DIR, 'users/templates/registration/') in temp_dirs


@pytest.mark.skipif('GITHUB_RUN_ID' in os.environ, reason='Different DB credentials in GitHub Actions')
temp_dirs = base.TEMPLATES[0]["DIRS"]
assert os.path.join(base.BASE_DIR, "templates") in temp_dirs
assert os.path.join(base.BASE_DIR, "aa_project/templates/") in temp_dirs
assert os.path.join(base.BASE_DIR, "aa_project/templates/admin/") in temp_dirs
assert os.path.join(base.APPS_DIR, "blog/templates/blog/") in temp_dirs
assert os.path.join(base.APPS_DIR, "cv/templates/cv/") in temp_dirs
assert os.path.join(base.APPS_DIR, "contacts/templates/contacts/") in temp_dirs
assert (
os.path.join(base.APPS_DIR, "countdown_letters/templates/countdown_letters/")
in temp_dirs
)
assert (
os.path.join(base.APPS_DIR, "countdown_numbers/templates/countdown_numbers/")
in temp_dirs
)
assert os.path.join(base.APPS_DIR, "pages/templates/pages/") in temp_dirs
assert os.path.join(base.APPS_DIR, "roulette/templates/roulette/") in temp_dirs
assert os.path.join(base.APPS_DIR, "scraping/templates/scraping/") in temp_dirs
assert os.path.join(base.APPS_DIR, "text_analysis/templates/text_analysis/") in temp_dirs
assert os.path.join(base.APPS_DIR, "users/templates/users/") in temp_dirs
assert os.path.join(base.APPS_DIR, "users/templates/registration/") in temp_dirs


@pytest.mark.skipif(
"GITHUB_RUN_ID" in os.environ, reason="Different DB credentials in GitHub Actions"
)
class TestDatabaseIsSecurelyConfigured:
def test_secure_database_setup(self):
assert base.DATABASES['default']['NAME'] == os.environ['DB_NAME']
assert base.DATABASES['default']['USER'] == os.environ['DB_USER']
assert base.DATABASES['default']['PASSWORD'] == os.environ['DB_PASS']
assert base.DATABASES['default']['HOST'] == os.environ['DB_DOCKER_POSTGRES_SERVICE']
assert base.DATABASES['default']['PORT'] == os.environ['DB_PORT']
assert base.DATABASES["default"]["NAME"] == os.environ["DB_NAME"]
assert base.DATABASES["default"]["USER"] == os.environ["DB_USER"]
assert base.DATABASES["default"]["PASSWORD"] == os.environ["DB_PASS"]
assert base.DATABASES["default"]["HOST"] == os.environ["DB_DOCKER_POSTGRES_SERVICE"]
assert base.DATABASES["default"]["PORT"] == os.environ["DB_PORT"]


class TestEmailProviderConfigured:
def test_amazon_ses_setup(self):
assert base.EMAIL_BACKEND == 'django_ses.SESBackend'
assert base.EMAIL_BACKEND == "django_ses.SESBackend"
assert base.EMAIL_USE_TLS
assert base.EMAIL_HOST_SES == os.environ['EMAIL_HOST_SES']
assert base.EMAIL_HOST_USER_SES == os.environ['EMAIL_HOST_USER_SES']
assert base.EMAIL_HOST_PASSWORD_SES == os.environ['EMAIL_HOST_PASSWORD_SES']
assert base.AWS_ACCESS_KEY_ID == os.environ['AWS_ACCESS_KEY_ID']
assert base.AWS_SECRET_ACCESS_KEY == os.environ['AWS_SECRET_ACCESS_KEY']
assert base.EMAIL_HOST_SES == os.environ["EMAIL_HOST_SES"]
assert base.EMAIL_HOST_USER_SES == os.environ["EMAIL_HOST_USER_SES"]
assert base.EMAIL_HOST_PASSWORD_SES == os.environ["EMAIL_HOST_PASSWORD_SES"]
assert base.AWS_ACCESS_KEY_ID == os.environ["AWS_ACCESS_KEY_ID"]
assert base.AWS_SECRET_ACCESS_KEY == os.environ["AWS_SECRET_ACCESS_KEY"]
assert base.EMAIL_PORT == 587
assert base.DEFAULT_FROM_EMAIL_SES == os.environ['DEFAULT_FROM_EMAIL_SES']
assert base.DEFAULT_FROM_EMAIL_SES == os.environ["DEFAULT_FROM_EMAIL_SES"]
12 changes: 6 additions & 6 deletions aa_project/tests/test_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

class TestAllowedHostsConfigured:
def test_allowed_hosts_have_required_hosts(self):
assert 'wl-portfolio.herokuapp.com' in prod.ALLOWED_HOSTS
assert 'waynelambert.dev' in prod.ALLOWED_HOSTS
assert 'www.waynelambert.dev' in prod.ALLOWED_HOSTS
assert "wl-portfolio.herokuapp.com" in prod.ALLOWED_HOSTS
assert "waynelambert.dev" in prod.ALLOWED_HOSTS
assert "www.waynelambert.dev" in prod.ALLOWED_HOSTS


class TestPreDeploymentChecklistCompleted:
Expand All @@ -15,9 +15,9 @@ def test_checklist_completed(self):
assert prod.SECURE_SSL_REDIRECT
assert prod.SESSION_COOKIE_SECURE
assert prod.CSRF_COOKIE_SECURE
assert prod.X_FRAME_OPTIONS == 'DENY'
assert prod.X_FRAME_OPTIONS == "DENY"
assert prod.SECURE_HSTS_SECONDS == 2592000
assert prod.SECURE_HSTS_INCLUDE_SUBDOMAINS
assert prod.SECURE_HSTS_PRELOAD
assert prod.SECURE_PROXY_SSL_HEADER == ('HTTP_X_FORWARDED_PROTO', 'https')
assert prod.SECURE_REFERRER_POLICY == 'same-origin'
assert prod.SECURE_PROXY_SSL_HEADER == ("HTTP_X_FORWARDED_PROTO", "https")
assert prod.SECURE_REFERRER_POLICY == "same-origin"
59 changes: 32 additions & 27 deletions aa_project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,71 @@
handler400 = BadRequestView.as_view()
handler403 = PermissionDeniedView.as_view()
handler404 = PageNotFoundView.as_view()
handler500 = 'apps.pages.views.handler500'
handler500 = "apps.pages.views.handler500"


urlpatterns = [
path('tinymce/', include('tinymce.urls')),
path('', include(tf_urls)),
path('', include('pages.urls', namespace='pages')),
path('blog/', include('blog.urls', namespace='blog')),
path('contact/', include('contacts.urls', namespace='contacts')),
path('cv/', include('cv.urls', namespace='cv')),
path('countdown-letters/', include('countdown_letters.urls', namespace='countdown_letters')),
path('countdown-numbers/', include('countdown_numbers.urls', namespace='countdown_numbers')),
path('text-analysis/', include('text_analysis.urls', namespace='text_analysis')),
path('roulette/', include('roulette.urls', namespace='roulette')),
path('scraping/', include('scraping.urls', namespace='scraping')),
path('api/', include('api.urls', namespace='api')),
path("tinymce/", include("tinymce.urls")),
path("", include(tf_urls)),
path("", include("pages.urls", namespace="pages")),
path("blog/", include("blog.urls", namespace="blog")),
path("contact/", include("contacts.urls", namespace="contacts")),
path("cv/", include("cv.urls", namespace="cv")),
path("countdown-letters/", include("countdown_letters.urls", namespace="countdown_letters")),
path("countdown-numbers/", include("countdown_numbers.urls", namespace="countdown_numbers")),
path("text-analysis/", include("text_analysis.urls", namespace="text_analysis")),
path("roulette/", include("roulette.urls", namespace="roulette")),
path("scraping/", include("scraping.urls", namespace="scraping")),
path("api/", include("api.urls", namespace="api")),
]


# Admin Site URLs
urlpatterns += [
path(
f'{DJANGO_ADMIN_LOGIN_PATH}/password_reset/',
f"{DJANGO_ADMIN_LOGIN_PATH}/password_reset/",
auth_views.PasswordResetView.as_view(),
name='admin_password_reset'
name="admin_password_reset",
),
path(
f'{DJANGO_ADMIN_LOGIN_PATH}/password_reset/done/',
f"{DJANGO_ADMIN_LOGIN_PATH}/password_reset/done/",
auth_views.PasswordResetDoneView.as_view(),
name='password_reset_done'
name="password_reset_done",
),
path(
'reset/<uidb64>/<token>/',
"reset/<uidb64>/<token>/",
auth_views.PasswordResetConfirmView.as_view(),
name='password_reset_confirm'
name="password_reset_confirm",
),
path(
'reset/done/',
"reset/done/",
auth_views.PasswordResetCompleteView.as_view(),
name='password_reset_complete'
name="password_reset_complete",
),
path(f'{DJANGO_ADMIN_LOGIN_PATH}/', admin.site.urls),
path(f"{DJANGO_ADMIN_LOGIN_PATH}/", admin.site.urls),
]

# Sitemap Config
sitemaps = {
'categories': CategorySitemap,
'posts': PostSitemap,
"categories": CategorySitemap,
"posts": PostSitemap,
}

urlpatterns += [
path('sitemap.xml', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
path(
"sitemap.xml",
sitemap,
{"sitemaps": sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
]

# Django Debug Toolbar Config
if settings.DEBUG:
import debug_toolbar

urlpatterns += [
path('__debug__/', include(debug_toolbar.urls)),
path("__debug__/", include(debug_toolbar.urls)),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Expand Down
2 changes: 1 addition & 1 deletion aa_project/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from django.core.wsgi import get_wsgi_application


os.environ.setdefault('DJANGO_SETTINGS_MODULE', os.environ['DJANGO_SETTINGS_MODULE'])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", os.environ["DJANGO_SETTINGS_MODULE"])

application = get_wsgi_application()
2 changes: 1 addition & 1 deletion apps/api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class ApiConfig(AppConfig):
name = 'apps.api'
name = "apps.api"
Loading

0 comments on commit b84e588

Please sign in to comment.