mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 17:41:08 +00:00
Use new "with ()" style
This commit is contained in:
parent
0ac9d12d1c
commit
5d597f1ca9
1 changed files with 18 additions and 16 deletions
|
@ -233,22 +233,24 @@ class BookwyrmExportJob(TestCase):
|
||||||
models.bookwyrm_export_job.create_archive_task(job_id=self.job.id)
|
models.bookwyrm_export_job.create_archive_task(job_id=self.job.id)
|
||||||
self.job.refresh_from_db()
|
self.job.refresh_from_db()
|
||||||
|
|
||||||
with self.job.export_data.open("rb") as tar_file:
|
with (
|
||||||
with BookwyrmTarFile.open(mode="r", fileobj=tar_file) as tar:
|
self.job.export_data.open("rb") as tar_file,
|
||||||
archive_json_file = tar.extractfile("archive.json")
|
BookwyrmTarFile.open(mode="r", fileobj=tar_file) as tar,
|
||||||
data = json.load(archive_json_file)
|
):
|
||||||
|
archive_json_file = tar.extractfile("archive.json")
|
||||||
|
data = json.load(archive_json_file)
|
||||||
|
|
||||||
# JSON from the archive should be what we want it to be
|
# JSON from the archive should be what we want it to be
|
||||||
self.assertEqual(data, self.job.export_json)
|
self.assertEqual(data, self.job.export_json)
|
||||||
|
|
||||||
# User avatar should be present in archive
|
# User avatar should be present in archive
|
||||||
with self.local_user.avatar.open() as expected_avatar:
|
with self.local_user.avatar.open() as expected_avatar:
|
||||||
archive_avatar = tar.extractfile(data["icon"]["url"])
|
archive_avatar = tar.extractfile(data["icon"]["url"])
|
||||||
self.assertEqual(expected_avatar.read(), archive_avatar.read())
|
self.assertEqual(expected_avatar.read(), archive_avatar.read())
|
||||||
|
|
||||||
# Edition cover should be present in archive
|
# Edition cover should be present in archive
|
||||||
with self.edition.cover.open() as expected_cover:
|
with self.edition.cover.open() as expected_cover:
|
||||||
archive_cover = tar.extractfile(
|
archive_cover = tar.extractfile(
|
||||||
data["books"][0]["edition"]["cover"]["url"]
|
data["books"][0]["edition"]["cover"]["url"]
|
||||||
)
|
)
|
||||||
self.assertEqual(expected_cover.read(), archive_cover.read())
|
self.assertEqual(expected_cover.read(), archive_cover.read())
|
||||||
|
|
Loading…
Reference in a new issue