mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-06-06 15:58:48 +00:00
minor pylint and mypy fixes
This commit is contained in:
parent
e29c93a1e9
commit
f30555be0f
4 changed files with 40 additions and 32 deletions
|
@ -1,4 +1,9 @@
|
||||||
"""Import data from Bookwyrm export files"""
|
"""Import data from Bookwyrm export files"""
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from django.http import QueryDict
|
||||||
|
|
||||||
|
from bookwyrm.models import User
|
||||||
from bookwyrm.models.bookwyrm_import_job import BookwyrmImportJob
|
from bookwyrm.models.bookwyrm_import_job import BookwyrmImportJob
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,8 +13,8 @@ class BookwyrmImporter:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def process_import(
|
def process_import(
|
||||||
self, user, archive_file, settings
|
self, user: User, archive_file: bytes, settings: QueryDict
|
||||||
): # pylint: disable=no-self-use
|
) -> BookwyrmImportJob: # pylint: disable=no-self-use
|
||||||
"""import user data from a Bookwyrm export file"""
|
"""import user data from a Bookwyrm export file"""
|
||||||
|
|
||||||
required = [k for k in settings if settings.get(k) == "on"]
|
required = [k for k in settings if settings.get(k) == "on"]
|
||||||
|
|
|
@ -60,7 +60,7 @@ def tar_export(json_data: str, user, file):
|
||||||
if getattr(user, "avatar", False):
|
if getattr(user, "avatar", False):
|
||||||
tar.add_image(user.avatar, filename="avatar")
|
tar.add_image(user.avatar, filename="avatar")
|
||||||
|
|
||||||
editions, books = get_books_for_user(user) # pylint: disable=unused-argument
|
editions, books = get_books_for_user(user) # pylint: disable=unused-variable
|
||||||
for book in editions:
|
for book in editions:
|
||||||
if getattr(book, "cover", False):
|
if getattr(book, "cover", False):
|
||||||
tar.add_image(book.cover)
|
tar.add_image(book.cover)
|
||||||
|
|
|
@ -13,7 +13,7 @@ from bookwyrm.utils.tar import BookwyrmTarFile
|
||||||
from bookwyrm.models import bookwyrm_import_job
|
from bookwyrm.models import bookwyrm_import_job
|
||||||
|
|
||||||
|
|
||||||
class BookwyrmImport(TestCase):
|
class BookwyrmImport(TestCase): # pylint: disable=too-many-public-methods
|
||||||
"""testing user import functions"""
|
"""testing user import functions"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -66,8 +66,10 @@ class BookwyrmImport(TestCase):
|
||||||
"../data/bookwyrm_account_export.tar.gz"
|
"../data/bookwyrm_account_export.tar.gz"
|
||||||
)
|
)
|
||||||
with open(self.archive_file, "rb") as fileobj:
|
with open(self.archive_file, "rb") as fileobj:
|
||||||
tarfile = BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj)
|
with BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile:
|
||||||
self.import_data = json.loads(tarfile.read("archive.json").decode("utf-8"))
|
self.import_data = json.loads(
|
||||||
|
tarfile.read("archive.json").decode("utf-8")
|
||||||
|
)
|
||||||
|
|
||||||
def test_update_user_profile(self):
|
def test_update_user_profile(self):
|
||||||
"""Test update the user's profile from import data"""
|
"""Test update the user's profile from import data"""
|
||||||
|
@ -77,7 +79,7 @@ class BookwyrmImport(TestCase):
|
||||||
):
|
):
|
||||||
|
|
||||||
with open(self.archive_file, "rb") as fileobj:
|
with open(self.archive_file, "rb") as fileobj:
|
||||||
tarfile = BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj)
|
with BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile:
|
||||||
|
|
||||||
models.bookwyrm_import_job.update_user_profile(
|
models.bookwyrm_import_job.update_user_profile(
|
||||||
self.local_user, tarfile, self.import_data.get("user")
|
self.local_user, tarfile, self.import_data.get("user")
|
||||||
|
@ -253,7 +255,7 @@ class BookwyrmImport(TestCase):
|
||||||
self.assertEqual(models.Edition.objects.count(), 1)
|
self.assertEqual(models.Edition.objects.count(), 1)
|
||||||
|
|
||||||
with open(self.archive_file, "rb") as fileobj:
|
with open(self.archive_file, "rb") as fileobj:
|
||||||
tarfile = BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj)
|
with BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile:
|
||||||
|
|
||||||
bookwyrm_import_job.get_or_create_edition(
|
bookwyrm_import_job.get_or_create_edition(
|
||||||
self.import_data["books"][1], tarfile
|
self.import_data["books"][1], tarfile
|
||||||
|
@ -269,7 +271,7 @@ class BookwyrmImport(TestCase):
|
||||||
self.assertEqual(models.Edition.objects.count(), 1)
|
self.assertEqual(models.Edition.objects.count(), 1)
|
||||||
|
|
||||||
with open(self.archive_file, "rb") as fileobj:
|
with open(self.archive_file, "rb") as fileobj:
|
||||||
tarfile = BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj)
|
with BookwyrmTarFile.open(mode="r:gz", fileobj=fileobj) as tarfile:
|
||||||
bookwyrm_import_job.get_or_create_edition(
|
bookwyrm_import_job.get_or_create_edition(
|
||||||
self.import_data["books"][0], tarfile
|
self.import_data["books"][0], tarfile
|
||||||
) # Seeing like a state
|
) # Seeing like a state
|
||||||
|
|
|
@ -39,6 +39,7 @@ class BookwyrmTarFile(tarfile.TarFile):
|
||||||
"""read data from the tar"""
|
"""read data from the tar"""
|
||||||
if reader := self.extractfile(filename):
|
if reader := self.extractfile(filename):
|
||||||
return reader.read()
|
return reader.read()
|
||||||
|
return None
|
||||||
|
|
||||||
def write_image_to_file(self, filename: str, file_field: Any) -> None:
|
def write_image_to_file(self, filename: str, file_field: Any) -> None:
|
||||||
"""add an image to the tar"""
|
"""add an image to the tar"""
|
||||||
|
|
Loading…
Reference in a new issue