Exemplo n.º 1
0
def test_little_content_helper_tag(_):
    back = InMemBackend()
    ap.use_backend(back)

    content, tags = content_helper.parse_markdown("hello #activitypub")
    base_url = back.base_url()
    assert content == (
        f'<p>hello <a href="{base_url}/tags/activitypub" class="mention hashtag" rel="tag">#'
        f"<span>activitypub</span></a></p>")
    assert tags == [{
        "href": f"{base_url}/tags/activitypub",
        "name": "#activitypub",
        "type": "Hashtag",
    }]
Exemplo n.º 2
0
def test_httpsig():
    back = InMemBackend()
    ap.use_backend(back)

    k = Key("https://lol.com")
    k.new()
    back.FETCH_MOCK["https://lol.com#main-key"] = {
        "publicKey": k.to_dict(),
        "id": "https://lol.com",
    }

    httpretty.register_uri(httpretty.POST,
                           "https://remote-instance.com",
                           body="ok")

    auth = httpsig.HTTPSigAuth(k)
    resp = requests.post("https://remote-instance.com",
                         json={"ok": 1},
                         auth=auth)

    assert httpsig.verify_request(
        resp.request.method,
        resp.request.path_url,
        resp.request.headers,
        resp.request.body,
    )
Exemplo n.º 3
0
def test_little_content_helper_simple():
    back = InMemBackend()
    ap.use_backend(back)

    content, tags = content_helper.parse_markdown("hello")
    assert content == "<p>hello</p>"
    assert tags == []
Exemplo n.º 4
0
def test_little_content_helper_linkify():
    back = InMemBackend()
    ap.use_backend(back)

    content, tags = content_helper.parse_markdown("hello https://google.com")
    assert content.startswith("<p>hello <a")
    assert "https://google.com" in content
    assert tags == []
Exemplo n.º 5
0
def test_unexpected_activity_type():
    back = InMemBackend()
    ap.use_backend(back)

    back.FETCH_MOCK["https://lol.com"] = {"type": "Actor", "id": "https://lol.com"}

    with pytest.raises(UnexpectedActivityTypeError):
        parse_collection(url="https://lol.com", fetcher=back.fetch_iri)
Exemplo n.º 6
0
def test_recursive_collection_limit():
    back = InMemBackend()
    ap.use_backend(back)

    back.FETCH_MOCK["https://lol.com"] = {
        "type": "Collection",
        "first": "https://lol.com",
        "id": "https://lol.com",
    }

    with pytest.raises(RecursionLimitExceededError):
        parse_collection(url="https://lol.com", fetcher=back.fetch_iri)
Exemplo n.º 7
0
def test_empty_collection():
    back = InMemBackend()
    ap.use_backend(back)

    back.FETCH_MOCK["https://lol.com"] = {
        "type": "Collection",
        "items": [],
        "id": "https://lol.com",
    }

    out = parse_collection(url="https://lol.com", fetcher=back.fetch_iri)
    assert out == []
Exemplo n.º 8
0
def test_little_content_helper_mention(_):
    back = InMemBackend()
    ap.use_backend(back)
    back.FETCH_MOCK["https://microblog.pub"] = {
        "id": "https://microblog.pub",
        "url": "https://microblog.pub",
    }

    content, tags = content_helper.parse_markdown("hello @[email protected]")
    assert content == (
        '<p>hello <span class="h-card"><a href="https://microblog.pub" class="u-url mention">@<span>dev</span></a>'
        "</span></p>")
    assert tags == [{
        "href": "https://microblog.pub",
        "name": "@[email protected]",
        "type": "Mention",
    }]
Exemplo n.º 9
0
def test_collection():
    back = InMemBackend()
    ap.use_backend(back)

    back.FETCH_MOCK["https://lol.com"] = {
        "type": "Collection",
        "first": "https://lol.com/page1",
        "id": "https://lol.com",
    }
    back.FETCH_MOCK["https://lol.com/page1"] = {
        "type": "CollectionPage",
        "id": "https://lol.com/page1",
        "items": [1, 2, 3],
    }

    out = parse_collection(url="https://lol.com", fetcher=back.fetch_iri)
    assert out == [1, 2, 3]
Exemplo n.º 10
0
def test_ordered_collection():
    back = InMemBackend()
    ap.use_backend(back)

    back.FETCH_MOCK["https://lol.com"] = {
        "type": "OrderedCollection",
        "first": {
            "type": "OrderedCollectionPage",
            "id": "https://lol.com/page1",
            "orderedItems": [1, 2, 3],
            "next": "https://lol.com/page2",
        },
        "id": "https://lol.com",
    }
    back.FETCH_MOCK["https://lol.com/page2"] = {
        "type": "OrderedCollectionPage",
        "id": "https://lol.com/page2",
        "orderedItems": [4, 5, 6],
    }

    out = parse_collection(url="https://lol.com", fetcher=back.fetch_iri)
    assert out == [1, 2, 3, 4, 5, 6]