moviewyrm/bookwyrm/tests/activitypub/test_person.py

28 lines
1.1 KiB
Python
Raw Normal View History

2020-12-12 23:00:20 +00:00
# pylint: disable=missing-module-docstring, missing-class-docstring, missing-function-docstring
import json
import pathlib
2020-12-12 23:00:20 +00:00
from unittest.mock import patch
from django.test import TestCase
2020-12-12 23:00:20 +00:00
from bookwyrm import activitypub, models
class Person(TestCase):
def setUp(self):
2021-03-08 16:49:10 +00:00
datafile = pathlib.Path(__file__).parent.joinpath("../data/ap_user.json")
self.user_data = json.loads(datafile.read_bytes())
def test_load_user_data(self):
activity = activitypub.Person(**self.user_data)
2021-03-08 16:49:10 +00:00
self.assertEqual(activity.id, "https://example.com/user/mouse")
self.assertEqual(activity.preferredUsername, "mouse")
self.assertEqual(activity.type, "Person")
2020-12-12 23:00:20 +00:00
def test_user_to_model(self):
activity = activitypub.Person(**self.user_data)
2021-08-02 23:05:40 +00:00
with patch("bookwyrm.models.user.set_remote_server.delay"):
user = activity.to_model(model=models.User)
2021-03-08 16:49:10 +00:00
self.assertEqual(user.username, "mouse@example.com")
self.assertEqual(user.remote_id, "https://example.com/user/mouse")
2020-12-12 23:00:20 +00:00
self.assertFalse(user.local)