mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-28 04:21:07 +00:00
More user serialization tests
This commit is contained in:
parent
eb28708230
commit
49979fabef
3 changed files with 21 additions and 1 deletions
|
@ -190,6 +190,7 @@ class KeyPair(ActivitypubMixin, BookWyrmModel):
|
|||
|
||||
|
||||
@receiver(models.signals.post_save, sender=User)
|
||||
#pylint: disable=unused-argument
|
||||
def execute_after_save(sender, instance, created, *args, **kwargs):
|
||||
''' create shelves for new users '''
|
||||
if not created:
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
# pylint: disable=missing-module-docstring, missing-class-docstring, missing-function-docstring
|
||||
import json
|
||||
import pathlib
|
||||
from unittest.mock import patch
|
||||
from django.test import TestCase
|
||||
|
||||
from bookwyrm import activitypub
|
||||
from bookwyrm import activitypub, models
|
||||
|
||||
|
||||
class Person(TestCase):
|
||||
|
@ -18,3 +20,12 @@ class Person(TestCase):
|
|||
self.assertEqual(activity.id, 'https://example.com/user/mouse')
|
||||
self.assertEqual(activity.preferredUsername, 'mouse')
|
||||
self.assertEqual(activity.type, 'Person')
|
||||
|
||||
|
||||
def test_user_to_model(self):
|
||||
activity = activitypub.Person(**self.user_data)
|
||||
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
||||
user = activity.to_model(models.User)
|
||||
self.assertEqual(user.username, 'mouse@example.com')
|
||||
self.assertEqual(user.remote_id, 'https://example.com/user/mouse')
|
||||
self.assertFalse(user.local)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
''' testing models '''
|
||||
from unittest.mock import patch
|
||||
from django.test import TestCase
|
||||
|
||||
from bookwyrm import models
|
||||
|
@ -22,6 +23,13 @@ class User(TestCase):
|
|||
self.assertIsNotNone(self.user.key_pair.private_key)
|
||||
self.assertIsNotNone(self.user.key_pair.public_key)
|
||||
|
||||
def test_remote_user(self):
|
||||
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
||||
user = models.User.objects.create_user(
|
||||
'rat', 'rat@rat.rat', 'ratword', local=False,
|
||||
remote_id='https://example.com/dfjkg')
|
||||
self.assertEqual(user.username, 'rat@example.com')
|
||||
|
||||
|
||||
def test_user_shelves(self):
|
||||
shelves = models.Shelf.objects.filter(user=self.user).all()
|
||||
|
|
Loading…
Reference in a new issue