Ejemplo 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",
    }]
Ejemplo 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,
    )
Ejemplo 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 == []
Ejemplo 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 == []
Ejemplo 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)
Ejemplo 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)
Ejemplo 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 == []
Ejemplo 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",
    }]
Ejemplo 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]
Ejemplo 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]