Add test for ActivitypubProfile entity

merge-requests/143/head
Jason Robinson 2019-03-20 22:50:43 +02:00
rodzic 4b778112d8
commit 967f494dec
2 zmienionych plików z 63 dodań i 33 usunięć

Wyświetl plik

@ -4,7 +4,8 @@ from Crypto.PublicKey.RSA import RsaKey
from federation.entities.activitypub.constants import (
CONTEXTS_DEFAULT, CONTEXT_MANUALLY_APPROVES_FOLLOWERS, CONTEXT_LD_SIGNATURES, CONTEXT_HASHTAG, CONTEXT_SENSITIVE)
from federation.entities.activitypub.entities import ActivitypubProfile, ActivitypubAccept
from federation.entities.activitypub.entities import ActivitypubAccept
from federation.tests.fixtures.keys import PUBKEY
from federation.types import UserType
@ -28,20 +29,33 @@ class TestEntitiesConvertToAS2:
]
assert result.get('type') == 'Note'
def test_profile_to_as2(self):
# TODO expand
entity = ActivitypubProfile(
handle="bob@example.com", raw_content="foobar", name="Bob Bobertson", public=True,
tag_list=["socialfederation", "federation"], image_urls={
"large": "urllarge", "medium": "urlmedium", "small": "urlsmall"
}
)
result = entity.to_as2()
assert result.get('@context') == CONTEXTS_DEFAULT + [
CONTEXT_LD_SIGNATURES,
CONTEXT_MANUALLY_APPROVES_FOLLOWERS,
]
assert result.get('type') == 'Person'
def test_profile_to_as2(self, activitypubprofile):
result = activitypubprofile.to_as2()
assert result == {
"@context": CONTEXTS_DEFAULT + [
CONTEXT_LD_SIGNATURES,
CONTEXT_MANUALLY_APPROVES_FOLLOWERS,
],
"endpoints": {
"sharedInbox": "https://example.com/public",
},
"followers": "https://example.com/bob/followers/",
"following": "https://example.com/bob/following/",
"id": "https://example.com/bob",
"inbox": "https://example.com/bob/private",
"manuallyApprovesFollowers": False,
"name": "Bob Bobertson",
"outbox": "https://example.com/bob/outbox/",
"publicKey": {
"id": "https://example.com/bob#main-key",
"owner": "https://example.com/bob",
"publicKeyPem": PUBKEY,
},
"type": "Person",
"url": "https://example.com/bob-bobertson",
"summary": "foobar",
"icon": "urllarge",
}
class TestEntitiesPostReceive:
@ -61,7 +75,7 @@ class TestEntitiesPostReceive:
assert args[1].id == "https://example.com/profile"
assert isinstance(args[1].private_key, RsaKey)
assert kwargs['recipients'] == [{
"fid": "https://example.com/private",
"fid": "https://example.com/bob/private",
"protocol": "activitypub",
"public": False,
}]

Wyświetl plik

@ -2,13 +2,15 @@ import uuid
import pytest
from federation.entities.activitypub.entities import ActivitypubPost, ActivitypubAccept, ActivitypubFollow
from federation.entities.activitypub.entities import (
ActivitypubPost, ActivitypubAccept, ActivitypubFollow, ActivitypubProfile)
from federation.entities.base import Profile
from federation.entities.diaspora.entities import (
DiasporaPost, DiasporaComment, DiasporaLike, DiasporaProfile, DiasporaRetraction,
DiasporaContact, DiasporaReshare,
)
from federation.tests.factories.entities import ShareFactory
from federation.tests.fixtures.keys import PUBKEY
from federation.tests.fixtures.payloads import DIASPORA_PUBLIC_PAYLOAD
@ -30,6 +32,34 @@ def activitypubfollow():
)
@pytest.fixture
def activitypubpost():
post_uuid = uuid.uuid4()
profile_uuid = uuid.uuid4()
return ActivitypubPost(
raw_content="raw_content",
public=True,
provider_display_name="Socialhome",
id=f"http://127.0.0.1:8000/post/{post_uuid}/",
guid=post_uuid,
actor_id=f"http://127.0.0.1:8000/profile/{profile_uuid}/",
handle="alice@example.com",
)
@pytest.fixture
def activitypubprofile():
return ActivitypubProfile(
id="https://example.com/bob", raw_content="foobar", name="Bob Bobertson", public=True,
tag_list=["socialfederation", "federation"], image_urls={
"large": "urllarge", "medium": "urlmedium", "small": "urlsmall"
}, inboxes={
"private": "https://example.com/bob/private",
"public": "https://example.com/public",
}, public_key=PUBKEY, url="https://example.com/bob-bobertson"
)
@pytest.fixture
def profile():
return Profile(
@ -41,9 +71,9 @@ def profile():
handle="alice@example.com",
guid="guid",
inboxes={
"private": "https://example.com/private",
"private": "https://example.com/bob/private",
"public": "https://example.com/public",
}
}, public_key=PUBKEY,
)
@ -90,20 +120,6 @@ def diasporalike():
)
@pytest.fixture
def activitypubpost():
post_uuid = uuid.uuid4()
profile_uuid = uuid.uuid4()
return ActivitypubPost(
raw_content="raw_content",
public=True,
provider_display_name="Socialhome",
id=f"http://127.0.0.1:8000/post/{post_uuid}/",
guid=post_uuid,
actor_id=f"http://127.0.0.1:8000/profile/{profile_uuid}/",
handle="alice@example.com",
)
@pytest.fixture
def diasporapost():
return DiasporaPost(