def test_listing_bulk_creation_correctly_checks_listings(self): """ There may be some listing with more than one product with quantity 1. Test that the method listing_bulk_creation doesn't consider these listings as 1xlistings """ # turn off automatic listing creation on product creation old_setting_value = bazaar_settings.AUTOMATIC_LISTING_CREATION_ON_PRODUCT_CREATION bazaar_settings.AUTOMATIC_LISTING_CREATION_ON_PRODUCT_CREATION = False self.assertEqual(Listing.objects.all().count(), 0) # create a listing with 2 products composite = CompositeProductFactory() ProductSetFactory(product=ProductFactory(), composite=composite, quantity=1) ProductSetFactory(product=ProductFactory(), composite=composite, quantity=1) ListingFactory(product=composite) self.assertEqual(Listing.objects.all().count(), 1) listing_bulk_creation(Product.objects.all()) self.assertEqual(Listing.objects.all().count(), 3) bazaar_settings.AUTOMATIC_LISTING_CREATION_ON_PRODUCT_CREATION = old_setting_value
def create_listing_for_product(sender, instance, **kwargs): if not bazaar_settings.AUTOMATIC_LISTING_CREATION_ON_PRODUCT_CREATION: return if not kwargs['created']: return if hasattr(instance, 'compositeproduct'): return # TODO: Is needed here? from bazaar.goods.api import listing_bulk_creation listing_bulk_creation(Product.objects.filter(pk=instance.id).all())
def test_listing_bulk_creation_with_product_that_has_no_listing(self): """ Test that the method does create a 1xlisting for every product passed in """ # turn off automatic listing creation on product creation old_setting_value = bazaar_settings.AUTOMATIC_LISTING_CREATION_ON_PRODUCT_CREATION bazaar_settings.AUTOMATIC_LISTING_CREATION_ON_PRODUCT_CREATION = False # create product with no associated 1xlisting product = ProductFactory() self.assertEqual(Listing.objects.all().count(), 0) listing_bulk_creation(Product.objects.all()) self.assertEqual(Listing.objects.all().count(), 1) self.assertEqual(Listing.objects.first().product, product) bazaar_settings.AUTOMATIC_LISTING_CREATION_ON_PRODUCT_CREATION = old_setting_value
def test_listing_bulk_creation_with_product_that_already_have_a_listing(self): """ Test that the method does not create any extra 1xlisting, since the products that are passed as parameters already have an associated 1xlisting """ # turn on automatic listing creation on product creation old_setting_value = bazaar_settings.AUTOMATIC_LISTING_CREATION_ON_PRODUCT_CREATION bazaar_settings.AUTOMATIC_LISTING_CREATION_ON_PRODUCT_CREATION = True # create 3 products with 1xlisting ProductFactory() ProductFactory() ProductFactory() self.assertEqual(Listing.objects.all().count(), 3) listing_bulk_creation(Product.objects.all()) self.assertEqual(Listing.objects.all().count(), 3) bazaar_settings.AUTOMATIC_LISTING_CREATION_ON_PRODUCT_CREATION = old_setting_value