def test_not_discountable_product_fails_condition(self):
     prod1, prod2 = factories.create_product(), factories.create_product()
     prod2.is_discountable = False
     prod2.save()
     add_product(self.basket, product=prod1)
     add_product(self.basket, product=prod2)
     self.assertFalse(self.condition.is_satisfied(self.offer, self.basket))
Exemple #2
0
 def test_dupe_skus_are_available(self):
     product = create_product(partner_sku='123123')
     create_product(partner_sku='123124')
     self.range.add_product(product)
     form = self.submit_form({'query': '123123, 123124'})
     self.assertTrue(form.is_valid())
     self.assertTrue('123123' in form.get_duplicate_skus())
Exemple #3
0
 def setUp(self):
     self.range = models.Range.objects.create(name='Child-specific range',
                                              includes_all_products=False)
     self.parent = create_product(structure='parent')
     self.child1 = create_product(structure='child', parent=self.parent)
     self.child2 = create_product(structure='child', parent=self.parent)
     self.range.add_product(self.child1)
Exemple #4
0
    def test_items_are_flushed_by_importer(self):
        upc = "0000000000000"
        create_product(price=D('10.00'), upc=upc)

        self.importer.handle(TEST_BOOKS_CSV)

        with self.assertRaises(Product.DoesNotExist):
            Product.objects.get(upc=upc)
Exemple #5
0
    def test_select_widget_renders_only_selected_choices(self):
        create_product()
        p2 = create_product()

        field = self._get_form_field()
        form_choices = list(field.widget.options(name='name', value=[p2.pk]))
        # We should only have one choice, not two
        self.assertEqual(len(form_choices), 1)
        self.assertEqual(form_choices[0]['value'], p2.pk)
Exemple #6
0
 def setUp(self):
     self.strategy = strategy.Default()
     parent = factories.create_product(structure='parent')
     factories.create_product(parent=parent,
                              price=D('10.00'),
                              num_in_stock=3)
     for x in range(2):
         factories.create_product(parent=parent)
     self.info = self.strategy.fetch_for_parent(parent)
Exemple #7
0
 def test_can_list_her_products(self):
     product1 = create_product(partner_name="A", partner_users=[self.user])
     product2 = create_product(partner_name="B", partner_users=[])
     page = self.get(reverse('dashboard:catalogue-product-list'))
     products_on_page = [
         row.record for row in page.context['products'].page.object_list
     ]
     self.assertIn(product1, products_on_page)
     self.assertNotIn(product2, products_on_page)
Exemple #8
0
    def test_shows_pagination_navigation_for_multiple_pages(self):
        per_page = settings.IZI_PRODUCTS_PER_PAGE
        title = "Product #%d"
        for idx in range(0, int(1.5 * per_page)):
            create_product(title=title % idx)

        page = self.app.get(reverse('catalogue:index'))

        self.assertContains(page, "Page 1 of 2")
Exemple #9
0
    def test_multiselect_widget_renders_only_selected_choices(self):
        create_product()
        p2 = create_product()
        p3 = create_product()

        field = self._get_multiselect_form_field()
        form_choices = list(
            field.widget.options(name='name', value=[p2.pk, p3.pk]))
        # We should only have two choices, not three
        self.assertEqual(len(form_choices), 2)
Exemple #10
0
    def test_can_delete_a_parent_product(self):
        parent_product = create_product(structure='parent')
        create_product(parent=parent_product)

        url = reverse('dashboard:catalogue-product-delete',
                      args=(parent_product.id, ))
        page = self.get(url).form.submit()

        self.assertRedirects(page, reverse('dashboard:catalogue-product-list'))
        self.assertEqual(Product.objects.count(), 0)
 def setUp(self):
     self.range = models.Range.objects.create(name="All products range",
                                              includes_all_products=True)
     self.basket = factories.create_basket(empty=True)
     self.condition = models.ValueCondition(range=self.range,
                                            type="Value",
                                            value=D('10.00'))
     self.offer = mock.Mock()
     self.item = factories.create_product(price=D('5.00'))
     self.expensive_item = factories.create_product(price=D('15.00'))
