mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-02-17 03:25:19 +00:00
Adds test and fixes logic errors
This commit is contained in:
parent
eee4e30e25
commit
8b88de624d
2 changed files with 14 additions and 4 deletions
|
@ -393,10 +393,10 @@ class Edition(Book):
|
||||||
existing_match = model.find_existing(data)
|
existing_match = model.find_existing(data)
|
||||||
|
|
||||||
# assign this edition to the parent of the duplicate edition
|
# assign this edition to the parent of the duplicate edition
|
||||||
new_work = existing_match.parent_work
|
if existing_match and existing_match.parent_work:
|
||||||
# if not, create a new work for it
|
new_work = existing_match.parent_work
|
||||||
if not new_work:
|
else:
|
||||||
new_work = models.Work.objects.create(title=self.title)
|
new_work = Work.objects.create(title=self.title)
|
||||||
|
|
||||||
self.parent_work = new_work
|
self.parent_work = new_work
|
||||||
self.save(update_fields=["parent_work"], broadcast=False)
|
self.save(update_fields=["parent_work"], broadcast=False)
|
||||||
|
|
|
@ -143,3 +143,13 @@ class Book(TestCase):
|
||||||
for article in articles
|
for article in articles
|
||||||
)
|
)
|
||||||
self.assertTrue(all(book.sort_title == "test edition" for book in books))
|
self.assertTrue(all(book.sort_title == "test edition" for book in books))
|
||||||
|
|
||||||
|
def test_repair_edition(self):
|
||||||
|
"""Fix editions with no works"""
|
||||||
|
edition = models.Edition.objects.create(title="test")
|
||||||
|
self.assertIsNone(edition.parent_work)
|
||||||
|
|
||||||
|
edition.repair()
|
||||||
|
edition.refresh_from_db()
|
||||||
|
|
||||||
|
self.assertEqual(edition.parent_work.title, "test")
|
||||||
|
|
Loading…
Reference in a new issue