Skip to content

Commit

Permalink
update logic, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelOtter committed Oct 26, 2023
1 parent 7c546b7 commit 59ca589
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions granary/bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ def web_url_to_at_uri(url, handle=None, did=None):
type = match.group('type')
tid = match.group('tid')

# If a did has been provided explicitly, replace the existing handle with it.
if did and HANDLE_PATTERN.match(id):
# If a did and handle have been provided explicitly,
# replace the existing handle with the did.
if did and handle and id == handle:
id = did

if type:
Expand Down
15 changes: 15 additions & 0 deletions granary/tests/test_bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,24 @@ def test_web_url_to_at_uri(self):

self.assertEqual(
'at://did:plc:foo',
web_url_to_at_uri('https://bsky.app/profile/foo.com', handle='foo.com', did='did:plc:foo')
)

self.assertEqual(
'at://foo.com',
web_url_to_at_uri('https://bsky.app/profile/foo.com', did='did:plc:foo')
)

self.assertEqual(
'at://foo.com',
web_url_to_at_uri('https://bsky.app/profile/foo.com', handle='foo.com')
)

self.assertEqual(
'at://foo.com',
web_url_to_at_uri('https://bsky.app/profile/foo.com', handle='alice.com', did='did:plc:foo')
)

for url in ('at://foo', 'http://not/bsky.app', 'https://bsky.app/x'):
with self.assertRaises(ValueError):
web_url_to_at_uri(url)
Expand Down

0 comments on commit 59ca589

Please sign in to comment.