def test_tag_field(self): """a special type of many to many field""" instance = fields.TagField("User") Serializable = namedtuple( "Serializable", ("to_activity", "remote_id", "name_field", "name")) Queryset = namedtuple("Queryset", ("all", "instance")) item = Serializable(lambda: {"a": "b"}, "https://e.b/c", "name", "Name") another_item = Serializable(lambda: {}, "example.com", "", "") items = Queryset(lambda: [item], another_item) result = instance.field_to_activity(items) self.assertIsInstance(result, list) self.assertEqual(len(result), 1) self.assertEqual(result[0].href, "https://e.b/c") self.assertEqual(result[0].name, "Name") self.assertEqual(result[0].type, "Serializable")
def test_tag_field(self): ''' a special type of many to many field ''' instance = fields.TagField('User') Serializable = namedtuple( 'Serializable', ('to_activity', 'remote_id', 'name_field', 'name')) Queryset = namedtuple('Queryset', ('all', 'instance')) item = Serializable(lambda: {'a': 'b'}, 'https://e.b/c', 'name', 'Name') another_item = Serializable(lambda: {}, 'example.com', '', '') items = Queryset(lambda: [item], another_item) result = instance.field_to_activity(items) self.assertIsInstance(result, list) self.assertEqual(len(result), 1) self.assertEqual(result[0].href, 'https://e.b/c') self.assertEqual(result[0].name, 'Name') self.assertEqual(result[0].type, 'Serializable')
class TestPrivacyModel(ActivitypubMixin, BookWyrmModel): """real simple mock model because BookWyrmModel is abstract""" privacy_field = fields.PrivacyField() mention_users = fields.TagField(User) user = fields.ForeignKey(User, on_delete=models.CASCADE)