Exemple #12
0
    def test_upc_filter(self):
        product1 = create_product(upc='123')
        product2 = create_product(upc='12')
        product3 = create_product(upc='1')

        # no value for upc, all results
        page = self.get("%s?upc=" %
                        reverse('dashboard:catalogue-product-list'))
        products_on_page = [
            row.record for row in page.context['products'].page.object_list
        ]
        self.assertIn(product1, products_on_page)
        self.assertIn(product2, products_on_page)
        self.assertIn(product3, products_on_page)

        # filter by upc, one result
        page = self.get("%s?upc=123" %
                        reverse('dashboard:catalogue-product-list'))
        products_on_page = [
            row.record for row in page.context['products'].page.object_list
        ]
        self.assertIn(product1, products_on_page)
        self.assertNotIn(product2, products_on_page)
        self.assertNotIn(product3, products_on_page)

        # exact match, one result, no multiple
        page = self.get("%s?upc=12" %
                        reverse('dashboard:catalogue-product-list'))
        products_on_page = [
            row.record for row in page.context['products'].page.object_list
        ]
        self.assertNotIn(product1, products_on_page)
        self.assertIn(product2, products_on_page)
        self.assertNotIn(product3, products_on_page)

        # part of the upc, one result
        page = self.get("%s?upc=3" %
                        reverse('dashboard:catalogue-product-list'))
        products_on_page = [
            row.record for row in page.context['products'].page.object_list
        ]
        self.assertIn(product1, products_on_page)
        self.assertNotIn(product2, products_on_page)
        self.assertNotIn(product3, products_on_page)

        # part of the upc, two results
        page = self.get("%s?upc=2" %
                        reverse('dashboard:catalogue-product-list'))
        products_on_page = [
            row.record for row in page.context['products'].page.object_list
        ]
        self.assertIn(product1, products_on_page)
        self.assertIn(product2, products_on_page)
        self.assertNotIn(product3, products_on_page)
Exemple #13
0
    def test_returns_correct_weight_for_nonempty_basket_with_line_quantities(
            self):
        basket = factories.create_basket(empty=True)
        products = [(factories.create_product(attributes={'weight': '1'},
                                              price=D('5.00')), 3),
                    (factories.create_product(attributes={'weight': '2'},
                                              price=D('5.00')), 4)]
        for product, quantity in products:
            basket.add(product, quantity=quantity)

        scale = Scale(attribute_code='weight')
        self.assertEqual(1 * 3 + 2 * 4, scale.weigh_basket(basket))
Exemple #14
0
    def test_can_delete_a_child_product(self):
        parent_product = create_product(structure='parent')
        child_product = create_product(parent=parent_product)

        url = reverse('dashboard:catalogue-product-delete',
                      args=(child_product.id, ))
        page = self.get(url).form.submit()

        expected_url = reverse('dashboard:catalogue-product',
                               kwargs={'pk': parent_product.pk})
        self.assertRedirects(page, expected_url)
        self.assertEqual(Product.objects.count(), 1)
Exemple #15
0
 def setUp(self):
     super().setUp()
     self.range = Range.objects.create(name='dummy')
     self.url = reverse('dashboard:range-products', args=(self.range.id, ))
     self.product1 = create_product(title='Product 1',
                                    partner_sku='123123',
                                    partner_name='Partner 1')
     self.product2 = create_product(title='Product 2',
                                    partner_sku='123123',
                                    partner_name='Partner 2')
     self.product3 = create_product(partner_sku='456')
     self.product4 = create_product(partner_sku='789')
