Fixed failing test
This commit is contained in:
parent
a252051351
commit
77c6bd5839
|
@ -175,29 +175,14 @@ class TestActor(SystemActor):
|
||||||
reply_url = 'https://{}/activities/note/{}'.format(
|
reply_url = 'https://{}/activities/note/{}'.format(
|
||||||
settings.FEDERATION_HOSTNAME, now.timestamp()
|
settings.FEDERATION_HOSTNAME, now.timestamp()
|
||||||
)
|
)
|
||||||
mention = '@{}@{}'.format(
|
|
||||||
sender.preferred_username,
|
|
||||||
sender.domain
|
|
||||||
)
|
|
||||||
reply_content = '{} Pong!'.format(
|
reply_content = '{} Pong!'.format(
|
||||||
mention
|
sender.mention_username
|
||||||
)
|
)
|
||||||
reply_activity = {
|
reply_activity = {
|
||||||
"@context": [
|
"@context": [
|
||||||
"https://www.w3.org/ns/activitystreams",
|
"https://www.w3.org/ns/activitystreams",
|
||||||
"https://w3id.org/security/v1",
|
"https://w3id.org/security/v1",
|
||||||
{
|
{}
|
||||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
|
||||||
"sensitive": "as:sensitive",
|
|
||||||
"movedTo": "as:movedTo",
|
|
||||||
"Hashtag": "as:Hashtag",
|
|
||||||
"ostatus": "http://ostatus.org#",
|
|
||||||
"atomUri": "ostatus:atomUri",
|
|
||||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
|
||||||
"conversation": "ostatus:conversation",
|
|
||||||
"toot": "http://joinmastodon.org/ns#",
|
|
||||||
"Emoji": "toot:Emoji"
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
'type': 'Create',
|
'type': 'Create',
|
||||||
'actor': test_actor.url,
|
'actor': test_actor.url,
|
||||||
|
@ -221,7 +206,7 @@ class TestActor(SystemActor):
|
||||||
{
|
{
|
||||||
"type": "Mention",
|
"type": "Mention",
|
||||||
"href": ac['actor'],
|
"href": ac['actor'],
|
||||||
"name": mention
|
"name": sender.mention_username
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -53,13 +53,15 @@ class SignedRequestFactory(factory.Factory):
|
||||||
|
|
||||||
@registry.register
|
@registry.register
|
||||||
class ActorFactory(factory.DjangoModelFactory):
|
class ActorFactory(factory.DjangoModelFactory):
|
||||||
url = factory.Faker('url')
|
|
||||||
inbox_url = factory.Faker('url')
|
|
||||||
outbox_url = factory.Faker('url')
|
|
||||||
public_key = None
|
public_key = None
|
||||||
private_key = None
|
private_key = None
|
||||||
preferred_username = factory.Faker('user_name')
|
preferred_username = factory.Faker('user_name')
|
||||||
summary = factory.Faker('paragraph')
|
summary = factory.Faker('paragraph')
|
||||||
|
domain = factory.Faker('domain_name')
|
||||||
|
url = factory.LazyAttribute(lambda o: 'https://{}/users/{}'.format(o.domain, o.preferred_username))
|
||||||
|
inbox_url = factory.LazyAttribute(lambda o: 'https://{}/users/{}/inbox'.format(o.domain, o.preferred_username))
|
||||||
|
outbox_url = factory.LazyAttribute(lambda o: 'https://{}/users/{}/outbox'.format(o.domain, o.preferred_username))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Actor
|
model = models.Actor
|
||||||
|
|
|
@ -42,3 +42,18 @@ class Actor(models.Model):
|
||||||
@property
|
@property
|
||||||
def private_key_id(self):
|
def private_key_id(self):
|
||||||
return '{}#main-key'.format(self.url)
|
return '{}#main-key'.format(self.url)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mention_username(self):
|
||||||
|
return '@{}@{}'.format(self.preferred_username, self.domain)
|
||||||
|
|
||||||
|
def save(self, **kwargs):
|
||||||
|
lowercase_fields = [
|
||||||
|
'domain',
|
||||||
|
]
|
||||||
|
for field in lowercase_fields:
|
||||||
|
v = getattr(self, field, None)
|
||||||
|
if v:
|
||||||
|
setattr(self, field, v.lower())
|
||||||
|
|
||||||
|
super().save(**kwargs)
|
||||||
|
|
|
@ -29,7 +29,7 @@ def clean_acct(acct_string):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise forms.ValidationError('Invalid format')
|
raise forms.ValidationError('Invalid format')
|
||||||
|
|
||||||
if hostname != settings.FEDERATION_HOSTNAME:
|
if hostname.lower() != settings.FEDERATION_HOSTNAME:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
'Invalid hostname {}'.format(hostname))
|
'Invalid hostname {}'.format(hostname))
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,8 @@ def test_test_post_outbox_validates_actor(nodb_factories):
|
||||||
assert msg in exc_info.value
|
assert msg in exc_info.value
|
||||||
|
|
||||||
|
|
||||||
def test_test_post_outbox_handles_create_note(mocker, factories):
|
def test_test_post_outbox_handles_create_note(
|
||||||
|
settings, mocker, factories):
|
||||||
deliver = mocker.patch(
|
deliver = mocker.patch(
|
||||||
'funkwhale_api.federation.activity.deliver')
|
'funkwhale_api.federation.activity.deliver')
|
||||||
actor = factories['federation.Actor']()
|
actor = factories['federation.Actor']()
|
||||||
|
@ -142,6 +143,7 @@ def test_test_post_outbox_handles_create_note(mocker, factories):
|
||||||
'content': '<p><a>@mention</a> /ping</p>'
|
'content': '<p><a>@mention</a> /ping</p>'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
test_actor = actors.SYSTEM_ACTORS['test'].get_actor_instance()
|
||||||
expected_note = factories['federation.Note'](
|
expected_note = factories['federation.Note'](
|
||||||
id='https://test.federation/activities/note/{}'.format(
|
id='https://test.federation/activities/note/{}'.format(
|
||||||
now.timestamp()
|
now.timestamp()
|
||||||
|
@ -149,16 +151,36 @@ def test_test_post_outbox_handles_create_note(mocker, factories):
|
||||||
content='Pong!',
|
content='Pong!',
|
||||||
published=now.isoformat(),
|
published=now.isoformat(),
|
||||||
inReplyTo=data['object']['id'],
|
inReplyTo=data['object']['id'],
|
||||||
)
|
cc=[],
|
||||||
test_actor = actors.SYSTEM_ACTORS['test'].get_actor_instance()
|
summary=None,
|
||||||
expected_activity = {
|
sensitive=False,
|
||||||
'actor': test_actor.url,
|
attributedTo=test_actor.url,
|
||||||
'id': 'https://test.federation/activities/note/{}/activity'.format(
|
attachment=[],
|
||||||
now.timestamp()
|
to=[actor.url],
|
||||||
|
url='https://{}/activities/note/{}'.format(
|
||||||
|
settings.FEDERATION_HOSTNAME, now.timestamp()
|
||||||
),
|
),
|
||||||
|
tag=[{
|
||||||
|
'href': actor.url,
|
||||||
|
'name': actor.mention_username,
|
||||||
|
'type': 'Mention',
|
||||||
|
}]
|
||||||
|
)
|
||||||
|
expected_activity = {
|
||||||
|
'@context': [
|
||||||
|
'https://www.w3.org/ns/activitystreams',
|
||||||
|
'https://w3id.org/security/v1',
|
||||||
|
{}
|
||||||
|
],
|
||||||
|
'actor': test_actor.url,
|
||||||
|
'id': 'https://{}/activities/note/{}/activity'.format(
|
||||||
|
settings.FEDERATION_HOSTNAME, now.timestamp()
|
||||||
|
),
|
||||||
|
'to': actor.url,
|
||||||
'type': 'Create',
|
'type': 'Create',
|
||||||
'published': now.isoformat(),
|
'published': now.isoformat(),
|
||||||
'object': expected_note
|
'object': expected_note,
|
||||||
|
'cc': [],
|
||||||
}
|
}
|
||||||
actors.SYSTEM_ACTORS['test'].post_inbox(data, actor=actor)
|
actors.SYSTEM_ACTORS['test'].post_inbox(data, actor=actor)
|
||||||
deliver.assert_called_once_with(
|
deliver.assert_called_once_with(
|
||||||
|
|
Loading…
Reference in New Issue