from unittest.mock import patch from django.test import TestCase from bookmarks.services import tasks from bookmarks.services.importer import import_netscape_html from bookmarks.tests.helpers import BookmarkFactoryMixin, disable_logging class ImporterTestCase(TestCase, BookmarkFactoryMixin): def create_import_html(self, bookmark_tags_string: str): return f''' Bookmarks

Bookmarks

{bookmark_tags_string}

''' @disable_logging def test_validate_empty_or_missing_bookmark_url(self): test_html = self.create_import_html(f'''

Empty URL
Empty URL
Missing URL
Missing URL ''') import_result = import_netscape_html(test_html, self.get_or_create_test_user()) self.assertEqual(import_result.success, 0) def test_schedule_snapshot_creation(self): user = self.get_or_create_test_user() test_html = self.create_import_html('') with patch.object(tasks, 'schedule_bookmarks_without_snapshots') as mock_schedule_bookmarks_without_snapshots: import_netscape_html(test_html, user) mock_schedule_bookmarks_without_snapshots.assert_called_once_with(user.id)