From 9d679815a6e2e7b34a228d140ffd6e3eccadad64 Mon Sep 17 00:00:00 2001 From: Marnanel Thurman Date: Sat, 10 Oct 2020 02:16:31 +0100 Subject: [PATCH] trilby_api.models.Status gains "is_local" for symmetry with Person. Tests updated. --- kepi/trilby_api/models/status.py | 4 ++++ kepi/trilby_api/tests/test_status.py | 31 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/kepi/trilby_api/models/status.py b/kepi/trilby_api/models/status.py index 5164e05..bcd7ba4 100644 --- a/kepi/trilby_api/models/status.py +++ b/kepi/trilby_api/models/status.py @@ -322,3 +322,7 @@ class Status(PolymorphicModel): # seem to be forthcoming on this point, so we'll # just have to wait until we find out. return self.content + + @property + def is_local(self): + return self.remote_url is None diff --git a/kepi/trilby_api/tests/test_status.py b/kepi/trilby_api/tests/test_status.py index 23716dc..4d86143 100644 --- a/kepi/trilby_api/tests/test_status.py +++ b/kepi/trilby_api/tests/test_status.py @@ -3,6 +3,7 @@ from rest_framework.test import APIClient, force_authenticate from kepi.trilby_api.views import * from kepi.trilby_api.tests import * from kepi.trilby_api.models import * +from kepi.bowler_pub.tests import create_remote_person from kepi.bowler_pub.utils import uri_to_url from django.conf import settings @@ -658,3 +659,33 @@ class TestGetStatus(TrilbyTestCase): details['detail'], 'Not found.', ) + + def test_is_local(self): + self._alice = create_local_person(name='alice') + + self._alice_status = create_local_status( + posted_by = self._alice, + content = 'Daisies are our silver.', + ) + + self.assertTrue( + self._alice_status.is_local, + ) + + self._bob = create_remote_person( + url = "https://example.org/people/bob", + name='bob', + auto_fetch = True, + ) + + self._bob_status = Status( + remote_url = "https://example.org/people/bob/status/100", + account = self._bob, + in_reply_to = self._alice_status, + content = "Buttercups our gold.", + ) + self._bob_status.save() + + self.assertFalse( + self._bob_status.is_local, + )