Exemple #16
0
    def test_returns_correct_weight_for_nonempty_basket(self):
        basket = factories.create_basket(empty=True)
        products = [
            factories.create_product(attributes={'weight': '1'},
                                     price=D('5.00')),
            factories.create_product(attributes={'weight': '2'},
                                     price=D('5.00'))
        ]
        for product in products:
            basket.add(product)

        scale = Scale(attribute_code='weight')
        self.assertEqual(1 + 2, scale.weigh_basket(basket))
 def setUp(self):
     self.products = [
         factories.create_product(),
         factories.create_product()
     ]
     self.range = models.Range.objects.create(name="Some products")
     for product in self.products:
         self.range.add_product(product)
         self.range.add_product(product)
     self.basket = factories.create_basket(empty=True)
     self.condition = models.CoverageCondition(range=self.range,
                                               type="Coverage",
                                               value=2)
     self.offer = mock.Mock()
Exemple #18
0
    def test_product_classes_in_all_products(self):
        product_in_included_class = create_product(product_class="123")
        included_product_class = product_in_included_class.product_class
        excluded_product_in_included_class = create_product(
            product_class=included_product_class.name)

        self.range.classes.add(included_product_class)
        self.range.excluded_products.add(excluded_product_in_included_class)

        all_products = self.range.all_products()
        self.assertTrue(product_in_included_class in all_products)
        self.assertTrue(excluded_product_in_included_class not in all_products)

        self.assertEqual(self.range.num_products(), 1)
Exemple #19
0
    def test_shows_not_available_for_out_of_stock_product(self):
        product = create_product(num_in_stock=0)

        page = self.app.get(reverse('catalogue:index'))

        self.assertContains(page, product.title)
        self.assertContains(page, "Unavailable")
Exemple #20
0
 def test_line_quantity_max_attribute_per_basket_threshold(self):
     self.basket.flush()
     product = factories.create_product(num_in_stock=20)
     add_product(self.basket, D('100'), 4, product)
     self.line = self.basket.all_lines()[0]
     form = self.build_form()
     self.assertIn('max="6"', str(form['quantity']))
Exemple #21
0
 def test_applies_correctly_to_basket_with_no_discountable_products(self):
     product = factories.create_product(is_discountable=False)
     add_product(self.basket, D('12.00'), 2, product=product)
     result = self.benefit.apply(self.basket, self.condition, self.offer)
     self.assertEqual(D('0.00'), result.discount)
     self.assertEqual(0, self.basket.num_items_with_discount)
     self.assertEqual(2, self.basket.num_items_without_discount)
Exemple #22
0
    def test_basket_prices_calculation_for_unavailable_pricing(self):
        new_product = factories.create_product()
        factories.create_stockrecord(
            new_product, price_excl_tax=D('5.00'))
        self.basket.add(new_product, 1)

        class UnavailableProductStrategy(strategy.Default):
            """ A test strategy that makes a specific product unavailable """

            def availability_policy(self, product, stockrecord):
                if product == new_product:
                    return availability.Unavailable()
                return super().availability_policy(product, stockrecord)

            def pricing_policy(self, product, stockrecord):
                if product == new_product:
                    return prices.Unavailable()
                return super().pricing_policy(product, stockrecord)

        self.basket.strategy = UnavailableProductStrategy()
        line = self.basket.all_lines()[1]
        self.assertEqual(line.get_warning(), "'D\xf9\uff4d\u03fb\u03d2 title' is no longer available")
        self.assertIsNone(line.line_price_excl_tax)
        self.assertIsNone(line.line_price_incl_tax)
        self.assertIsNone(line.line_price_excl_tax_incl_discounts)
        self.assertIsNone(line.line_price_incl_tax_incl_discounts)
        self.assertIsNone(line.line_tax)
        self.assertEqual(self.basket.total_excl_tax, 100)
        self.assertEqual(self.basket.total_incl_tax, 100)
        self.assertEqual(self.basket.total_excl_tax_excl_discounts, 100)
        self.assertEqual(self.basket.total_incl_tax_excl_discounts, 100)
 def setUp(self):
     self.product = factories.create_product()
     self.stockrecord = factories.create_stockrecord(self.product,
                                                     D('12.00'),
                                                     num_in_stock=5)
     self.basket = factories.create_basket(empty=True)
     add_product(self.basket, product=self.product)
