Skip to content

Commit

Permalink
Clean up and kitten saving in test code.
Browse files Browse the repository at this point in the history
Replace numbered variables with a list comprehension
Create the product image in one line using .create(**kwags) instead
    of instantiating and then saving.
  • Loading branch information
zsoobhan committed Jul 30, 2014
1 parent 5fcfb90 commit f8e1f8d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
15 changes: 5 additions & 10 deletions oscar/test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,19 @@ 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
else:
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):
Expand Down
22 changes: 6 additions & 16 deletions tests/integration/catalogue/product_image_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f8e1f8d

Please sign in to comment.