diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 2b0b3b477..b5e321ee7 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -119,7 +119,7 @@ class ManyToManyField(ActivitypubFieldMixin, models.ManyToManyField): def field_to_activity(self, value): if self.link_only: - return '%s/followers' % value.instance.remote_id + return '%s/%s' % (value.instance.remote_id, self.name) return [i.remote_id for i in value.all()] diff --git a/bookwyrm/tests/models/test_fields.py b/bookwyrm/tests/models/test_fields.py index 5e29a5272..e73930967 100644 --- a/bookwyrm/tests/models/test_fields.py +++ b/bookwyrm/tests/models/test_fields.py @@ -78,3 +78,28 @@ class ActivitypubFields(TestCase): Serializable = namedtuple('Serializable', ('to_activity', 'remote_id')) item = Serializable(lambda: {'a': 'b'}, 'https://e.b/c') self.assertEqual(instance.field_to_activity(item), 'https://e.b/c') + + def test_one_to_one_field(self): + instance = fields.OneToOneField('User', on_delete=models.CASCADE) + Serializable = namedtuple('Serializable', ('to_activity', 'remote_id')) + item = Serializable(lambda: {'a': 'b'}, 'https://e.b/c') + self.assertEqual(instance.field_to_activity(item), {'a': 'b'}) + + def test_many_to_many_field(self): + instance = fields.ManyToManyField('User') + + Serializable = namedtuple('Serializable', ('to_activity', 'remote_id')) + Queryset = namedtuple('Queryset', ('all', 'instance')) + item = Serializable(lambda: {'a': 'b'}, 'https://e.b/c') + another_item = Serializable(lambda: {}, 'example.com') + + items = Queryset(lambda: [item], another_item) + + self.assertEqual(instance.field_to_activity(items), ['https://e.b/c']) + + instance = fields.ManyToManyField('User', link_only=True) + instance.name = 'snake_case' + self.assertEqual( + instance.field_to_activity(items), + 'example.com/snake_case' + )