Fixes tagging

This commit is contained in:
Mouse Reeve 2020-12-31 08:30:51 -08:00
parent 29ee027f6d
commit a7a586ea90
3 changed files with 25 additions and 7 deletions

View file

@ -283,11 +283,6 @@ def to_markdown(content):
return sanitizer.get_output()
def handle_tag(user, tag):
''' tag a book '''
broadcast(user, tag.to_add_activity(user))
def handle_untag(user, book, name):
''' tag a book '''
book = models.Book.objects.get(id=book)

View file

@ -41,6 +41,9 @@ class ViewActions(TestCase):
content='Test status',
remote_id='https://example.com/status/1',
)
self.work = models.Work.objects.create(title='Test Work')
self.book = models.Edition.objects.create(
title='Test Book', parent_work=self.work)
self.settings = models.SiteSettings.objects.create(id=1)
self.factory = RequestFactory()
@ -351,3 +354,23 @@ class ViewActions(TestCase):
author.refresh_from_db()
self.assertEqual(author.name, 'Test Author')
self.assertEqual(resp.template_name, 'edit_author.html')
def test_tag(self):
''' add a tag to a book '''
request = self.factory.post(
'', {
'name': 'A Tag!?',
'book': self.book.id,
})
request.user = self.local_user
with patch('bookwyrm.broadcast.broadcast_task.delay'):
actions.tag(request)
tag = models.Tag.objects.get()
user_tag = models.UserTag.objects.get()
self.assertEqual(tag.name, 'A Tag!?')
self.assertEqual(tag.identifier, 'A+Tag%21%3F')
self.assertEqual(user_tag.user, self.local_user)
self.assertEqual(user_tag.book, self.book)

View file

@ -577,14 +577,14 @@ def tag(request):
tag_obj, created = models.Tag.objects.get_or_create(
name=name,
)
user_tag = models.UserTag.objects.get_or_create(
user_tag, _ = models.UserTag.objects.get_or_create(
user=request.user,
book=book,
tag=tag_obj,
)
if created:
outgoing.handle_tag(request.user, user_tag)
broadcast(request.user, user_tag.to_add_activity(request.user))
return redirect('/book/%s' % book_id)