rename main code directory
This commit is contained in:
1
bookwyrm/tests/activitypub/__init__.py
Normal file
1
bookwyrm/tests/activitypub/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from . import *
|
27
bookwyrm/tests/activitypub/test_author.py
Normal file
27
bookwyrm/tests/activitypub/test_author.py
Normal file
@ -0,0 +1,27 @@
|
||||
import datetime
|
||||
|
||||
from django.test import TestCase
|
||||
from fedireads import models
|
||||
|
||||
|
||||
class Author(TestCase):
|
||||
def setUp(self):
|
||||
self.book = models.Edition.objects.create(
|
||||
title='Example Edition',
|
||||
remote_id='https://example.com/book/1',
|
||||
)
|
||||
self.author = models.Author.objects.create(
|
||||
name='Author fullname',
|
||||
first_name='Auth',
|
||||
last_name='Or',
|
||||
aliases=['One', 'Two'],
|
||||
bio='bio bio bio',
|
||||
)
|
||||
|
||||
|
||||
def test_serialize_model(self):
|
||||
activity = self.author.to_activity()
|
||||
self.assertEqual(activity['id'], self.author.remote_id)
|
||||
self.assertIsInstance(activity['aliases'], list)
|
||||
self.assertEqual(activity['aliases'], ['One', 'Two'])
|
||||
self.assertEqual(activity['name'], 'Author fullname')
|
32
bookwyrm/tests/activitypub/test_person.py
Normal file
32
bookwyrm/tests/activitypub/test_person.py
Normal file
@ -0,0 +1,32 @@
|
||||
import json
|
||||
import pathlib
|
||||
from django.test import TestCase
|
||||
|
||||
from fedireads import activitypub, models
|
||||
|
||||
|
||||
class Person(TestCase):
|
||||
def setUp(self):
|
||||
self.user = models.User.objects.create_user(
|
||||
'rat', 'rat@rat.com', 'ratword',
|
||||
)
|
||||
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)
|
||||
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}
|
||||
)
|
46
bookwyrm/tests/activitypub/test_quotation.py
Normal file
46
bookwyrm/tests/activitypub/test_quotation.py
Normal file
@ -0,0 +1,46 @@
|
||||
import json
|
||||
import pathlib
|
||||
|
||||
from django.test import TestCase
|
||||
from fedireads import activitypub, models
|
||||
|
||||
|
||||
class Quotation(TestCase):
|
||||
''' we have hecka ways to create statuses '''
|
||||
def setUp(self):
|
||||
self.user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword',
|
||||
local=False,
|
||||
inbox='https://example.com/user/mouse/inbox',
|
||||
outbox='https://example.com/user/mouse/outbox',
|
||||
remote_id='https://example.com/user/mouse',
|
||||
)
|
||||
self.book = models.Edition.objects.create(
|
||||
title='Example Edition',
|
||||
remote_id='https://example.com/book/1',
|
||||
)
|
||||
datafile = pathlib.Path(__file__).parent.joinpath(
|
||||
'../data/ap_quotation.json'
|
||||
)
|
||||
self.status_data = json.loads(datafile.read_bytes())
|
||||
|
||||
|
||||
def test_quotation_activity(self):
|
||||
quotation = activitypub.Quotation(**self.status_data)
|
||||
|
||||
self.assertEqual(quotation.type, 'Quotation')
|
||||
self.assertEqual(
|
||||
quotation.id, 'https://example.com/user/mouse/quotation/13')
|
||||
self.assertEqual(quotation.content, 'commentary')
|
||||
self.assertEqual(quotation.quote, 'quote body')
|
||||
self.assertEqual(quotation.inReplyToBook, 'https://example.com/book/1')
|
||||
self.assertEqual(
|
||||
quotation.published, '2020-05-10T02:38:31.150343+00:00')
|
||||
|
||||
|
||||
def test_activity_to_model(self):
|
||||
activity = activitypub.Quotation(**self.status_data)
|
||||
quotation = activity.to_model(models.Quotation)
|
||||
|
||||
self.assertEqual(quotation.book, self.book)
|
||||
self.assertEqual(quotation.user, self.user)
|
Reference in New Issue
Block a user