From 02a14a32f47ca45379744854481da73e3f0ee0b1 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 17 Jun 2023 06:35:21 +0200 Subject: [PATCH] add tests for user display and slug customization --- umap/tests/test_views.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/umap/tests/test_views.py b/umap/tests/test_views.py index 2ceeee33..dc385917 100644 --- a/umap/tests/test_views.py +++ b/umap/tests/test_views.py @@ -207,3 +207,33 @@ def test_read_only_shows_create_buttons_if_disabled(client, settings): settings.UMAP_READONLY = False response = client.get(reverse("home")) assert "Create a map" in response.content.decode() + + +@pytest.mark.django_db +def test_change_user_display_name(client, user, settings): + username = "MyUserFooName" + first_name = "Ezekiel" + user.username = username + user.first_name = first_name + user.save() + client.login(username=username, password="123123") + response = client.get(reverse("home")) + assert username in response.content.decode() + assert first_name not in response.content.decode() + settings.USER_DISPLAY_NAME = "{first_name}" + response = client.get(reverse("home")) + assert first_name in response.content.decode() + # username will still be in the contant as it's in the "my maps" URL path. + + +@pytest.mark.django_db +def test_change_user_slug(client, user, settings): + username = "MyUserFooName" + user.username = username + user.save() + client.login(username=username, password="123123") + response = client.get(reverse("home")) + assert f"/en/user/{username}/" in response.content.decode() + settings.USER_URL_FIELD = "pk" + response = client.get(reverse("home")) + assert f"/en/user/{user.pk}/" in response.content.decode()