diff --git a/tests/test_activitypub.py b/tests/test_activitypub.py index 33a145f..0bf94c1 100644 --- a/tests/test_activitypub.py +++ b/tests/test_activitypub.py @@ -2158,8 +2158,10 @@ class ActivityPubUtilsTest(TestCase): def test_convert_actor_as2(self): self.assert_equals(ACTOR, ActivityPub.convert(Object(as2=ACTOR))) - @patch('requests.get', return_value=requests_response(test_web.ACTOR_HTML)) - def test_convert_actor_as1_from_user(self, _): + @patch('requests.get') + def test_convert_actor_as1_from_user(self, mock_get): + mock_get.return_value = requests_response(test_web.ACTOR_HTML) + obj = Object(our_as1={ 'objectType': 'person', 'id': 'https://user.com/', diff --git a/tests/test_web.py b/tests/test_web.py index 9ad15b5..b7cfb82 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -2664,6 +2664,12 @@ class WebUtilTest(TestCase): }, obj.mf2) self.assert_equals(ACTOR_AS1_UNWRAPPED_URLS, obj.as1) + def test_load_user_domain(self, mock_get, __): + loaded = Web.load('user.com') + self.assert_entities_equal(loaded, self.user.obj) + self.assertFalse(loaded.changed) + self.assertFalse(loaded.new) + def test_fetch_user_homepage_metaformats(self, mock_get, __): mock_get.return_value = requests_response( ACTOR_HTML_METAFORMATS, url='https://user.com/') diff --git a/web.py b/web.py index 2022f1a..2276cd4 100644 --- a/web.py +++ b/web.py @@ -401,6 +401,14 @@ class Web(User, Protocol): webmention.send(endpoint, source_url, url) return True + @classmethod + def load(cls, id, **kwargs): + """Wrap :meth:`Protocol.load` to convert domains to homepage URLs.""" + if re.match(DOMAIN_RE, id): + id = f'https://{id}/' + + return super().load(id, **kwargs) + @classmethod def fetch(cls, obj, gateway=False, check_backlink=False, **kwargs): """Fetches a URL over HTTP and extracts its microformats2.