From 18a7438dce1cd3e05ec8a28b9465d2f38ecb35fb Mon Sep 17 00:00:00 2001 From: Lars van de Kerkhof Date: Wed, 17 Apr 2024 10:01:42 +0200 Subject: [PATCH] moer query checks --- tests/reverse/test_reallifecase.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/reverse/test_reallifecase.py b/tests/reverse/test_reallifecase.py index c4976e7..5de286c 100644 --- a/tests/reverse/test_reallifecase.py +++ b/tests/reverse/test_reallifecase.py @@ -209,7 +209,7 @@ def test_mapping(self): # Map the csv resources to product resources product_resources = CSVProductMapping.apply(products) - with self.assertNumQueries(10): + with self.assertNumQueries(59 * 4 + 10): # Map the product resources to products and save in DB _, errors = products_to_db(product_resources) self.assertEqual(len(errors), 0) @@ -218,6 +218,22 @@ def test_mapping(self): self.assertEqual(ProductAttributeValue.objects.all().count(), 257) self.assertEqual(ProductImage.objects.all().count(), 52) + + with open(csv_file) as f: + products_2 = csv_codec.reader(f, CSVProductResource, includes_header=True) + + # The seocnd time, the querycount should be lower + product_resources_2 = CSVProductMapping.apply(products_2) + + with self.assertNumQueries(59 + 10): + # Map the product resources to products and save in DB + _, errors = products_to_db(product_resources_2) + self.assertEqual(len(errors), 0) + + self.assertEqual(Product.objects.all().count(), 59) + self.assertEqual(ProductAttributeValue.objects.all().count(), 257) + self.assertEqual(ProductImage.objects.all().count(), 52) + def get_csv_fixture(self, filename): return path.realpath( path.join(