Fixes remote user code
and tests!
This commit is contained in:
parent
b203ae5b33
commit
a0507edcac
3 changed files with 97 additions and 13 deletions
36
fedireads/tests/data/ap_user.json
Normal file
36
fedireads/tests/data/ap_user.json
Normal file
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"schema": "http://schema.org#",
|
||||
"PropertyValue": "schema:PropertyValue",
|
||||
"value": "schema:value"
|
||||
}
|
||||
],
|
||||
"id": "https://example.com/user/mouse",
|
||||
"type": "Person",
|
||||
"preferredUsername": "mouse",
|
||||
"name": "MOUSE?? MOUSE!!",
|
||||
"inbox": "https://example.com/user/mouse/inbox",
|
||||
"outbox": "https://example.com/user/mouse/outbox",
|
||||
"followers": "https://example.com/user/mouse/followers",
|
||||
"following": "https://example.com/user/mouse/following",
|
||||
"summary": "",
|
||||
"publicKey": {
|
||||
"id": "https://example.com/user/mouse/#main-key",
|
||||
"owner": "https://example.com/user/mouse",
|
||||
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC6QisDrjOQvkRo/MqNmSYPwqtt\nCxg/8rCW+9jKbFUKvqjTeKVotEE85122v/DCvobCCdfQuYIFdVMk+dB1xJ0iPGPg\nyU79QHY22NdV9mFKA2qtXVVxb5cxpA4PlwOHM6PM/k8B+H09OUrop2aPUAYwy+vg\n+MXyz8bAXrIS1kq6fQIDAQAB\n-----END PUBLIC KEY-----"
|
||||
},
|
||||
"endpoints": {
|
||||
"sharedInbox": "https://example.com/inbox"
|
||||
},
|
||||
"fedireadsUser": true,
|
||||
"manuallyApprovesFollowers": false,
|
||||
"icon": {
|
||||
"type": "Image",
|
||||
"mediaType": "image/png",
|
||||
"url": "https://example.com/images/avatars/AL-2-crop-50.png"
|
||||
}
|
||||
}
|
37
fedireads/tests/test_remote_user.py
Normal file
37
fedireads/tests/test_remote_user.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
from django.test import TestCase
|
||||
import json
|
||||
import pathlib
|
||||
|
||||
from fedireads import models, remote_user
|
||||
|
||||
|
||||
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(
|
||||
'mouse', 'mouse@mouse.com', 'mouseword',
|
||||
local=False,
|
||||
remote_id='https://example.com/users/mouse',
|
||||
inbox='https://example.com/users/mouse/inbox',
|
||||
outbox='https://example.com/users/mouse/outbox',
|
||||
)
|
||||
|
||||
def test_get_remote_user(self):
|
||||
actor = 'https://example.com/users/mouse'
|
||||
user = remote_user.get_or_create_remote_user(actor)
|
||||
self.assertEqual(user, self.remote_user)
|
||||
|
||||
|
||||
def test_create_remote_user(self):
|
||||
datafile = pathlib.Path(__file__).parent.joinpath('data/ap_user.json')
|
||||
data = json.loads(datafile.read_bytes())
|
||||
user = remote_user.create_remote_user(data)
|
||||
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, data['publicKey']['publicKeyPem'])
|
||||
self.assertEqual(user.local, False)
|
||||
self.assertEqual(user.fedireads_user, True)
|
||||
self.assertEqual(user.manually_approves_followers, False)
|
Loading…
Add table
Add a link
Reference in a new issue