def test_tag_bookmarks_should_accept_mix_of_int_and_string_ids(self): bookmark1 = self.setup_bookmark() bookmark2 = self.setup_bookmark() bookmark3 = self.setup_bookmark() tag1 = self.setup_tag() tag2 = self.setup_tag() tag_bookmarks([str(bookmark1.id), bookmark2.id, str(bookmark3.id)], f'{tag1.name} {tag2.name}', self.get_or_create_test_user()) self.assertCountEqual(bookmark1.tags.all(), [tag1, tag2]) self.assertCountEqual(bookmark2.tags.all(), [tag1, tag2]) self.assertCountEqual(bookmark3.tags.all(), [tag1, tag2])
def test_tag_bookmarks_should_only_tag_specified_bookmarks(self): bookmark1 = self.setup_bookmark() bookmark2 = self.setup_bookmark() bookmark3 = self.setup_bookmark() tag1 = self.setup_tag() tag2 = self.setup_tag() tag_bookmarks([bookmark1.id, bookmark3.id], f'{tag1.name} {tag2.name}', self.get_or_create_test_user()) bookmark1.refresh_from_db() bookmark2.refresh_from_db() bookmark3.refresh_from_db() self.assertCountEqual(bookmark1.tags.all(), [tag1, tag2]) self.assertCountEqual(bookmark2.tags.all(), []) self.assertCountEqual(bookmark3.tags.all(), [tag1, tag2])
def bulk_edit(request): bookmark_ids = request.POST.getlist('bookmark_id') # Determine action if 'bulk_archive' in request.POST: archive_bookmarks(bookmark_ids, request.user) if 'bulk_unarchive' in request.POST: unarchive_bookmarks(bookmark_ids, request.user) if 'bulk_delete' in request.POST: delete_bookmarks(bookmark_ids, request.user) if 'bulk_tag' in request.POST: tag_string = request.POST['bulk_tag_string'] tag_bookmarks(bookmark_ids, tag_string, request.user) if 'bulk_untag' in request.POST: tag_string = request.POST['bulk_tag_string'] untag_bookmarks(bookmark_ids, tag_string, request.user) return_url = request.GET.get('return_url') return_url = return_url if return_url else reverse('bookmarks:index') return HttpResponseRedirect(return_url)
def test_tag_bookmarks_should_only_tag_user_owned_bookmarks(self): other_user = User.objects.create_user('otheruser', '*****@*****.**', 'password123') bookmark1 = self.setup_bookmark() bookmark2 = self.setup_bookmark() inaccessible_bookmark = self.setup_bookmark(user=other_user) tag1 = self.setup_tag() tag2 = self.setup_tag() tag_bookmarks([bookmark1.id, bookmark2.id, inaccessible_bookmark.id], f'{tag1.name} {tag2.name}', self.get_or_create_test_user()) bookmark1.refresh_from_db() bookmark2.refresh_from_db() inaccessible_bookmark.refresh_from_db() self.assertCountEqual(bookmark1.tags.all(), [tag1, tag2]) self.assertCountEqual(bookmark2.tags.all(), [tag1, tag2]) self.assertCountEqual(inaccessible_bookmark.tags.all(), [])
def test_tag_bookmarks_should_create_tags(self): bookmark1 = self.setup_bookmark() bookmark2 = self.setup_bookmark() bookmark3 = self.setup_bookmark() tag_bookmarks([bookmark1.id, bookmark2.id, bookmark3.id], 'tag1 tag2', self.get_or_create_test_user()) bookmark1.refresh_from_db() bookmark2.refresh_from_db() bookmark3.refresh_from_db() self.assertEqual(2, Tag.objects.count()) tag1 = Tag.objects.filter(name='tag1').first() tag2 = Tag.objects.filter(name='tag2').first() self.assertIsNotNone(tag1) self.assertIsNotNone(tag2) self.assertCountEqual(bookmark1.tags.all(), [tag1, tag2]) self.assertCountEqual(bookmark2.tags.all(), [tag1, tag2]) self.assertCountEqual(bookmark3.tags.all(), [tag1, tag2])