test_activitypub.py 1.49 KB
Newer Older
1
2
3
4
5
from retribute_api.search import activitypub


def test_profile_serializer():
    payload = {
6
7
        "id": "https://test.domain",
        "url": "https://test.domain",
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
        "tag": [{"type": "Hashtag", "name": "#nobot"}],
        "attachment": [
            {
                "type": "PropertyValue",
                "name": "patreon",
                "value": '<a href="https://patreon.com/username" rel="me nofollow noopener">Test</a>',
            }
        ],
    }
    serializer = activitypub.ActorSerializer(data=payload)
    assert serializer.is_valid(raise_exception=True) is True

    assert serializer.validated_data == payload


def test_extract_urls_from_attachments():
    attachments = [
        {
            "type": "PropertyValue",
            "name": "Support me on Patreon",
            "value": '<a href="https://patreon.com/username" rel="me nofollow noopener" target="_blank">This is my Patreon</a>',
        },
        {
            "type": "PropertyValue",
            "name": "Support me on Ko-Fi",
            "value": '<a href="https://ko-fi.com/username" rel="me nofollow noopener" target="_blank">This is my Ko-Fi</a>',
        },
        {"type": "PropertyValue", "name": "Irrelevant text", "value": "No link"},
    ]

    expected = [
        {"summary": "Support me on Patreon", "url": "https://patreon.com/username"},
        {"summary": "Support me on Ko-Fi", "url": "https://ko-fi.com/username"},
    ]

    assert activitypub.extract_urls_from_attachments(attachments) == expected