diff --git a/oscar/test/factories.py b/oscar/test/factories.py index 620f8ee924b..7562e9d1f19 100644 --- a/oscar/test/factories.py +++ b/oscar/test/factories.py @@ -102,8 +102,6 @@ def create_product_image(product=None, ): if not product: product = create_product() - if not original: - original = None # FIXME change? if not display_order: if not product.images.all(): display_order = 0 @@ -111,15 +109,12 @@ def create_product_image(product=None, display_order = max( [i.display_order for i in product.images.all()])+1 - i_kwargs = {'product_id': product.id, - 'original': original, - 'display_order': display_order, - 'caption': caption, } + kwargs = {'product_id': product.id, + 'original': original, + 'display_order': display_order, + 'caption': caption, } - product_image = ProductImage(**i_kwargs) - product_image.save() - - return product_image + return ProductImage.objects.create(**kwargs) def create_basket(empty=False): diff --git a/tests/integration/catalogue/product_image_tests.py b/tests/integration/catalogue/product_image_tests.py index 43783a54733..75075f1e11e 100644 --- a/tests/integration/catalogue/product_image_tests.py +++ b/tests/integration/catalogue/product_image_tests.py @@ -5,22 +5,12 @@ class TestProductImages(TestCase): - def setUp(self): - self.product = factories.create_product() - self.im_1 = factories.create_product_image(product=self.product, - display_order=0) - self.im_2 = factories.create_product_image(product=self.product, - display_order=1) - self.im_3 = factories.create_product_image(product=self.product, - display_order=2) - self.im_4 = factories.create_product_image(product=self.product, - display_order=3) - - def tearDown(self): - self.product.delete() - def test_images_are_in_consecutive_order(self): - self.product.images.all()[2].delete() + product = factories.create_product() + images = [factories.create_product_image( + product=product, display_order=i) for i in range(4)] + + product.images.all()[2].delete() - for idx, im in enumerate(self.product.images.all()): + for idx, im in enumerate(product.images.all()): self.assertEqual(im.display_order, idx)