Add unit test

This commit is contained in:
zandercymatics 2024-05-30 09:52:50 -06:00
parent a5a0c136df
commit e94412e7a5
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
4 changed files with 35 additions and 20 deletions

View file

@ -2,7 +2,6 @@
import time import time
import logging import logging
from typing import Any
from urllib.parse import urlparse, urlunparse, urlencode from urllib.parse import urlparse, urlunparse, urlencode
@ -270,19 +269,24 @@ class CreateOrUpdateOrganizationTypeHelper:
return True return True
def replace_url_queryparams(url_to_modify: str, query_params: dict[Any, list]): def replace_url_queryparams(url_to_modify: str, query_params, convert_list_to_csv=False):
""" """
Replaces the query parameters of a given URL. Replaces the query parameters of a given URL.
Because this replaces them, this can be used to either add, delete, or modify. Because this replaces them, this can be used to either add, delete, or modify.
Args: Args:
url_to_modify (str): The URL whose query parameters need to be modified. url_to_modify (str): The URL whose query parameters need to be modified.
query_params (dict): Dictionary of query parameters to use. query_params (dict): Dictionary of query parameters to use.
convert_list_to_csv (bool): If the queryparam contains a list of items,
convert it to a csv representation instead.
Returns: Returns:
str: The modified URL with the updated query parameters. str: The modified URL with the updated query parameters.
""" """
# Ensure each key in query_params maps to a single value, not a list # Ensure each key in query_params maps to a single value, not a list
query_params = {k: v[0] if isinstance(v, list) else v for k, v in query_params.items()} if convert_list_to_csv:
for key, value in query_params.items():
if isinstance(value, list):
query_params[key] = ",".join(value)
# Split the URL into parts # Split the URL into parts
url_parts = list(urlparse(url_to_modify)) url_parts = list(urlparse(url_to_modify))

View file

@ -10,6 +10,18 @@ Edit your User Profile |
{% block content %} {% block content %}
<main id="main-content" class="grid-container"> <main id="main-content" class="grid-container">
<div class="grid-col desktop:grid-offset-2 desktop:grid-col-8"> <div class="grid-col desktop:grid-offset-2 desktop:grid-col-8">
{# messages block #}
{% if messages %}
{% for message in messages %}
<div class="usa-alert usa-alert--{{ message.tags }} usa-alert--slim margin-bottom-3">
<div class="usa-alert__body">
{{ message }}
</div>
</div>
{% endfor %}
{% endif %}
{% include "includes/form_errors.html" with form=form %}
<a href="{% if not return_to_request %}{% url 'home' %}{% else %}{% url 'domain-request:' %}{% endif %}" class="breadcrumb__back"> <a href="{% if not return_to_request %}{% url 'home' %}{% else %}{% url 'domain-request:' %}{% endif %}" class="breadcrumb__back">
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img"> <svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
<use xlink:href="{% static 'img/sprite.svg' %}#arrow_back"></use> <use xlink:href="{% static 'img/sprite.svg' %}#arrow_back"></use>
@ -24,17 +36,6 @@ Edit your User Profile |
</p> </p>
{% endif %} {% endif %}
</a> </a>
{# messages block is under the back breadcrumb link #}
{% if messages %}
{% for message in messages %}
<div class="usa-alert usa-alert--{{ message.tags }} usa-alert--slim margin-bottom-3">
<div class="usa-alert__body">
{{ message }}
</div>
</div>
{% endfor %}
{% endif %}
{% include "includes/form_errors.html" with form=form %}
<h1>Your profile</h1> <h1>Your profile</h1>
<p>We <a href="{% public_site_url 'domains/requirements/#what-.gov-domain-registrants-must-do' %}" target="_blank">require</a> that you maintain accurate contact information. The details you provide will only be used to support the administration of .gov and wont be made public.</p> <p>We <a href="{% public_site_url 'domains/requirements/#what-.gov-domain-registrants-must-do' %}" target="_blank">require</a> that you maintain accurate contact information. The details you provide will only be used to support the administration of .gov and wont be made public.</p>

View file

@ -597,6 +597,16 @@ class UserProfileTests(TestWithUser, WebTest):
response = self.client.get("/user-profile") response = self.client.get("/user-profile")
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
@less_console_noise_decorator
def test_user_profile_back_button_when_coming_from_domain_request(self):
"""tests user profile when profile_feature is on,
and when they are redirected from the domain request page"""
with override_flag("profile_feature", active=True):
response = self.client.get("/user-profile?return_to_request=True")
self.assertContains(response, "Your profile")
self.assertContains(response, "Go back to your domain request")
self.assertNotContains(response, "Back to manage your domains")
@less_console_noise_decorator @less_console_noise_decorator
def test_domain_detail_profile_feature_on(self): def test_domain_detail_profile_feature_on(self):
"""test that domain detail view when profile_feature is on""" """test that domain detail view when profile_feature is on"""

View file

@ -71,7 +71,7 @@ class UserProfileView(UserProfilePermissionView, FormMixin):
# Preserve queryparams and add them back to the url # Preserve queryparams and add them back to the url
base_url = reverse("user-profile") base_url = reverse("user-profile")
new_redirect = replace_url_queryparams(base_url, query_params) if query_params else base_url new_redirect = replace_url_queryparams(base_url, query_params, convert_list_to_csv=True)
return new_redirect return new_redirect
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):