-
-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from django.urls import reverse | ||
|
||
from ...test import assert_contains, assert_has_success_message | ||
|
||
|
||
def test_account_preferences_returns_error_for_guests(user, client): | ||
response = client.get(reverse("misago:account-preferences")) | ||
assert_contains(response, "You need to be signed in", status_code=403) | ||
|
||
|
||
def test_account_preferences_renders_form(user_client): | ||
response = user_client.get(reverse("misago:account-preferences")) | ||
assert_contains(response, "Change preferences") | ||
|
||
|
||
def create_form_data(data: dict | None = None) -> dict: | ||
default_data = { | ||
"is_hiding_presence": "0", | ||
"limits_private_thread_invites_to": "0", | ||
"watch_started_threads": "0", | ||
"watch_replied_threads": "0", | ||
"watch_new_private_threads_by_followed": "0", | ||
"watch_new_private_threads_by_other_users": "0", | ||
"notify_new_private_threads_by_followed": "0", | ||
"notify_new_private_threads_by_other_users": "0", | ||
} | ||
|
||
if data: | ||
default_data.update(data) | ||
|
||
return default_data | ||
|
||
|
||
def test_account_preferences_form_updates_user_account(user, user_client): | ||
response = user_client.post( | ||
reverse("misago:account-preferences"), | ||
create_form_data( | ||
{ | ||
"is_hiding_presence": "1", | ||
"limits_private_thread_invites_to": "1", | ||
"watch_started_threads": "1", | ||
"watch_replied_threads": "2", | ||
"watch_new_private_threads_by_followed": "1", | ||
"watch_new_private_threads_by_other_users": "2", | ||
"notify_new_private_threads_by_followed": "1", | ||
"notify_new_private_threads_by_other_users": "2", | ||
} | ||
), | ||
) | ||
|
||
assert response.status_code == 302 | ||
assert_has_success_message(response, "Preferences updated") | ||
|
||
user.refresh_from_db() | ||
assert user.is_hiding_presence | ||
assert user.limits_private_thread_invites_to == 1 | ||
assert user.watch_started_threads == 1 | ||
assert user.watch_replied_threads == 2 | ||
assert user.watch_new_private_threads_by_followed == 1 | ||
assert user.watch_new_private_threads_by_other_users == 2 | ||
assert user.notify_new_private_threads_by_followed == 1 | ||
assert user.notify_new_private_threads_by_other_users == 2 | ||
|
||
|
||
def test_account_preferences_form_updates_user_account_in_htmx(user, user_client): | ||
response = user_client.post( | ||
reverse("misago:account-preferences"), | ||
create_form_data( | ||
{ | ||
"is_hiding_presence": "1", | ||
"limits_private_thread_invites_to": "1", | ||
"watch_started_threads": "1", | ||
"watch_replied_threads": "2", | ||
"watch_new_private_threads_by_followed": "1", | ||
"watch_new_private_threads_by_other_users": "2", | ||
"notify_new_private_threads_by_followed": "1", | ||
"notify_new_private_threads_by_other_users": "2", | ||
} | ||
), | ||
headers={"hx-request": "true"}, | ||
) | ||
|
||
assert_contains(response, "Preferences updated") | ||
|
||
user.refresh_from_db() | ||
assert user.is_hiding_presence | ||
assert user.limits_private_thread_invites_to == 1 | ||
assert user.watch_started_threads == 1 | ||
assert user.watch_replied_threads == 2 | ||
assert user.watch_new_private_threads_by_followed == 1 | ||
assert user.watch_new_private_threads_by_other_users == 2 | ||
assert user.notify_new_private_threads_by_followed == 1 | ||
assert user.notify_new_private_threads_by_other_users == 2 |