Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhea0 committed Nov 30, 2023
1 parent 2001c53 commit 8f66f9a
Show file tree
Hide file tree
Showing 23 changed files with 358 additions and 171 deletions.
2 changes: 1 addition & 1 deletion core/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

application = get_asgi_application()
91 changes: 50 additions & 41 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,28 @@
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

SECRET_KEY = os.environ.get("SECRET_KEY", default="hussx3!p=8@%iej1k_7vxd*!6acbv7ln93_+_2ia8kb-becqc1")
SECRET_KEY = os.environ.get(
"SECRET_KEY", default="hussx3!p=8@%iej1k_7vxd*!6acbv7ln93_+_2ia8kb-becqc1"
)
DEBUG = int(os.environ.get("DEBUG", default=0))
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", default="127.0.0.1 localhost [::1]").split(" ")

CSRF_TRUSTED_ORIGINS = os.environ.get("CSRF_TRUSTED_ORIGINS", default="http://127.0.0.1:8000 http://localhost:8000").split(" ")

SESSION_COOKIE_SECURE = True # ensures cookie is only sent under an HTTPS connection
CSRF_COOKIE_SECURE = True # ensures CSRF cookie is only sent under an HTTPS connection
SECURE_HSTS_SECONDS = 604800 # determines how long browsers should remember that your site should only be accessed using HTTPS
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") # signifies a request is secure despite using proxy
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https" # django-allauth's default protocol for generating URLs
ALLOWED_HOSTS = os.environ.get(
"DJANGO_ALLOWED_HOSTS", default="127.0.0.1 localhost [::1]"
).split(" ")

CSRF_TRUSTED_ORIGINS = os.environ.get(
"CSRF_TRUSTED_ORIGINS", default="http://127.0.0.1:8000 http://localhost:8000"
).split(" ")

SESSION_COOKIE_SECURE = True # ensures cookie is only sent under an HTTPS connection
CSRF_COOKIE_SECURE = True # ensures CSRF cookie is only sent under an HTTPS connection
SECURE_HSTS_SECONDS = 604800 # determines how long browsers should remember that your site should only be accessed using HTTPS
SECURE_PROXY_SSL_HEADER = (
"HTTP_X_FORWARDED_PROTO",
"https",
) # signifies a request is secure despite using proxy
ACCOUNT_DEFAULT_HTTP_PROTOCOL = (
"https" # django-allauth's default protocol for generating URLs
)

# Application definition

Expand Down Expand Up @@ -70,34 +81,34 @@
"allauth.account.middleware.AccountMiddleware",
]

ROOT_URLCONF = 'core.urls'
ROOT_URLCONF = "core.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = 'core.wsgi.application'
WSGI_APPLICATION = "core.wsgi.application"


# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}

Expand All @@ -109,26 +120,26 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

Expand All @@ -138,7 +149,7 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = 'static/'
STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "staticfiles"

STORAGES = {
Expand All @@ -150,7 +161,7 @@
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

AUTH_USER_MODEL = "party.CustomUser"

Expand All @@ -162,16 +173,14 @@

CRISPY_TEMPLATE_PACK = "bootstrap4"

LOGIN_REDIRECT_URL = "page_party_list" # where to redirect after login
LOGIN_URL = 'party_login' # where to redirect when login is required to access a view
LOGIN_REDIRECT_URL = "page_party_list" # where to redirect after login
LOGIN_URL = "party_login" # where to redirect when login is required to access a view


AUTHENTICATION_BACKENDS = (
"allauth.account.auth_backends.AuthenticationBackend",
)
AUTHENTICATION_BACKENDS = ("allauth.account.auth_backends.AuthenticationBackend",)

SITE_ID = 1 # needs to match the Site ID in the admin
ACCOUNT_EMAIL_VERIFICATION = "none" # no email verification needed
SOCIALACCOUNT_LOGIN_ON_GET = True # skip additional confirm page, less secure
ACCOUNT_LOGOUT_ON_GET = True # skip the confirm logout page
SITE_ID = 1 # needs to match the Site ID in the admin
ACCOUNT_EMAIL_VERIFICATION = "none" # no email verification needed
SOCIALACCOUNT_LOGIN_ON_GET = True # skip additional confirm page, less secure
ACCOUNT_LOGOUT_ON_GET = True # skip the confirm logout page
ACCOUNT_UNIQUE_EMAIL = True
2 changes: 1 addition & 1 deletion core/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

application = get_wsgi_application()
4 changes: 2 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -18,5 +18,5 @@ def main():
execute_from_command_line(sys.argv)


if __name__ == '__main__':
if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions party/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class PartyConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'party'
default_auto_field = "django.db.models.BigAutoField"
name = "party"
1 change: 0 additions & 1 deletion party/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def clean_party_date(self):


class GiftForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
Expand Down
1 change: 0 additions & 1 deletion party/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
1 change: 0 additions & 1 deletion party/migrations/0002_party_guest_gift.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

dependencies = [
("party", "0001_initial"),
]
Expand Down
6 changes: 5 additions & 1 deletion party/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class Party(models.Model):
party_time = models.TimeField()
invitation = models.TextField()
venue = models.CharField(max_length=200)
organizer = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="organized_parties")
organizer = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="organized_parties",
)

