mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-12 10:15:29 +00:00
Additional import tests
This commit is contained in:
parent
7a547d9a1a
commit
10c74d0619
1 changed files with 37 additions and 5 deletions
|
@ -1,13 +1,14 @@
|
||||||
""" test for app action functionality """
|
""" test for app action functionality """
|
||||||
import pathlib
|
import pathlib
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
from bookwyrm.tests.validate_html import validate_html
|
|
||||||
|
|
||||||
from bookwyrm import forms, models, views
|
from bookwyrm import forms, models, views
|
||||||
|
from bookwyrm.tests.validate_html import validate_html
|
||||||
|
|
||||||
|
|
||||||
class ImportViews(TestCase):
|
class ImportViews(TestCase):
|
||||||
|
@ -44,15 +45,29 @@ class ImportViews(TestCase):
|
||||||
import_job = models.ImportJob.objects.create(user=self.local_user, mappings={})
|
import_job = models.ImportJob.objects.create(user=self.local_user, mappings={})
|
||||||
request = self.factory.get("")
|
request = self.factory.get("")
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
with patch("bookwyrm.tasks.app.AsyncResult") as async_result:
|
|
||||||
async_result.return_value = []
|
result = view(request, import_job.id)
|
||||||
result = view(request, import_job.id)
|
|
||||||
self.assertIsInstance(result, TemplateResponse)
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
validate_html(result.render())
|
validate_html(result.render())
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_import_status_reformat(self):
|
||||||
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
|
view = views.ImportStatus.as_view()
|
||||||
|
import_job = models.ImportJob.objects.create(user=self.local_user, mappings={})
|
||||||
|
request = self.factory.post("")
|
||||||
|
request.user = self.local_user
|
||||||
|
with patch(
|
||||||
|
"bookwyrm.importers.goodreads_import.GoodreadsImporter.update_legacy_job"
|
||||||
|
) as mock:
|
||||||
|
result = view(request, import_job.id)
|
||||||
|
self.assertEqual(mock.call_args[0][0], import_job)
|
||||||
|
|
||||||
|
self.assertEqual(result.status_code, 302)
|
||||||
|
|
||||||
def test_start_import(self):
|
def test_start_import(self):
|
||||||
"""retry failed items"""
|
"""start a job"""
|
||||||
view = views.Import.as_view()
|
view = views.Import.as_view()
|
||||||
form = forms.ImportForm()
|
form = forms.ImportForm()
|
||||||
form.data["source"] = "Goodreads"
|
form.data["source"] = "Goodreads"
|
||||||
|
@ -74,3 +89,20 @@ class ImportViews(TestCase):
|
||||||
job = models.ImportJob.objects.get()
|
job = models.ImportJob.objects.get()
|
||||||
self.assertFalse(job.include_reviews)
|
self.assertFalse(job.include_reviews)
|
||||||
self.assertEqual(job.privacy, "public")
|
self.assertEqual(job.privacy, "public")
|
||||||
|
|
||||||
|
def test_retry_item(self):
|
||||||
|
"""try again on a single row"""
|
||||||
|
job = models.ImportJob.objects.create(user=self.local_user, mappings={})
|
||||||
|
item = models.ImportItem.objects.create(
|
||||||
|
index=0,
|
||||||
|
job=job,
|
||||||
|
book_guess=self.book,
|
||||||
|
fail_reason="no match",
|
||||||
|
data={},
|
||||||
|
normalized_data={},
|
||||||
|
)
|
||||||
|
request = self.factory.post("")
|
||||||
|
request.user = self.local_user
|
||||||
|
with patch("bookwyrm.importers.importer.import_item_task.delay") as mock:
|
||||||
|
views.retry_item(request, job.id, item.id)
|
||||||
|
self.assertEqual(mock.call_count, 1)
|
||||||
|
|
Loading…
Reference in a new issue