Fixed failing test

merge-requests/154/head
Eliot Berriot 2018-04-02 19:15:27 +02:00
rodzic a252051351
commit 77c6bd5839
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DD6965E2476E5C27
5 zmienionych plików z 54 dodań i 30 usunięć

Wyświetl plik

@ -175,29 +175,14 @@ class TestActor(SystemActor):
reply_url = 'https://{}/activities/note/{}'.format(
settings.FEDERATION_HOSTNAME, now.timestamp()
)
mention = '@{}@{}'.format(
sender.preferred_username,
sender.domain
)
reply_content = '{} Pong!'.format(
mention
sender.mention_username
)
reply_activity = {
"@context": [
"https://www.w3.org/ns/activitystreams",
"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',
'actor': test_actor.url,
@ -221,7 +206,7 @@ class TestActor(SystemActor):
{
"type": "Mention",
"href": ac['actor'],
"name": mention
"name": sender.mention_username
}
]
)

Wyświetl plik

@ -53,13 +53,15 @@ class SignedRequestFactory(factory.Factory):
@registry.register
class ActorFactory(factory.DjangoModelFactory):
url = factory.Faker('url')
inbox_url = factory.Faker('url')
outbox_url = factory.Faker('url')
public_key = None
private_key = None
preferred_username = factory.Faker('user_name')
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:
model = models.Actor

Wyświetl plik

@ -42,3 +42,18 @@ class Actor(models.Model):
@property
def private_key_id(self):
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)

Wyświetl plik

@ -29,7 +29,7 @@ def clean_acct(acct_string):
except ValueError:
raise forms.ValidationError('Invalid format')
if hostname != settings.FEDERATION_HOSTNAME:
if hostname.lower() != settings.FEDERATION_HOSTNAME:
raise forms.ValidationError(
'Invalid hostname {}'.format(hostname))

Wyświetl plik

@ -126,7 +126,8 @@ def test_test_post_outbox_validates_actor(nodb_factories):
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(
'funkwhale_api.federation.activity.deliver')
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>'
}
}
test_actor = actors.SYSTEM_ACTORS['test'].get_actor_instance()
expected_note = factories['federation.Note'](
id='https://test.federation/activities/note/{}'.format(
now.timestamp()
@ -149,16 +151,36 @@ def test_test_post_outbox_handles_create_note(mocker, factories):
content='Pong!',
published=now.isoformat(),
inReplyTo=data['object']['id'],
)
test_actor = actors.SYSTEM_ACTORS['test'].get_actor_instance()
expected_activity = {
'actor': test_actor.url,
'id': 'https://test.federation/activities/note/{}/activity'.format(
now.timestamp()
cc=[],
summary=None,
sensitive=False,
attributedTo=test_actor.url,
attachment=[],
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',
'published': now.isoformat(),
'object': expected_note
'object': expected_note,
'cc': [],
}
actors.SYSTEM_ACTORS['test'].post_inbox(data, actor=actor)
deliver.assert_called_once_with(