2022-12-24 16:34:24 +00:00
|
|
|
"""Unit tests for actor.py."""
|
2022-12-28 17:27:42 +00:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
from oauth_dropins.webutil import util
|
|
|
|
from oauth_dropins.webutil.testutil import requests_response
|
|
|
|
import requests
|
|
|
|
|
2022-12-24 16:34:24 +00:00
|
|
|
from . import testutil
|
|
|
|
|
|
|
|
|
2022-12-28 17:27:42 +00:00
|
|
|
@patch('requests.get')
|
2022-12-29 01:30:22 +00:00
|
|
|
class XrpcActorTest(testutil.TestCase):
|
2022-12-24 16:34:24 +00:00
|
|
|
|
2022-12-28 17:27:42 +00:00
|
|
|
def test_getProfile(self, mock_get):
|
|
|
|
mock_get.return_value = requests_response("""
|
|
|
|
<body class="h-card">
|
|
|
|
<a class="u-url p-name" rel="me" href="/about-me">Mrs. ☕ Foo</a>
|
|
|
|
<img class="u-photo" src="/me.jpg" />
|
|
|
|
<img class="u-featured" src="/header.png" />
|
|
|
|
<span class="u-summary">I'm a person</span>
|
|
|
|
</body>
|
|
|
|
""", url='https://foo.com/')
|
|
|
|
|
2022-12-30 18:10:49 +00:00
|
|
|
resp = self.client.get('/xrpc/app.bsky.actor.getProfile',
|
|
|
|
query_string={'actor': 'foo.com'})
|
|
|
|
self.assertEqual(200, resp.status_code)
|
2022-12-28 17:27:42 +00:00
|
|
|
self.assertEqual({
|
|
|
|
'$type': 'app.bsky.actor.profile',
|
2023-01-13 20:50:46 +00:00
|
|
|
'handle': 'foo.com/about-me',
|
2023-01-13 00:36:12 +00:00
|
|
|
'did': 'did:web:foo.com:about-me',
|
|
|
|
'creator': 'did:web:foo.com:about-me',
|
2022-12-28 17:27:42 +00:00
|
|
|
'displayName': 'Mrs. ☕ Foo',
|
|
|
|
'declaration': {
|
2022-12-31 06:52:56 +00:00
|
|
|
'$type': 'app.bsky.system.declRef',
|
2022-12-28 17:27:42 +00:00
|
|
|
'cid': 'TODO',
|
|
|
|
'actorType': 'app.bsky.system.actorUser',
|
|
|
|
},
|
|
|
|
'description': "I'm a person",
|
|
|
|
'avatar': 'https://foo.com/me.jpg',
|
|
|
|
'banner': 'https://foo.com/header.png',
|
|
|
|
'followersCount': 0,
|
|
|
|
'followsCount': 0,
|
|
|
|
'membersCount': 0,
|
|
|
|
'postsCount': 0,
|
|
|
|
'myState': {
|
|
|
|
'follow': 'TODO',
|
|
|
|
'member': 'TODO',
|
|
|
|
},
|
2022-12-30 18:10:49 +00:00
|
|
|
}, resp.json)
|
2022-12-28 17:27:42 +00:00
|
|
|
|
|
|
|
def test_getProfile_not_domain(self, _):
|
2022-12-28 17:46:32 +00:00
|
|
|
resp = self.client.get('/xrpc/app.bsky.actor.getProfile',
|
|
|
|
query_string={'actor': 'not a domain'})
|
|
|
|
self.assertEqual(400, resp.status_code)
|
|
|
|
|
|
|
|
def test_getSuggestions(self, _):
|
2022-12-30 18:10:49 +00:00
|
|
|
resp = self.client.get('/xrpc/app.bsky.actor.getSuggestions')
|
|
|
|
self.assertEqual(200, resp.status_code)
|
2022-12-28 17:46:32 +00:00
|
|
|
self.assertEqual({
|
|
|
|
'actors': [],
|
2022-12-30 18:10:49 +00:00
|
|
|
}, resp.json)
|
2022-12-28 21:11:11 +00:00
|
|
|
|
|
|
|
def test_search(self, _):
|
2022-12-30 18:10:49 +00:00
|
|
|
resp = self.client.get('/xrpc/app.bsky.actor.search',
|
|
|
|
query_string={'term': 'foo'})
|
|
|
|
self.assertEqual(200, resp.status_code)
|
2022-12-28 21:11:11 +00:00
|
|
|
self.assertEqual({
|
|
|
|
'users': [],
|
2022-12-30 18:10:49 +00:00
|
|
|
}, resp.json)
|
2022-12-28 21:11:11 +00:00
|
|
|
|
|
|
|
def test_searchTypeahead(self, _):
|
2022-12-30 18:10:49 +00:00
|
|
|
resp = self.client.get('/xrpc/app.bsky.actor.searchTypeahead',
|
|
|
|
query_string={'term': 'foo'})
|
|
|
|
self.assertEqual(200, resp.status_code)
|
2022-12-28 21:11:11 +00:00
|
|
|
self.assertEqual({
|
|
|
|
'users': [],
|
2022-12-30 18:10:49 +00:00
|
|
|
}, resp.json)
|