moviewyrm/bookwyrm/tests/test_remote_user.py

71 lines
2.4 KiB
Python
Raw Normal View History

2020-05-14 19:08:57 +00:00
import json
import pathlib
from django.test import TestCase
2020-05-14 19:08:57 +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(
'rat', 'rat@rat.com', 'ratword',
2020-05-14 19:08:57 +00:00
local=False,
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
)
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):
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):
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')
self.assertEqual(
user.public_key,
self.user_data['publicKey']['publicKeyPem']
)
2020-05-14 19:08:57 +00:00
self.assertEqual(user.local, False)
self.assertEqual(user.bookwyrm_user, True)
2020-05-14 19:08:57 +00:00
self.assertEqual(user.manually_approves_followers, False)
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)