Allow statusless posts (#677)

pull/680/head
Jamie Bliss 2023-12-07 18:32:18 -05:00 zatwierdzone przez GitHub
rodzic 123c20efb1
commit d07482f5a8
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 30 dodań i 4 usunięć

Wyświetl plik

@ -39,7 +39,7 @@ class PostPollSchema(Schema):
class PostStatusSchema(Schema):
status: str
status: str | None
in_reply_to_id: str | None = None
sensitive: bool = False
spoiler_text: str | None = None
@ -82,9 +82,9 @@ def post_for_id(request: HttpRequest, id: str) -> Post:
@api_view.post
def post_status(request, details: PostStatusSchema) -> schemas.Status:
# Check text length
if len(details.status) > Config.system.post_length:
if details.status and len(details.status) > Config.system.post_length:
raise ApiError(400, "Status is too long")
if len(details.status) == 0 and not details.media_ids:
if not details.status and not details.media_ids:
raise ApiError(400, "Status is empty")
# Grab attachments
attachments = [get_object_or_404(PostAttachment, pk=id) for id in details.media_ids]
@ -103,7 +103,7 @@ def post_status(request, details: PostStatusSchema) -> schemas.Status:
pass
post = Post.create_local(
author=request.identity,
content=details.status,
content=details.status or "",
summary=details.spoiler_text,
sensitive=details.sensitive,
visibility=visibility_map[details.visibility],

Wyświetl plik

@ -56,6 +56,32 @@ def test_post_status(api_client, identity):
assert response.status_code == 404
@pytest.mark.django_db
def test_post_statusless(api_client, identity):
"""
Tests we can post with media but no status
"""
# Create media attachment
attachment = PostAttachment.objects.create(
mimetype="image/webp",
name=None,
state=PostAttachmentStates.fetched,
author=identity,
)
# Post new one
response = api_client.post(
"/api/v1/statuses",
content_type="application/json",
data={
"media_ids": [attachment.id],
},
)
assert 200 <= response.status_code < 300
body = response.json()
assert body["content"] == "<p></p>"
assert body["media_attachments"][0]["description"] is None
@pytest.mark.django_db
def test_mention_format(api_client, identity, remote_identity):
"""