Skip to content

Commit

Permalink
add test for fetch_shares
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelOtter committed Oct 21, 2023
1 parent 1158986 commit 84a7b5a
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions granary/tests/test_bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@

POST_FEED_VIEW_WITH_LIKES_BSKY = copy.deepcopy(POST_FEED_VIEW_BSKY)
POST_FEED_VIEW_WITH_LIKES_BSKY['post']['likeCount'] = 1
POST_FEED_VIEW_WITH_REPOSTS_BSKY = copy.deepcopy(POST_FEED_VIEW_BSKY)
POST_FEED_VIEW_WITH_REPOSTS_BSKY['post']['repostCount'] = 1

LIKE_BSKY = {
'indexedAt': NOW.isoformat(),
Expand All @@ -316,6 +318,21 @@
'url': 'https://bsky.app/profile/alice.com'
})

POST_AUTHOR_PROFILE_WITH_REPOSTS_AS = copy.deepcopy(POST_AUTHOR_PROFILE_AS)
POST_AUTHOR_PROFILE_WITH_REPOSTS_AS['object']['tags'] = [{
'author': copy.deepcopy(ACTOR_AS),
'id': 'tag:bsky.app:at://did/app.bsky.feed.post/tid_reposted_by_did:web:alice.com',
'objectType': 'activity',
'verb': 'share',
'url': 'https://bsky.app/profile/alice.com/post/tid',
'object': {'url': 'https://bsky.app/profile/alice.com/post/tid'}
}]
POST_AUTHOR_PROFILE_WITH_REPOSTS_AS['object']['tags'][0]['author'].update({
'id': 'tag:bsky.app:did:web:alice.com',
'username': 'alice.com',
'url': 'https://bsky.app/profile/alice.com'
})

class BlueskyTest(testutil.TestCase):

def setUp(self):
Expand Down Expand Up @@ -894,6 +911,43 @@ def test_get_activities_with_likes(self, mock_get):
},
)

@patch('requests.get')
def test_get_activities_with_reposts(self, mock_get):
mock_get.side_effect = [
requests_response({
'cursor': 'timestamp::cid',
'feed': [POST_FEED_VIEW_WITH_REPOSTS_BSKY],
}),
requests_response({
'cursor': 'timestamp::cid',
'uri': 'at://did/app.bsky.feed.post/tid',
'repostedBy': [ACTOR_PROFILE_VIEW_BSKY]
})
]

self.assert_equals(
[POST_AUTHOR_PROFILE_WITH_REPOSTS_AS],
self.bs.get_activities(fetch_shares=True)
)
mock_get.assert_any_call(
'https://bsky.social/xrpc/app.bsky.feed.getTimeline',
json=None,
headers={
'Authorization': 'Bearer towkin',
'Content-Type': 'application/json',
'User-Agent': util.user_agent,
},
)
mock_get.assert_any_call(
'https://bsky.social/xrpc/app.bsky.feed.getRepostedBy?uri=at%3A%2F%2Fdid%2Fapp.bsky.feed.post%2Ftid',
json=None,
headers={
'Authorization': 'Bearer towkin',
'Content-Type': 'application/json',
'User-Agent': util.user_agent,
},
)


@patch('requests.get')
def test_get_comment(self, mock_get):
Expand Down

0 comments on commit 84a7b5a

Please sign in to comment.