Skip to content

Commit

Permalink
Remove debug prints, add tests for htmx requests to threads list
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Jul 6, 2024
1 parent aa21e5c commit 163e477
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
1 change: 0 additions & 1 deletion misago/account/tests/test_account_email_confirm_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,4 @@ def test_account_email_confirm_change_returns_error_if_token_email_is_invalid(
kwargs={"user_id": user.id, "token": token},
)
)
print(response.content)
assert_contains(response, "This e-mail address is not available.")
13 changes: 13 additions & 0 deletions misago/threads/tests/test_threads_lists_polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,19 @@ def test_private_threads_list_poll_doesnt_return_button_if_request_is_not_htmx(
assert_not_contains(response, "new or updated thread")


def test_private_threads_list_poll_shows_error_to_users_without_permission(
user_client, private_threads_category, members_group
):
members_group.can_use_private_threads = False
members_group.save()

response = user_client.get(
private_threads_category.get_absolute_url() + "?poll_new=0",
headers={"hx-request": "true"},
)
assert_contains(response, "You can't use private threads.", status_code=403)


def test_private_threads_list_poll_doesnt_return_button_if_new_threads_are_not_visible(
user_client, private_threads_category, other_user
):
Expand Down
69 changes: 68 additions & 1 deletion misago/threads/tests/test_threads_lists_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def test_private_threads_list_shows_permission_error_to_users_without_permission
members_group.save()

response = user_client.get(reverse("misago:private-threads"))
print(response.content)
assert_contains(response, "You can't use private threads.", status_code=403)


Expand Down Expand Up @@ -221,3 +220,71 @@ def test_private_threads_list_displays_user_private_thread(

response = user_client.get(reverse("misago:private-threads"))
assert_contains(response, "Test Private Thread")


@override_dynamic_settings(index_view="categories")
def test_threads_list_displays_empty_in_htmx_request(db, user_client):
response = user_client.get(
reverse("misago:threads"),
headers={"hx-request": "true"},
)
assert_not_contains(response, "<h1>")


@override_dynamic_settings(index_view="categories")
def test_threads_list_displays_thread_in_htmx_request(default_category, user_client):
post_thread(default_category, title="Test Thread")
response = user_client.get(
reverse("misago:threads"),
headers={"hx-request": "true"},
)
assert_not_contains(response, "<h1>")
assert_contains(response, "Test Thread")


@override_dynamic_settings(index_view="categories")
def test_category_threads_list_displays_empty_in_htmx_request(
default_category, user_client
):
response = user_client.get(
default_category.get_absolute_url(),
headers={"hx-request": "true"},
)
assert_not_contains(response, "<h1>")


@override_dynamic_settings(index_view="categories")
def test_category_threads_list_displays_thread_in_htmx_request(
default_category, user_client
):
post_thread(default_category, title="Test Thread")
response = user_client.get(
default_category.get_absolute_url(),
headers={"hx-request": "true"},
)
assert_not_contains(response, "<h1>")
assert_contains(response, "Test Thread")


@override_dynamic_settings(index_view="categories")
def test_private__threads_list_displays_empty_in_htmx_request(db, user_client):
response = user_client.get(
reverse("misago:private-threads"),
headers={"hx-request": "true"},
)
assert_not_contains(response, "<h1>")


@override_dynamic_settings(index_view="categories")
def test_private_threads_list_displays_thread_in_htmx_request(
user, private_threads_category, user_client
):
thread = post_thread(private_threads_category, title="Test Thread")
ThreadParticipant.objects.create(thread=thread, user=user)

response = user_client.get(
reverse("misago:private-threads"),
headers={"hx-request": "true"},
)
assert_not_contains(response, "<h1>")
assert_contains(response, "Test Thread")

0 comments on commit 163e477

Please sign in to comment.