See #170: add a description field on tracks, albums, tracks
This commit is contained in:
parent
424b9f133a
commit
2bc71eecfd
38 changed files with 653 additions and 59 deletions
|
|
@ -71,3 +71,17 @@ def test_attachment_queryset_attached(args, expected, factories, queryset_equal_
|
|||
queryset = attachments[0].__class__.objects.attached(*args).order_by("id")
|
||||
expected_objs = [attachments[i] for i in expected]
|
||||
assert queryset == expected_objs
|
||||
|
||||
|
||||
def test_removing_obj_removes_content(factories):
|
||||
kept_content = factories["common.Content"]()
|
||||
removed_content = factories["common.Content"]()
|
||||
track1 = factories["music.Track"](description=removed_content)
|
||||
factories["music.Track"](description=kept_content)
|
||||
|
||||
track1.delete()
|
||||
|
||||
with pytest.raises(removed_content.DoesNotExist):
|
||||
removed_content.refresh_from_db()
|
||||
|
||||
kept_content.refresh_from_db()
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ from django.urls import reverse
|
|||
import django_filters
|
||||
|
||||
from funkwhale_api.common import serializers
|
||||
from funkwhale_api.common import utils
|
||||
from funkwhale_api.users import models
|
||||
from funkwhale_api.federation import utils as federation_utils
|
||||
|
||||
|
|
@ -252,3 +253,17 @@ def test_attachment_serializer_remote_file(factories, to_api_date):
|
|||
serializer = serializers.AttachmentSerializer(attachment)
|
||||
|
||||
assert serializer.data == expected
|
||||
|
||||
|
||||
def test_content_serializer(factories):
|
||||
content = factories["common.Content"]()
|
||||
|
||||
expected = {
|
||||
"text": content.text,
|
||||
"content_type": content.content_type,
|
||||
"html": utils.render_html(content.text, content.content_type),
|
||||
}
|
||||
|
||||
serializer = serializers.ContentSerializer(content)
|
||||
|
||||
assert serializer.data == expected
|
||||
|
|
|
|||
|
|
@ -99,3 +99,28 @@ def test_get_updated_fields(conf, mock_args, data, expected, mocker):
|
|||
)
|
||||
def test_join_url(start, end, expected):
|
||||
assert utils.join_url(start, end) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"text, content_type, expected",
|
||||
[
|
||||
("hello world", "text/markdown", "<p>hello world</p>"),
|
||||
("hello world", "text/plain", "<p>hello world</p>"),
|
||||
("<strong>hello world</strong>", "text/html", "<strong>hello world</strong>"),
|
||||
# images and other non whitelisted html should be removed
|
||||
("hello world\n", "text/markdown", "<p>hello world</p>"),
|
||||
(
|
||||
"hello world\n\n<script></script>\n\n<style></style>",
|
||||
"text/markdown",
|
||||
"<p>hello world</p>",
|
||||
),
|
||||
(
|
||||
"<p>hello world</p><script></script>\n\n<style></style>",
|
||||
"text/html",
|
||||
"<p>hello world</p>",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_render_html(text, content_type, expected):
|
||||
result = utils.render_html(text, content_type)
|
||||
assert result == expected
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue