mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-06 01:35:22 +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
|
||||
|
||||
|
||||
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]):
|
||||
"""
|
||||
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
|
||||
new_url = urlunparse(url_parts)
|
||||
|
||||
return new_url
|
||||
return new_url
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
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.http import HttpResponseRedirect
|
||||
from waffle.decorators import flag_is_active
|
||||
|
@ -41,7 +41,7 @@ class CheckUserProfileMiddleware:
|
|||
request.user.contact.first_name,
|
||||
request.user.contact.last_name,
|
||||
request.user.contact.title,
|
||||
request.user.contact.phone
|
||||
request.user.contact.phone,
|
||||
]
|
||||
if None in user_values:
|
||||
finished_setup = False
|
||||
|
@ -51,7 +51,7 @@ class CheckUserProfileMiddleware:
|
|||
|
||||
# Continue processing the view
|
||||
return None
|
||||
|
||||
|
||||
def _handle_setup_not_finished(self, request):
|
||||
setup_page = reverse("finish-user-profile-setup", kwargs={"pk": request.user.contact.pk})
|
||||
logout_page = reverse("logout")
|
||||
|
|
|
@ -522,6 +522,7 @@ class HomeTests(TestWithUser):
|
|||
|
||||
class FinishUserProfileTests(TestWithUser, WebTest):
|
||||
"""A series of tests that target the finish setup page for user profile"""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.user.title = None
|
||||
|
@ -541,11 +542,11 @@ class FinishUserProfileTests(TestWithUser, WebTest):
|
|||
Domain.objects.all().delete()
|
||||
Website.objects.all().delete()
|
||||
Contact.objects.all().delete()
|
||||
|
||||
|
||||
def _set_session_cookie(self):
|
||||
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
|
||||
|
||||
def _submit_form_webtest(self, form, follow=False):
|
||||
page = form.submit()
|
||||
self._set_session_cookie()
|
||||
|
@ -583,7 +584,7 @@ class FinishUserProfileTests(TestWithUser, WebTest):
|
|||
self.assertEqual(completed_setup_page.status_code, 200)
|
||||
# Assert that we're on the home page
|
||||
self.assertContains(completed_setup_page, "Manage your domain")
|
||||
|
||||
|
||||
@less_console_noise_decorator
|
||||
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"""
|
||||
|
@ -619,17 +620,16 @@ class FinishUserProfileTests(TestWithUser, WebTest):
|
|||
self.assertContains(completed_setup_page, "How we’ll reach you")
|
||||
self.assertContains(completed_setup_page, "Your contact information")
|
||||
|
||||
|
||||
@less_console_noise_decorator
|
||||
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"""
|
||||
with override_flag("profile_feature", active=False):
|
||||
response = self.client.get("/")
|
||||
self.assertNotContains(response, "Finish setting up your profile")
|
||||
|
||||
|
||||
@less_console_noise_decorator
|
||||
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"""
|
||||
with override_flag("profile_feature", active=False):
|
||||
response = self.client.get("/request/")
|
||||
|
|
|
@ -89,7 +89,6 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
|
|||
return None
|
||||
|
||||
|
||||
|
||||
class FinishProfileSetupView(UserProfileView):
|
||||
"""This view forces the user into providing additional details that
|
||||
we may have missed from Login.gov"""
|
||||
|
@ -123,7 +122,7 @@ class FinishProfileSetupView(UserProfileView):
|
|||
|
||||
if self.redirect_type == self.RedirectType.COMPLETE_SETUP:
|
||||
context["confirm_changes"] = True
|
||||
|
||||
|
||||
if "redirect_viewname" in self.session:
|
||||
context["going_to_specific_page"] = True
|
||||
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 "
|
||||
f'and log back in. <a class="usa-link" href={help_url}>Get help with your Login.gov account.</a>'
|
||||
) # nosec
|
||||
|
||||
|
||||
def get_success_message(self, cleaned_data):
|
||||
"""Content of the returned success message"""
|
||||
|
@ -185,7 +183,7 @@ class FinishProfileSetupView(UserProfileView):
|
|||
if self.redirect_type in completed_states:
|
||||
self.request.user.finished_setup = True
|
||||
self.request.user.save()
|
||||
|
||||
|
||||
if "contact_setup_save_button" in request.POST:
|
||||
# Logic for when the 'Save' button is clicked
|
||||
self.redirect_type = self.RedirectType.COMPLETE_SETUP
|
||||
|
@ -227,10 +225,7 @@ class FinishProfileSetupView(UserProfileView):
|
|||
"""
|
||||
|
||||
# These redirect types redirect to the same page
|
||||
self_redirect = [
|
||||
self.RedirectType.BACK_TO_SELF,
|
||||
self.RedirectType.COMPLETE_SETUP
|
||||
]
|
||||
self_redirect = [self.RedirectType.BACK_TO_SELF, self.RedirectType.COMPLETE_SETUP]
|
||||
|
||||
# Maps the redirect type to a URL
|
||||
base_url = ""
|
||||
|
@ -256,4 +251,3 @@ class FinishProfileSetupView(UserProfileView):
|
|||
# Generate the full url from the given query params
|
||||
full_url = replace_url_queryparams(base_url, query_params)
|
||||
return full_url
|
||||
|
||||
|
|
|
@ -161,4 +161,3 @@ class UserProfilePermissionView(UserProfilePermission, DetailView, abc.ABC):
|
|||
@abc.abstractmethod
|
||||
def template_name(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue