Tests base_model to_activity

This commit is contained in:
Mouse Reeve 2020-12-04 15:14:26 -08:00
parent 800ddf2a6b
commit 9c9da35d9a

View file

@ -1,8 +1,10 @@
''' testing models '''
from collections import namedtuple
from dataclasses import dataclass
import re
from django.test import TestCase
from bookwyrm.activitypub.base_activity import ActivityObject
from bookwyrm import models
from bookwyrm.models import base_model
from bookwyrm.models.base_model import ActivitypubMixin
@ -135,3 +137,21 @@ class BaseModel(TestCase):
self.assertEqual(activity['actor'], user.remote_id)
self.assertEqual(activity['type'], 'Undo')
self.assertEqual(activity['object'], {})
def test_to_activity(self):
@dataclass(init=False)
class TestActivity(ActivityObject):
type: str = 'Test'
class TestModel(ActivitypubMixin, base_model.BookWyrmModel):
pass
instance = TestModel()
instance.remote_id = 'https://www.example.com/test'
instance.activity_serializer = TestActivity
activity = instance.to_activity()
self.assertIsInstance(activity, dict)
self.assertEqual(activity['id'], 'https://www.example.com/test')
self.assertEqual(activity['type'], 'Test')