diff --git a/ids.py b/ids.py index ca9ff82..5b1c924 100644 --- a/ids.py +++ b/ids.py @@ -52,10 +52,10 @@ def web_ap_base_domain(user_domain): if _NON_WEB_SUBDOMAIN_SITES is None: _NON_WEB_SUBDOMAIN_SITES = { user.key.id(): user.ap_subdomain - for key in Query('MagicKey', - filters=FilterNode('ap_subdomain', '!=', 'web'), - projection=['ap_subdomain'], - ).fetch() + for user in Query('MagicKey', + filters=FilterNode('ap_subdomain', '!=', 'web'), + projection=['ap_subdomain'], + ).fetch() } logger.info(f'Loaded {len(_NON_WEB_SUBDOMAIN_SITES)} non-web.brid.gy Web users') diff --git a/tests/test_ids.py b/tests/test_ids.py index 7d23890..f13a29a 100644 --- a/tests/test_ids.py +++ b/tests/test_ids.py @@ -88,11 +88,10 @@ class IdsTest(TestCase): self.assertEqual(expected, translate_user_id( id='https://www.user.com/', from_=Web, to=proto)) - @patch('ids._NON_WEB_SUBDOMAIN_SITES', new={ - 'on-bsky.com': 'bsky', - 'on-fed.com': 'fed', - }) def test_translate_user_id_web_ap_subdomain_fed(self): + self.make_user('on-fed.com', cls=Web, ap_subdomain='fed') + self.make_user('on-bsky.com', cls=Web, ap_subdomain='bsky') + for base_url in ['https://web.brid.gy/', 'https://fed.brid.gy/']: with app.test_request_context('/', base_url=base_url): self.assertEqual('https://web.brid.gy/on-web.com', translate_user_id( @@ -198,8 +197,9 @@ class IdsTest(TestCase): self.assertEqual(expected, translate_object_id( id=id, from_=from_, to=to)) - @patch('ids._NON_WEB_SUBDOMAIN_SITES', new={'on-fed.com': 'fed'}) def test_translate_object_id_web_ap_subdomain_fed(self): + self.make_user('on-fed.com', cls=Web, ap_subdomain='fed') + for base_url in ['https://web.brid.gy/', 'https://fed.brid.gy/']: with app.test_request_context('/', base_url=base_url): got = translate_object_id(id='http://on-fed.com/post', from_=Web, diff --git a/tests/testutil.py b/tests/testutil.py index 8f89ca9..3405a24 100644 --- a/tests/testutil.py +++ b/tests/testutil.py @@ -230,6 +230,7 @@ class TestCase(unittest.TestCase, testutil.Asserts): cls.fetched = [] cls.created_for = [] + ids._NON_WEB_SUBDOMAIN_SITES = None ids.COPIES_PROTOCOLS = ('atproto', 'fake', 'other') common.PROTOCOL_DOMAINS = ( 'ap.brid.gy',