Exemple #24
0
    def test_moving_from_saved_basket_more_than_stocklevel_raises(self):
        self.user = User.objects.create_user(username='******',
                                             password='******',
                                             email='*****@*****.**')
        product = create_product(price=D('10.00'), num_in_stock=1)
        basket, created = Basket.open.get_or_create(owner=self.user)
        add_product(basket, product=product)

        saved_basket, created = Basket.saved.get_or_create(owner=self.user)
        add_product(saved_basket, product=product)

        response = self.get(reverse('basket:summary'))
        saved_formset = response.context['saved_formset']
        saved_form = saved_formset.forms[0]

        data = {
            saved_formset.add_prefix('INITIAL_FORMS'): 1,
            saved_formset.add_prefix('MAX_NUM_FORMS'): 1,
            saved_formset.add_prefix('TOTAL_FORMS'): 1,
            saved_form.add_prefix('id'): saved_form.initial['id'],
            saved_form.add_prefix('move_to_basket'): True,
        }
        response = self.post(reverse('basket:saved'), params=data)
        # we can't add more than stock level into basket
        self.assertEqual(
            Basket.open.get(id=basket.id).lines.get(product=product).quantity,
            1)
        self.assertRedirects(response, reverse('basket:summary'))
Exemple #25
0
    def test_adding_more_than_threshold_raises(self):
        dummy_product = create_product(price=D('10.00'), num_in_stock=10)
        url = reverse('basket:add', kwargs={'pk': dummy_product.pk})
        post_params = {
            'product_id': dummy_product.id,
            'action': 'add',
            'quantity': 2
        }
        response = self.app.post(url, params=post_params)
        self.assertTrue('izi_open_basket' in response.test_app.cookies)
        post_params = {
            'product_id': dummy_product.id,
            'action': 'add',
            'quantity': 2
        }
        response = self.app.post(url, params=post_params)

        expected = gettext(
            "Due to technical limitations we are not able to ship more "
            "than %(threshold)d items in one order. Your basket currently "
            "has %(basket)d items.") % ({
                'threshold': 3,
                'basket': 2
            })
        self.assertTrue(expected in response.test_app.cookies['messages'])
Exemple #26
0
 def test_cant_create_child_product_for_invalid_parents(self):
     # Creates a product with stockrecords.
     invalid_parent = create_product(partner_users=[self.user])
     self.assertFalse(invalid_parent.can_be_parent())
     url = reverse('dashboard:catalogue-product-create-child',
                   kwargs={'parent_pk': invalid_parent.pk})
     self.assertRedirects(self.get(url),
                          reverse('dashboard:catalogue-product-list'))
Exemple #27
0
    def test_can_create_a_child_product(self):
        parent_product = create_product(structure='parent')
        url = reverse('dashboard:catalogue-product-create-child',
                      kwargs={'parent_pk': parent_product.pk})
        form = self.get(url).form
        form.submit()

        self.assertEqual(Product.objects.count(), 2)
Exemple #28
0
 def setUp(self):
     self.basket = Basket()
     self.basket.strategy = strategy.Default()
     self.product = factories.create_product()
     self.record = factories.create_stockrecord(
         self.product, price_excl_tax=D('10.00'))
     self.purchase_info = factories.create_purchase_info(self.record)
     self.basket.add(self.product, 10)
Exemple #29
0
 def test_variant_images_fallback_to_parent(self):
     parent = factories.ProductFactory(structure='parent')
     variant = factories.create_product(parent=parent)
     factories.create_product_image(product=parent, caption='Parent Product Image')
     all_images = variant.get_all_images()
     self.assertEquals(all_images.count(), 1)
     product_image = all_images.first()
     self.assertEquals(product_image.caption, 'Parent Product Image')
Exemple #30
0
    def test_enforces_canonical_url(self):
        p = create_product()
        kwargs = {'product_slug': '1_wrong-but-valid-slug_1', 'pk': p.id}
        wrong_url = reverse('catalogue:detail', kwargs=kwargs)

        response = self.app.get(wrong_url)
        self.assertEqual(http_client.MOVED_PERMANENTLY, response.status_code)
        self.assertTrue(p.get_absolute_url() in response.location)