class Meta:
verbose_name_plural = "parties"
Expand Down
4 changes: 2 additions & 2 deletions party/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _create_gift(party, **kwargs):
gift=kwargs.get("gift", "Test gift"),
price=kwargs.get("price", 12.5),
link=kwargs.get("price", "https://testlink.com"),
party=party
party=party,
)

return _create_gift
Expand All @@ -54,7 +54,7 @@ def _create_guest(party, **kwargs):
return Guest.objects.create(
name=kwargs.get("name", "Anna Boleyn"),
attending=kwargs.get("attending", True),
party=party
party=party,
)

return _create_guest
24 changes: 18 additions & 6 deletions party/tests/test_gift_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def test_gift_detail_partial_returns_gift_detail_including_party(
assert response.context_data["party"] == party


def test_partial_gift_update_returns_gift_update_form(authenticated_client, create_user, create_party, create_gift):
def test_partial_gift_update_returns_gift_update_form(
authenticated_client, create_user, create_party, create_gift
):
party = create_party(create_user)
gift = create_gift(party=party)

Expand All @@ -50,7 +52,9 @@ def test_partial_gift_update_returns_gift_update_form(authenticated_client, crea
assert response.context["form"].instance == gift


def test_partial_gift_update_updates_gift_and_returns_its_details_including_party_id(authenticated_client, create_user, create_party, create_gift):
def test_partial_gift_update_updates_gift_and_returns_its_details_including_party_id(
authenticated_client, create_user, create_party, create_gift
):
party = create_party(create_user)
gift = create_gift(party=party)

Expand All @@ -63,7 +67,9 @@ def test_partial_gift_update_updates_gift_and_returns_its_details_including_part
)

url = reverse("partial_gift_update", args=[gift.uuid])
response = authenticated_client(create_user).put(url, content_type="application/json", data=data)
response = authenticated_client(create_user).put(
url, content_type="application/json", data=data
)

assert Gift.objects.get(uuid=gift.uuid).gift == "Updated gift"
assert Gift.objects.get(uuid=gift.uuid).price == 50.0
Expand All @@ -74,7 +80,9 @@ def test_partial_gift_update_updates_gift_and_returns_its_details_including_part
assert response.context["party"] == party


def test_partial_gift_delete_removes_gift(authenticated_client, create_user, create_party, create_gift):
def test_partial_gift_delete_removes_gift(
authenticated_client, create_user, create_party, create_gift
):
party = create_party(organizer=create_user)
gift = create_gift(party=party)

Expand All @@ -87,7 +95,9 @@ def test_partial_gift_delete_removes_gift(authenticated_client, create_user, cre
assert Gift.objects.count() == 0


def test_get_partial_new_gift_returns_create_gift_form_with_party(authenticated_client, create_user, create_party):
def test_get_partial_new_gift_returns_create_gift_form_with_party(
authenticated_client, create_user, create_party
):
party = create_party(organizer=create_user)

url = reverse("partial_new_gift", args=[party.uuid])
Expand All @@ -99,7 +109,9 @@ def test_get_partial_new_gift_returns_create_gift_form_with_party(authenticated_
assert response.context["party_id"] == party.uuid


def test_put_partial_new_gift_saves_gift(authenticated_client, create_user, create_party):
def test_put_partial_new_gift_saves_gift(
authenticated_client, create_user, create_party
):
party = create_party(organizer=create_user)

data = {
Expand Down
Loading

0 comments on commit 8f66f9a

Please sign in to comment.