Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix issue with required attributes creating a product

  • Loading branch information...
commit 01519420abb2e66911c2b133b2d2840041dd2898 1 parent bdb5497
@elbaschid elbaschid authored codeinthehole committed
Showing with 8 additions and 9 deletions.
  1. +8 −9 oscar_testsupport/factories.py
View
17 oscar_testsupport/factories.py
@@ -35,8 +35,14 @@ def create_product(price=None, title=u"Dummy title",
Helper method for creating products that are used in tests.
"""
ic, __ = ProductClass._default_manager.get_or_create(name=product_class)
- item = Product._default_manager.create(title=title, product_class=ic,
- upc=upc, **kwargs)
+ item = Product(title=title, product_class=ic, upc=upc, **kwargs)
+
+ if attributes:
+ for key, value in attributes.items():
+ setattr(item.attr, key, value)
+
+ item.save()
+
if price is not None or partner_sku or num_in_stock is not None:
if not partner_sku:
partner_sku = 'sku_%d_%d' % (item.id, random.randint(0, 10000))
@@ -48,13 +54,6 @@ def create_product(price=None, title=u"Dummy title",
partner_sku=partner_sku,
price_excl_tax=price,
num_in_stock=num_in_stock)
- if attributes:
- for key, value in attributes.items():
- attr, __ = ProductAttribute.objects.get_or_create(
- name=key, code=key)
- ProductAttributeValue.objects.create(
- product=item, attribute=attr, value=value)
-
return item
Please sign in to comment.
Something went wrong with that request. Please try again.