From 49979fabef7390ad6344c3ce164496af5cecf303 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 12 Dec 2020 15:00:20 -0800 Subject: [PATCH] More user serialization tests --- bookwyrm/models/user.py | 1 + bookwyrm/tests/activitypub/test_person.py | 13 ++++++++++++- bookwyrm/tests/models/test_user_model.py | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 0ef9a2e6..63549d36 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -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: diff --git a/bookwyrm/tests/activitypub/test_person.py b/bookwyrm/tests/activitypub/test_person.py index 3e0d74e0..c7a8221c 100644 --- a/bookwyrm/tests/activitypub/test_person.py +++ b/bookwyrm/tests/activitypub/test_person.py @@ -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) diff --git a/bookwyrm/tests/models/test_user_model.py b/bookwyrm/tests/models/test_user_model.py index dabf760c..0454fb40 100644 --- a/bookwyrm/tests/models/test_user_model.py +++ b/bookwyrm/tests/models/test_user_model.py @@ -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()