def validate_help_text(self, v):
     if not v:
         return
     v["html"] = common_utils.render_html(v["text"],
                                          content_type=v["content_type"],
                                          permissive=True)
     return v
Example #2
0
def test_can_render_text_preview(api_client, db):
    payload = {"text": "Hello world"}
    url = reverse("api:v1:text-preview")
    response = api_client.post(url, payload)

    expected = {"rendered": utils.render_html(payload["text"], "text/markdown")}
    assert response.status_code == 200
    assert response.data == expected
def test_get_serialized_preference(value, preferences):
    pref_id = "moderation__signup_form_customization"

    preferences[pref_id] = value
    if "help_text" in value:
        value["help_text"]["html"] = common_utils.render_html(
            value["help_text"]["text"],
            content_type=value["help_text"]["content_type"],
            permissive=True,
        )
    assert preferences[pref_id] == value
Example #4
0
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
def test_update_via_api(superuser_api_client, preferences):
    pref_id = "moderation__signup_form_customization"
    url = reverse("api:v1:instance:admin-settings-bulk")
    new_value = {
        "help_text": {"text": "hello", "content_type": "text/markdown"},
        "fields": [{"required": True, "label": "hello", "input_type": "short_text"}],
    }
    response = superuser_api_client.post(url, {pref_id: new_value}, format="json")
    assert response.status_code == 200
    new_value["help_text"]["html"] = common_utils.render_html(
        new_value["help_text"]["text"],
        content_type=new_value["help_text"]["content_type"],
        permissive=True,
    )
    assert preferences[pref_id] == new_value
Example #6
0
def test_render_html(text, content_type, permissive, expected):
    result = utils.render_html(text, content_type, permissive=permissive)
    assert result == expected