From 7a153e185a798f491cb315878393de87ae77df46 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 16 Oct 2020 09:45:14 -0700 Subject: [PATCH] User activitypub tests --- bookwyrm/tests/activitypub/test_person.py | 9 ---- bookwyrm/tests/models/test_user_model.py | 51 +++++++++++++++++------ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/bookwyrm/tests/activitypub/test_person.py b/bookwyrm/tests/activitypub/test_person.py index 8a077a29e..bec9e19bd 100644 --- a/bookwyrm/tests/activitypub/test_person.py +++ b/bookwyrm/tests/activitypub/test_person.py @@ -21,12 +21,3 @@ class Person(TestCase): self.assertEqual(activity.id, 'https://example.com/user/mouse') self.assertEqual(activity.preferredUsername, 'mouse') self.assertEqual(activity.type, 'Person') - - - def test_serialize_model(self): - activity = self.user.to_activity() - self.assertEqual(activity['id'], self.user.remote_id) - self.assertEqual( - activity['endpoints'], - {'sharedInbox': self.user.shared_inbox} - ) diff --git a/bookwyrm/tests/models/test_user_model.py b/bookwyrm/tests/models/test_user_model.py index a423de37c..0b43cc005 100644 --- a/bookwyrm/tests/models/test_user_model.py +++ b/bookwyrm/tests/models/test_user_model.py @@ -7,28 +7,55 @@ from bookwyrm.settings import DOMAIN class User(TestCase): def setUp(self): - models.User.objects.create_user( + self.user = models.User.objects.create_user( 'mouse', 'mouse@mouse.mouse', 'mouseword') def test_computed_fields(self): ''' username instead of id here ''' - user = models.User.objects.get(localname='mouse') expected_id = 'https://%s/user/mouse' % DOMAIN - self.assertEqual(user.remote_id, expected_id) - self.assertEqual(user.username, 'mouse@%s' % DOMAIN) - self.assertEqual(user.localname, 'mouse') - self.assertEqual(user.shared_inbox, 'https://%s/inbox' % DOMAIN) - self.assertEqual(user.inbox, '%s/inbox' % expected_id) - self.assertEqual(user.outbox, '%s/outbox' % expected_id) - self.assertIsNotNone(user.private_key) - self.assertIsNotNone(user.public_key) + self.assertEqual(self.user.remote_id, expected_id) + self.assertEqual(self.user.username, 'mouse@%s' % DOMAIN) + self.assertEqual(self.user.localname, 'mouse') + self.assertEqual(self.user.shared_inbox, 'https://%s/inbox' % DOMAIN) + self.assertEqual(self.user.inbox, '%s/inbox' % expected_id) + self.assertEqual(self.user.outbox, '%s/outbox' % expected_id) + self.assertIsNotNone(self.user.private_key) + self.assertIsNotNone(self.user.public_key) def test_user_shelves(self): - user = models.User.objects.get(localname='mouse') - shelves = models.Shelf.objects.filter(user=user).all() + shelves = models.Shelf.objects.filter(user=self.user).all() self.assertEqual(len(shelves), 3) names = [s.name for s in shelves] self.assertEqual(names, ['To Read', 'Currently Reading', 'Read']) ids = [s.identifier for s in shelves] self.assertEqual(ids, ['to-read', 'reading', 'read']) + + + def test_activitypub_serialize(self): + activity = self.user.to_activity() + self.assertEqual(activity['id'], self.user.remote_id) + self.assertEqual(activity['@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', + } + ]) + self.assertEqual(activity['preferredUsername'], self.user.localname) + self.assertEqual(activity['name'], self.user.name) + self.assertEqual(activity['inbox'], self.user.inbox) + self.assertEqual(activity['outbox'], self.user.outbox) + self.assertEqual(activity['followers'], self.user.ap_followers) + self.assertEqual(activity['bookwyrmUser'], False) + self.assertEqual(activity['discoverable'], True) + self.assertEqual(activity['type'], 'Person') + + def test_activitypub_outbox(self): + activity = self.user.to_outbox() + self.assertEqual(activity['type'], 'OrderedCollection') + self.assertEqual(activity['id'], self.user.outbox) + self.assertEqual(activity['totalItems'], 0)