2022-12-24 16:34:24 +00:00
|
|
|
"""Unit tests for feed.py."""
|
2022-12-29 01:30:22 +00:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
2022-12-31 06:52:56 +00:00
|
|
|
from granary.tests.test_bluesky import (
|
|
|
|
ACTOR_AS,
|
|
|
|
ACTOR_REF_BSKY,
|
|
|
|
POST_BSKY,
|
|
|
|
POST_HTML,
|
|
|
|
REPLY_BSKY,
|
|
|
|
REPLY_HTML,
|
|
|
|
REPOST_BSKY,
|
|
|
|
REPOST_HTML,
|
|
|
|
)
|
2022-12-29 01:30:22 +00:00
|
|
|
from oauth_dropins.webutil import util
|
2022-12-31 06:52:56 +00:00
|
|
|
from oauth_dropins.webutil.testutil import requests_response
|
2022-12-29 01:30:22 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
from . import testutil
|
|
|
|
|
|
|
|
|
|
|
|
@patch('requests.get')
|
|
|
|
class XrpcFeedTest(testutil.TestCase):
|
|
|
|
|
|
|
|
def test_getAuthorFeed(self, mock_get):
|
2022-12-30 18:10:49 +00:00
|
|
|
mock_get.return_value = requests_response(f"""\
|
|
|
|
<body class="h-feed">
|
|
|
|
<a href="/" class="u-author h-card">
|
|
|
|
<img src="/alice.jpg"> Alice
|
|
|
|
</a>
|
|
|
|
{POST_HTML}
|
|
|
|
{REPLY_HTML}
|
|
|
|
{REPOST_HTML}
|
2022-12-29 01:30:22 +00:00
|
|
|
</body>
|
2022-12-30 18:10:49 +00:00
|
|
|
""", url='https://alice.com/')
|
2022-12-29 01:30:22 +00:00
|
|
|
|
2022-12-30 18:10:49 +00:00
|
|
|
resp = self.client.get('/xrpc/app.bsky.feed.getAuthorFeed',
|
|
|
|
query_string={'author': 'alice.com'})
|
|
|
|
self.assertEqual(200, resp.status_code, resp.get_data(as_text=True))
|
2022-12-29 01:30:22 +00:00
|
|
|
self.assertEqual({
|
2022-12-31 06:52:56 +00:00
|
|
|
'feed': [POST_BSKY, REPLY_BSKY, REPOST_BSKY],
|
2022-12-30 18:10:49 +00:00
|
|
|
}, resp.json)
|
2022-12-29 01:30:22 +00:00
|
|
|
|
|
|
|
def test_getAuthorFeed_not_domain(self, _):
|
|
|
|
resp = self.client.get('/xrpc/app.bsky.feed.getAuthorFeed',
|
2022-12-30 18:10:49 +00:00
|
|
|
query_string={'author': 'not a domain'})
|
2022-12-29 01:30:22 +00:00
|
|
|
self.assertEqual(400, resp.status_code)
|
|
|
|
|
2022-12-30 18:10:49 +00:00
|
|
|
# def test_getPostThread(self, mock_get):
|
|
|
|
# mock_get.return_value = requests_response("""
|
|
|
|
# <body>
|
|
|
|
# </body>
|
|
|
|
# """, url='https://foo.com/')
|
|
|
|
|
|
|
|
# got = self.client.get('/xrpc/app.bsky.actor.getProfile',
|
|
|
|
# query_string={'actor': 'foo.com'},
|
|
|
|
# ).json
|
|
|
|
# self.assertEqual({
|
|
|
|
# }, got)
|
|
|
|
|
|
|
|
# def test_getRepostedBy(self, mock_get):
|
|
|
|
# mock_get.return_value = requests_response("""
|
|
|
|
# <body>
|
|
|
|
# </body>
|
|
|
|
# """, url='https://foo.com/')
|
|
|
|
|
|
|
|
# got = self.client.get('/xrpc/app.bsky.actor.getProfile',
|
|
|
|
# query_string={'actor': 'foo.com'},
|
|
|
|
# ).json
|
|
|
|
# self.assertEqual({
|
|
|
|
# }, got)
|
|
|
|
|
|
|
|
# def test_getTimeline(self, mock_get):
|
|
|
|
# mock_get.return_value = requests_response("""
|
|
|
|
# <body>
|
|
|
|
# </body>
|
|
|
|
# """, url='https://foo.com/')
|
|
|
|
|
|
|
|
# got = self.client.get('/xrpc/app.bsky.actor.getProfile',
|
|
|
|
# query_string={'actor': 'foo.com'},
|
|
|
|
# ).json
|
|
|
|
# self.assertEqual({
|
|
|
|
# }, got)
|
|
|
|
|
|
|
|
# def test_getVotes(self, mock_get):
|
|
|
|
# mock_get.return_value = requests_response("""
|
|
|
|
# <body>
|
|
|
|
# </body>
|
|
|
|
# """, url='https://foo.com/')
|
|
|
|
|
|
|
|
# got = self.client.get('/xrpc/app.bsky.actor.getVotes',
|
|
|
|
# query_string={'actor': 'foo.com'},
|
|
|
|
# ).json
|
|
|
|
# self.assertEqual({
|
|
|
|
# }, got)
|