mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-16 06:24:12 +02:00
Linting
This commit is contained in:
parent
1d44a4027e
commit
244753210b
5 changed files with 13 additions and 40 deletions
|
@ -269,26 +269,6 @@ class CreateOrUpdateOrganizationTypeHelper:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def to_database(form, obj):
|
|
||||||
"""
|
|
||||||
Adds the form's cleaned data to `obj` and saves `obj`.
|
|
||||||
|
|
||||||
Does nothing if form is not valid.
|
|
||||||
"""
|
|
||||||
if not form.is_valid():
|
|
||||||
return None
|
|
||||||
for name, value in form.cleaned_data.items():
|
|
||||||
setattr(obj, name, value)
|
|
||||||
obj.save()
|
|
||||||
|
|
||||||
|
|
||||||
def from_database(form_class, obj):
|
|
||||||
"""Returns a dict of form field values gotten from `obj`."""
|
|
||||||
if obj is None:
|
|
||||||
return {}
|
|
||||||
return {name: getattr(obj, name) for name in form_class.declared_fields.keys()} # type: ignore
|
|
||||||
|
|
||||||
|
|
||||||
def replace_url_queryparams(url_to_modify: str, query_params: dict[Any, list]):
|
def replace_url_queryparams(url_to_modify: str, query_params: dict[Any, list]):
|
||||||
"""
|
"""
|
||||||
Replaces the query parameters of a given URL.
|
Replaces the query parameters of a given URL.
|
||||||
|
@ -310,4 +290,4 @@ def replace_url_queryparams(url_to_modify: str, query_params: dict[Any, list]):
|
||||||
# Reassemble the URL
|
# Reassemble the URL
|
||||||
new_url = urlunparse(url_parts)
|
new_url = urlunparse(url_parts)
|
||||||
|
|
||||||
return new_url
|
return new_url
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Contains middleware used in settings.py
|
Contains middleware used in settings.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode
|
from urllib.parse import parse_qs
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from waffle.decorators import flag_is_active
|
from waffle.decorators import flag_is_active
|
||||||
|
@ -41,7 +41,7 @@ class CheckUserProfileMiddleware:
|
||||||
request.user.contact.first_name,
|
request.user.contact.first_name,
|
||||||
request.user.contact.last_name,
|
request.user.contact.last_name,
|
||||||
request.user.contact.title,
|
request.user.contact.title,
|
||||||
request.user.contact.phone
|
request.user.contact.phone,
|
||||||
]
|
]
|
||||||
if None in user_values:
|
if None in user_values:
|
||||||
finished_setup = False
|
finished_setup = False
|
||||||
|
@ -51,7 +51,7 @@ class CheckUserProfileMiddleware:
|
||||||
|
|
||||||
# Continue processing the view
|
# Continue processing the view
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _handle_setup_not_finished(self, request):
|
def _handle_setup_not_finished(self, request):
|
||||||
setup_page = reverse("finish-user-profile-setup", kwargs={"pk": request.user.contact.pk})
|
setup_page = reverse("finish-user-profile-setup", kwargs={"pk": request.user.contact.pk})
|
||||||
logout_page = reverse("logout")
|
logout_page = reverse("logout")
|
||||||
|
|
|
@ -522,6 +522,7 @@ class HomeTests(TestWithUser):
|
||||||
|
|
||||||
class FinishUserProfileTests(TestWithUser, WebTest):
|
class FinishUserProfileTests(TestWithUser, WebTest):
|
||||||
"""A series of tests that target the finish setup page for user profile"""
|
"""A series of tests that target the finish setup page for user profile"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.user.title = None
|
self.user.title = None
|
||||||
|
@ -541,11 +542,11 @@ class FinishUserProfileTests(TestWithUser, WebTest):
|
||||||
Domain.objects.all().delete()
|
Domain.objects.all().delete()
|
||||||
Website.objects.all().delete()
|
Website.objects.all().delete()
|
||||||
Contact.objects.all().delete()
|
Contact.objects.all().delete()
|
||||||
|
|
||||||
def _set_session_cookie(self):
|
def _set_session_cookie(self):
|
||||||
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
def _submit_form_webtest(self, form, follow=False):
|
def _submit_form_webtest(self, form, follow=False):
|
||||||
page = form.submit()
|
page = form.submit()
|
||||||
self._set_session_cookie()
|
self._set_session_cookie()
|
||||||
|
@ -583,7 +584,7 @@ class FinishUserProfileTests(TestWithUser, WebTest):
|
||||||
self.assertEqual(completed_setup_page.status_code, 200)
|
self.assertEqual(completed_setup_page.status_code, 200)
|
||||||
# Assert that we're on the home page
|
# Assert that we're on the home page
|
||||||
self.assertContains(completed_setup_page, "Manage your domain")
|
self.assertContains(completed_setup_page, "Manage your domain")
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_new_user_goes_to_domain_request_with_profile_feature_on(self):
|
def test_new_user_goes_to_domain_request_with_profile_feature_on(self):
|
||||||
"""Tests that a new user is redirected to the domain request page when profile_feature is on"""
|
"""Tests that a new user is redirected to the domain request page when profile_feature is on"""
|
||||||
|
@ -619,17 +620,16 @@ class FinishUserProfileTests(TestWithUser, WebTest):
|
||||||
self.assertContains(completed_setup_page, "How we’ll reach you")
|
self.assertContains(completed_setup_page, "How we’ll reach you")
|
||||||
self.assertContains(completed_setup_page, "Your contact information")
|
self.assertContains(completed_setup_page, "Your contact information")
|
||||||
|
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_new_user_with_profile_feature_off(self):
|
def test_new_user_with_profile_feature_off(self):
|
||||||
"""Tests that a new user is not redirected to the profile setup page when profile_feature is off"""
|
"""Tests that a new user is not redirected to the profile setup page when profile_feature is off"""
|
||||||
with override_flag("profile_feature", active=False):
|
with override_flag("profile_feature", active=False):
|
||||||
response = self.client.get("/")
|
response = self.client.get("/")
|
||||||
self.assertNotContains(response, "Finish setting up your profile")
|
self.assertNotContains(response, "Finish setting up your profile")
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_new_user_goes_to_domain_request_with_profile_feature_off(self):
|
def test_new_user_goes_to_domain_request_with_profile_feature_off(self):
|
||||||
"""Tests that a new user is redirected to the domain request page
|
"""Tests that a new user is redirected to the domain request page
|
||||||
when profile_feature is off but not the setup page"""
|
when profile_feature is off but not the setup page"""
|
||||||
with override_flag("profile_feature", active=False):
|
with override_flag("profile_feature", active=False):
|
||||||
response = self.client.get("/request/")
|
response = self.client.get("/request/")
|
||||||
|
|
|
@ -89,7 +89,6 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class FinishProfileSetupView(UserProfileView):
|
class FinishProfileSetupView(UserProfileView):
|
||||||
"""This view forces the user into providing additional details that
|
"""This view forces the user into providing additional details that
|
||||||
we may have missed from Login.gov"""
|
we may have missed from Login.gov"""
|
||||||
|
@ -123,7 +122,7 @@ class FinishProfileSetupView(UserProfileView):
|
||||||
|
|
||||||
if self.redirect_type == self.RedirectType.COMPLETE_SETUP:
|
if self.redirect_type == self.RedirectType.COMPLETE_SETUP:
|
||||||
context["confirm_changes"] = True
|
context["confirm_changes"] = True
|
||||||
|
|
||||||
if "redirect_viewname" in self.session:
|
if "redirect_viewname" in self.session:
|
||||||
context["going_to_specific_page"] = True
|
context["going_to_specific_page"] = True
|
||||||
context["redirect_button_text"] = "Continue to your request"
|
context["redirect_button_text"] = "Continue to your request"
|
||||||
|
@ -138,7 +137,6 @@ class FinishProfileSetupView(UserProfileView):
|
||||||
"If the wrong email is displayed below, you’ll need to update your Login.gov account "
|
"If the wrong email is displayed below, you’ll need to update your Login.gov account "
|
||||||
f'and log back in. <a class="usa-link" href={help_url}>Get help with your Login.gov account.</a>'
|
f'and log back in. <a class="usa-link" href={help_url}>Get help with your Login.gov account.</a>'
|
||||||
) # nosec
|
) # nosec
|
||||||
|
|
||||||
|
|
||||||
def get_success_message(self, cleaned_data):
|
def get_success_message(self, cleaned_data):
|
||||||
"""Content of the returned success message"""
|
"""Content of the returned success message"""
|
||||||
|
@ -185,7 +183,7 @@ class FinishProfileSetupView(UserProfileView):
|
||||||
if self.redirect_type in completed_states:
|
if self.redirect_type in completed_states:
|
||||||
self.request.user.finished_setup = True
|
self.request.user.finished_setup = True
|
||||||
self.request.user.save()
|
self.request.user.save()
|
||||||
|
|
||||||
if "contact_setup_save_button" in request.POST:
|
if "contact_setup_save_button" in request.POST:
|
||||||
# Logic for when the 'Save' button is clicked
|
# Logic for when the 'Save' button is clicked
|
||||||
self.redirect_type = self.RedirectType.COMPLETE_SETUP
|
self.redirect_type = self.RedirectType.COMPLETE_SETUP
|
||||||
|
@ -227,10 +225,7 @@ class FinishProfileSetupView(UserProfileView):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# These redirect types redirect to the same page
|
# These redirect types redirect to the same page
|
||||||
self_redirect = [
|
self_redirect = [self.RedirectType.BACK_TO_SELF, self.RedirectType.COMPLETE_SETUP]
|
||||||
self.RedirectType.BACK_TO_SELF,
|
|
||||||
self.RedirectType.COMPLETE_SETUP
|
|
||||||
]
|
|
||||||
|
|
||||||
# Maps the redirect type to a URL
|
# Maps the redirect type to a URL
|
||||||
base_url = ""
|
base_url = ""
|
||||||
|
@ -256,4 +251,3 @@ class FinishProfileSetupView(UserProfileView):
|
||||||
# Generate the full url from the given query params
|
# Generate the full url from the given query params
|
||||||
full_url = replace_url_queryparams(base_url, query_params)
|
full_url = replace_url_queryparams(base_url, query_params)
|
||||||
return full_url
|
return full_url
|
||||||
|
|
||||||
|
|
|
@ -161,4 +161,3 @@ class UserProfilePermissionView(UserProfilePermission, DetailView, abc.ABC):
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def template_name(self):
|
def template_name(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue