From 9f5ca7ae602b51075bc9f0c3269c910616b807fa Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 25 Aug 2024 17:53:43 -0700 Subject: [PATCH 1/2] Uses workaround for test that fails ~sometimes~ --- bookwyrm/tests/importers/test_importer.py | 39 ++++++++++++----------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/bookwyrm/tests/importers/test_importer.py b/bookwyrm/tests/importers/test_importer.py index da2e1b3d8..8abe7a223 100644 --- a/bookwyrm/tests/importers/test_importer.py +++ b/bookwyrm/tests/importers/test_importer.py @@ -65,25 +65,28 @@ class GenericImporter(TestCase): import_items = models.ImportItem.objects.filter(job=import_job).all() self.assertEqual(len(import_items), 4) - self.assertEqual(import_items[0].index, 0) - self.assertEqual(import_items[0].normalized_data["id"], "38") - self.assertEqual(import_items[0].normalized_data["title"], "Gideon the Ninth") - self.assertEqual(import_items[0].normalized_data["authors"], "Tamsyn Muir") - self.assertEqual(import_items[0].normalized_data["isbn_13"], "9781250313195") - self.assertIsNone(import_items[0].normalized_data["isbn_10"]) - self.assertEqual(import_items[0].normalized_data["shelf"], "read") - self.assertEqual(import_items[1].index, 1) - self.assertEqual(import_items[1].normalized_data["id"], "48") - self.assertEqual(import_items[1].normalized_data["title"], "Harrow the Ninth") - - self.assertEqual(import_items[2].index, 2) - self.assertEqual(import_items[2].normalized_data["id"], "23") - self.assertEqual(import_items[2].normalized_data["title"], "Subcutanean") - - self.assertEqual(import_items[3].index, 3) - self.assertEqual(import_items[3].normalized_data["id"], "10") - self.assertEqual(import_items[3].normalized_data["title"], "Patisserie at Home") + # items don't get added in a predictable order, so we're using this weird loop + for item in import_items: + if item.index == 0: + self.assertEqual(item.normalized_data["id"], "38") + self.assertEqual(item.normalized_data["title"], "Gideon the Ninth") + self.assertEqual(item.normalized_data["authors"], "Tamsyn Muir") + self.assertEqual(item.normalized_data["isbn_13"], "9781250313195") + self.assertIsNone(item.normalized_data["isbn_10"]) + self.assertEqual(item.normalized_data["shelf"], "read") + elif item.index == 1: + self.assertEqual(item.index, 1) + self.assertEqual(item.normalized_data["id"], "48") + self.assertEqual(item.normalized_data["title"], "Harrow the Ninth") + elif item.index == 2: + self.assertEqual(item.index, 2) + self.assertEqual(item.normalized_data["id"], "23") + self.assertEqual(item.normalized_data["title"], "Subcutanean") + elif item.index == 3: + self.assertEqual(item.index, 3) + self.assertEqual(item.normalized_data["id"], "10") + self.assertEqual(item.normalized_data["title"], "Patisserie at Home") def test_create_retry_job(self, *_): """trying again with items that didn't import""" From bd773f41c7818099b071b601506b9b46ce7a9393 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 26 Aug 2024 11:33:01 -0700 Subject: [PATCH 2/2] Uses much simpler approach to ensuring test result order --- bookwyrm/tests/importers/test_importer.py | 43 +++++++++++------------ 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/bookwyrm/tests/importers/test_importer.py b/bookwyrm/tests/importers/test_importer.py index 8abe7a223..31e01d96a 100644 --- a/bookwyrm/tests/importers/test_importer.py +++ b/bookwyrm/tests/importers/test_importer.py @@ -63,30 +63,29 @@ class GenericImporter(TestCase): self.assertEqual(import_job.include_reviews, False) self.assertEqual(import_job.privacy, "public") - import_items = models.ImportItem.objects.filter(job=import_job).all() + import_items = ( + models.ImportItem.objects.filter(job=import_job).all().order_by("id") + ) self.assertEqual(len(import_items), 4) + self.assertEqual(import_items[0].index, 0) + self.assertEqual(import_items[0].normalized_data["id"], "38") + self.assertEqual(import_items[0].normalized_data["title"], "Gideon the Ninth") + self.assertEqual(import_items[0].normalized_data["authors"], "Tamsyn Muir") + self.assertEqual(import_items[0].normalized_data["isbn_13"], "9781250313195") + self.assertIsNone(import_items[0].normalized_data["isbn_10"]) + self.assertEqual(import_items[0].normalized_data["shelf"], "read") - # items don't get added in a predictable order, so we're using this weird loop - for item in import_items: - if item.index == 0: - self.assertEqual(item.normalized_data["id"], "38") - self.assertEqual(item.normalized_data["title"], "Gideon the Ninth") - self.assertEqual(item.normalized_data["authors"], "Tamsyn Muir") - self.assertEqual(item.normalized_data["isbn_13"], "9781250313195") - self.assertIsNone(item.normalized_data["isbn_10"]) - self.assertEqual(item.normalized_data["shelf"], "read") - elif item.index == 1: - self.assertEqual(item.index, 1) - self.assertEqual(item.normalized_data["id"], "48") - self.assertEqual(item.normalized_data["title"], "Harrow the Ninth") - elif item.index == 2: - self.assertEqual(item.index, 2) - self.assertEqual(item.normalized_data["id"], "23") - self.assertEqual(item.normalized_data["title"], "Subcutanean") - elif item.index == 3: - self.assertEqual(item.index, 3) - self.assertEqual(item.normalized_data["id"], "10") - self.assertEqual(item.normalized_data["title"], "Patisserie at Home") + self.assertEqual(import_items[1].index, 1) + self.assertEqual(import_items[1].normalized_data["id"], "48") + self.assertEqual(import_items[1].normalized_data["title"], "Harrow the Ninth") + + self.assertEqual(import_items[2].index, 2) + self.assertEqual(import_items[2].normalized_data["id"], "23") + self.assertEqual(import_items[2].normalized_data["title"], "Subcutanean") + + self.assertEqual(import_items[3].index, 3) + self.assertEqual(import_items[3].normalized_data["id"], "10") + self.assertEqual(import_items[3].normalized_data["title"], "Patisserie at Home") def test_create_retry_job(self, *_): """trying again with items that didn't import"""