Skip to content

Commit

Permalink
Test in edit formsets skipping deleted attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Jan 11, 2025
1 parent 7169c5f commit 0f97a23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions misago/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ def _attachment_factory(
uploader=None,
post=None,
thumbnail_path=None,
is_deleted=False,
):
filename = filename or str(os.path.split(file_path)[-1])
filetype = filetypes.match_filetype(filename)
Expand Down Expand Up @@ -583,6 +584,7 @@ def _attachment_factory(
image=image,
video=video,
file=file,
is_deleted=is_deleted,
)

return _attachment_factory
Expand Down
15 changes: 15 additions & 0 deletions misago/posting/tests/test_formsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ def test_get_edit_thread_formset_loads_post_attachments(
attachment_factory(text_file, uploader=other_user, post=other_thread.first_post)
attachment_factory(text_file, uploader=user)
attachment_factory(text_file, uploader=other_user)
attachment_factory(
text_file, uploader=user, post=thread.first_post, is_deleted=True
)

formset = get_edit_thread_formset(request, thread.first_post)
assert formset.title
Expand Down Expand Up @@ -459,6 +462,12 @@ def test_get_edit_private_thread_formset_loads_post_attachments(
)
attachment_factory(text_file, uploader=user)
attachment_factory(text_file, uploader=other_user)
attachment_factory(
text_file,
uploader=user,
post=other_user_private_thread.first_post,
is_deleted=True,
)

formset = get_edit_private_thread_formset(request, private_thread.first_post)
assert formset.title
Expand Down Expand Up @@ -572,6 +581,9 @@ def test_get_edit_thread_post_formset_loads_post_attachments(
attachment_factory(text_file, uploader=other_user, post=other_thread.first_post)
attachment_factory(text_file, uploader=user)
attachment_factory(text_file, uploader=other_user)
attachment_factory(
text_file, uploader=user, post=thread.first_post, is_deleted=True
)

formset = get_edit_thread_post_formset(request, thread.first_post)
assert not formset.title
Expand Down Expand Up @@ -676,6 +688,9 @@ def test_get_edit_private_thread_post_formset_loads_post_attachments(
)
attachment_factory(text_file, uploader=user)
attachment_factory(text_file, uploader=other_user)
attachment_factory(
text_file, uploader=user, post=private_thread.first_post, is_deleted=True
)

formset = get_edit_private_thread_post_formset(request, private_thread.first_post)
assert not formset.title
Expand Down

0 comments on commit 0f97a23

Please sign in to comment.