2020-05-14 19:08:57 +00:00
|
|
|
import json
|
|
|
|
import pathlib
|
2020-09-17 20:02:52 +00:00
|
|
|
from django.test import TestCase
|
2020-05-14 19:08:57 +00:00
|
|
|
|
2020-09-21 15:10:37 +00:00
|
|
|
from bookwyrm import models, remote_user
|
2020-05-14 19:08:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RemoteUser(TestCase):
|
|
|
|
''' not too much going on in the books model but here we are '''
|
|
|
|
def setUp(self):
|
|
|
|
self.remote_user = models.User.objects.create_user(
|
2020-09-17 20:02:52 +00:00
|
|
|
'rat', 'rat@rat.com', 'ratword',
|
2020-05-14 19:08:57 +00:00
|
|
|
local=False,
|
2020-09-17 20:02:52 +00:00
|
|
|
remote_id='https://example.com/users/rat',
|
|
|
|
inbox='https://example.com/users/rat/inbox',
|
|
|
|
outbox='https://example.com/users/rat/outbox',
|
2020-05-14 19:08:57 +00:00
|
|
|
)
|
2020-09-17 20:02:52 +00:00
|
|
|
datafile = pathlib.Path(__file__).parent.joinpath(
|
|
|
|
'data/ap_user.json'
|
|
|
|
)
|
|
|
|
self.user_data = json.loads(datafile.read_bytes())
|
|
|
|
|
|
|
|
|
2020-05-14 19:08:57 +00:00
|
|
|
|
|
|
|
def test_get_remote_user(self):
|
2020-09-17 20:02:52 +00:00
|
|
|
actor = 'https://example.com/users/rat'
|
2020-05-14 19:08:57 +00:00
|
|
|
user = remote_user.get_or_create_remote_user(actor)
|
|
|
|
self.assertEqual(user, self.remote_user)
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_remote_user(self):
|
2020-09-17 20:02:52 +00:00
|
|
|
user = remote_user.create_remote_user(self.user_data)
|
|
|
|
self.assertFalse(user.local)
|
|
|
|
self.assertEqual(user.remote_id, 'https://example.com/user/mouse')
|
2020-05-14 19:08:57 +00:00
|
|
|
self.assertEqual(user.username, 'mouse@example.com')
|
|
|
|
self.assertEqual(user.name, 'MOUSE?? MOUSE!!')
|
|
|
|
self.assertEqual(user.inbox, 'https://example.com/user/mouse/inbox')
|
|
|
|
self.assertEqual(user.outbox, 'https://example.com/user/mouse/outbox')
|
|
|
|
self.assertEqual(user.shared_inbox, 'https://example.com/inbox')
|
2020-09-17 20:02:52 +00:00
|
|
|
self.assertEqual(
|
|
|
|
user.public_key,
|
|
|
|
self.user_data['publicKey']['publicKeyPem']
|
|
|
|
)
|
2020-05-14 19:08:57 +00:00
|
|
|
self.assertEqual(user.local, False)
|
2020-09-21 15:10:37 +00:00
|
|
|
self.assertEqual(user.bookwyrm_user, True)
|
2020-05-14 19:08:57 +00:00
|
|
|
self.assertEqual(user.manually_approves_followers, False)
|
2020-09-17 20:02:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_create_remote_user_missing_inbox(self):
|
|
|
|
del self.user_data['inbox']
|
|
|
|
self.assertRaises(
|
|
|
|
TypeError,
|
|
|
|
remote_user.create_remote_user,
|
|
|
|
self.user_data
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_remote_user_missing_outbox(self):
|
|
|
|
del self.user_data['outbox']
|
|
|
|
self.assertRaises(
|
|
|
|
TypeError,
|
|
|
|
remote_user.create_remote_user,
|
|
|
|
self.user_data
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_remote_user_default_fields(self):
|
|
|
|
del self.user_data['manuallyApprovesFollowers']
|
|
|
|
user = remote_user.create_remote_user(self.user_data)
|
|
|
|
self.assertEqual(user.manually_approves_followers, False)
|