mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-02-16 19:15:16 +00:00
Adds tests for resolve_remote_id
This commit is contained in:
parent
74ac8d60f8
commit
f61fcb1261
1 changed files with 38 additions and 1 deletions
|
@ -1,9 +1,14 @@
|
||||||
''' tests the base functionality for activitypub dataclasses '''
|
''' tests the base functionality for activitypub dataclasses '''
|
||||||
|
import json
|
||||||
|
import pathlib
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
import responses
|
||||||
|
|
||||||
from bookwyrm.activitypub.base_activity import ActivityObject, \
|
from bookwyrm.activitypub.base_activity import ActivityObject, \
|
||||||
find_existing_by_remote_id
|
find_existing_by_remote_id, resolve_remote_id
|
||||||
from bookwyrm.activitypub import ActivitySerializerError
|
from bookwyrm.activitypub import ActivitySerializerError
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
|
|
||||||
|
@ -79,3 +84,35 @@ class BaseActivity(TestCase):
|
||||||
# test subclass match
|
# test subclass match
|
||||||
result = find_existing_by_remote_id(
|
result = find_existing_by_remote_id(
|
||||||
models.Status, 'https://comment.net')
|
models.Status, 'https://comment.net')
|
||||||
|
|
||||||
|
@responses.activate
|
||||||
|
def test_resolve_remote_id(self):
|
||||||
|
''' look up or load remote data '''
|
||||||
|
user = models.User.objects.create_user(
|
||||||
|
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||||
|
user.remote_id = 'http://example.com/a/b'
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
# existing item
|
||||||
|
result = resolve_remote_id(models.User, 'http://example.com/a/b')
|
||||||
|
self.assertEqual(result, user)
|
||||||
|
|
||||||
|
# remote item
|
||||||
|
datafile = pathlib.Path(__file__).parent.joinpath(
|
||||||
|
'../data/ap_user.json'
|
||||||
|
)
|
||||||
|
userdata = json.loads(datafile.read_bytes())
|
||||||
|
# don't try to load the user icon
|
||||||
|
del userdata['icon']
|
||||||
|
responses.add(
|
||||||
|
responses.GET,
|
||||||
|
'https://example.com/user/mouse',
|
||||||
|
json=userdata,
|
||||||
|
status=200)
|
||||||
|
|
||||||
|
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
||||||
|
result = resolve_remote_id(
|
||||||
|
models.User, 'https://example.com/user/mouse')
|
||||||
|
self.assertIsInstance(result, models.User)
|
||||||
|
self.assertEqual(result.remote_id, 'https://example.com/user/mouse')
|
||||||
|
self.assertEqual(result.name, 'MOUSE?? MOUSE!!')
|
||||||
|
|
Loading…
Reference in a new issue