コード例 #1
0
 def setUp(self):
     super(ValueConditionTest, self).setUp()
     self.condition = models.ValueCondition(range=self.range, type="Value", value=D("10.00"))
     self.offer = mock.Mock()
     self.offer.applies_to_tax_exclusive_prices = False
     self.item = factories.create_product(price=D("5.00"))
     self.expensive_item = factories.create_product(price=D("15.00"))
コード例 #2
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)
コード例 #3
0
    def test_weight_calculation_of_basket(self):
        basket = Basket()
        basket.add_product(create_product(attributes={'weight': '1'}))
        basket.add_product(create_product(attributes={'weight': '2'}))

        scales = Scales(attribute_code='weight')
        self.assertEquals(1+2, scales.weigh_basket(basket))
コード例 #4
0
    def test_weight_calculation_of_basket_with_line_quantity(self):
        basket = Basket()
        basket.add_product(create_product(attributes={'weight': 1}), quantity=3)
        basket.add_product(create_product(attributes={'weight': 2}), quantity=4)

        scales = Scales(attribute_code='weight')
        self.assertEquals(1*3+2*4, scales.weigh_basket(basket))
コード例 #5
0
 def setUp(self):
     super(ValueConditionTest, self).setUp()
     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'))
コード例 #6
0
 def test_dupe_skus_are_available(self):
     product = create_product(partner_sku='123123')
     create_product(partner_sku='123124')
     self.range.included_products.add(product)
     form = self.submit_form({'query': '123123, 123124'})
     self.assertTrue(form.is_valid())
     self.assertTrue('123123' in form.get_duplicate_skus())
コード例 #7
0
ファイル: catalogue_tests.py プロジェクト: MrReN/django-oscar
    def test_can_delete_a_canonical_product(self):
        canonical_product = create_product(title="Canonical Product",
                                           partner_users=[self.user,])

        product = create_product(title="Variant 1", parent=canonical_product)
        stockrecord = create_stockrecord(product)

        category = Category.add_root(name='Test Category')
        product_category = ProductCategory.objects.create(
            category=category, product=product)

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

        self.assertRedirects(page, reverse('dashboard:catalogue-product-list'))

        self.assertEqual(Product.objects.count(), 0)
        self.assertEqual(StockRecord.objects.count(), 0)
        self.assertEqual(ProductCategory.objects.count(), 0)

        self.assertRaises(Product.DoesNotExist,
                          Product.objects.get, id=canonical_product.id)

        self.assertRaises(Product.DoesNotExist,
                          Product.objects.get, id=product.id)
        self.assertRaises(StockRecord.DoesNotExist,
                          StockRecord.objects.get, id=stockrecord.id)
        self.assertRaises(ProductCategory.DoesNotExist,
                          ProductCategory.objects.get, id=product_category.id)
コード例 #8
0
 def test_not_discountable_product_fails_condition(self):
     prod1, prod2 = create_product(), create_product()
     prod2.is_discountable = False
     prod2.save()
     self.basket.add_product(prod1)
     self.basket.add_product(prod2)
     self.assertFalse(self.condition.is_satisfied(self.basket))
コード例 #9
0
 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.basket))
コード例 #10
0
 def test_applies_correctly_to_basket_which_exceeds_condition_with_smaller_prices_than_discount_and_higher_prices_first(self):
     for product in [create_product(price=D('4.00')),
                     create_product(price=D('2.00'))]:
         self.basket.add_product(product, 2)
     result = self.benefit.apply(self.basket, self.condition)
     self.assertEqual(D('3.00'), result.discount)
     self.assertEqual(4, self.basket.num_items_with_discount)
     self.assertEqual(0, self.basket.num_items_without_discount)
コード例 #11
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)
コード例 #12
0
 def test_can_list_her_products(self):
     product1 = create_product(partner_users=[self.user, ])
     product2 = create_product(partner_name="sneaky", partner_users=[])
     page = self.get(reverse('dashboard:catalogue-product-list'))
     products_on_page = [row.record for row
                         in page.context['products'].page.object_list]
     assert product1 in products_on_page
     assert product2 in products_on_page
コード例 #13
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)
コード例 #14
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)
コード例 #15
0
 def test_applies_correctly_to_basket_which_exceeds_condition(self):
     for product in [create_product(price=D('4.00')),
                     create_product(price=D('2.00'))]:
         self.basket.add_product(product, 2)
     result = self.benefit.apply(self.basket, self.condition)
     self.assertEqual(D('2.00'), result.discount)
     self.assertEqual(3, self.basket.num_items_with_discount)
     self.assertEqual(1, self.basket.num_items_without_discount)
コード例 #16
0
    def test_shows_pagination_navigation_for_multiple_pages(self):
        per_page = ProductListView.paginate_by
        title = u"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")
コード例 #17
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)
コード例 #18
0
 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.included_products.add(product)
         self.range.included_products.add(product)
     self.basket = factories.create_basket(empty=True)
     self.condition = models.CoverageCondition(
         range=self.range, type="Coverage", value=2)
コード例 #19
0
 def test_applies_correctly_to_basket_which_exceeds_condition(self):
     for product in [create_product(price=D('12.00')),
                     create_product(price=D('20.00'))]:
         self.basket.add_product(product, 2)
     result = self.benefit.apply(self.basket, self.condition)
     self.assertEqual(1 * D('12.00') * D('0.2'), result.discount)
     # Should only consume the condition products
     self.assertEqual(2, self.basket.num_items_with_discount)
     self.assertEqual(2, self.basket.num_items_without_discount)
コード例 #20
0
ファイル: test_condition.py プロジェクト: aibon/django-oscar
 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'))
コード例 #21
0
    def test_shows_pagination_navigation_for_multiple_pages(self):
        per_page = settings.OSCAR_PRODUCTS_PER_PAGE
        title = u"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")
コード例 #22
0
    def setUp(self):
        self.products = [create_product(Decimal('5.00')), create_product(Decimal('10.00'))]
        self.range = models.Range.objects.create(name="Some products")
        for product in self.products:
            self.range.included_products.add(product)
            self.range.included_products.add(product)

        self.basket = Basket.objects.create()
        self.condition = models.CoverageCondition(range=self.range, type="Coverage", value=2)
コード例 #23
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)
コード例 #24
0
 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()
     self.offer.applies_to_tax_exclusive_prices = False
コード例 #25
0
 def test_not_discountable_product_fails_condition(
     self, count_condition, empty_basket
 ):
     basket = empty_basket
     prod1, prod2 = factories.create_product(), factories.create_product()
     prod2.is_discountable = False
     prod2.save()
     add_product(basket, product=prod1)
     add_product(basket, product=prod2)
     assert count_condition.is_satisfied(self.offer, basket) is False
コード例 #26
0
    def test_consumes_correct_number_of_products_for_4_product_basket(self):
        basket = G(Basket)
        for product in [create_product(), create_product()]:
            basket.add_product(product, 2)

        self.assertTrue(self.offer.is_condition_satisfied(basket))
        discount = self.offer.apply_benefit(basket)
        self.assertTrue(discount > 0)
        self.assertEqual(3, basket.num_items_with_discount)
        self.assertEqual(1, basket.num_items_without_discount)
        self.assertFalse(self.offer.is_condition_satisfied(basket))
コード例 #27
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))
コード例 #28
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)
コード例 #29
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))
コード例 #30
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))
コード例 #31
0
 def setUp(self):
     self.product = create_product()
     self.user = User.objects.create_user(username=self.username,
                                          email=self.email,
                                          password=self.password)
コード例 #32
0
ファイル: test_alert.py プロジェクト: zyyettie/django-oscar
 def setUp(self):
     self.user = UserFactory()
     self.product = create_product()
コード例 #33
0
 def test_weighs_uses_specified_attribute(self):
     scale = Scale(attribute_code='weight')
     p = factories.create_product(attributes={'weight': '1'})
     self.assertEqual(1, scale.weigh_product(p))
コード例 #34
0
 def test_total_sums_product_totals(self):
     product = factories.create_product()
     factories.create_stockrecord(product, price_excl_tax=D('5.00'))
     self.basket.add(product, 1)
     self.assertEqual(self.basket.total_excl_tax, 105)
コード例 #35
0
 def setUp(self):
     self.range = models.Range.objects.create(name="All products",
                                              includes_all_products=False)
     self.parent = create_product(structure='parent')
     self.child = create_product(structure='child', parent=self.parent)
コード例 #36
0
ファイル: 17212_test_catalogue.py プロジェクト: dslika/Oscar
 def test_shows_add_to_basket_button_for_available_product(self):
     product = create_product(num_in_stock=1)
     page = self.app.get(reverse('catalogue:index'))
     self.assertContains(page, product.title)
     self.assertContains(page, ugettext("Add to basket"))
コード例 #37
0
 def setUp(self):
     super(TestHiddenFeatures, self).setUp()
     self.product = create_product()
     self.wishlists_url = reverse('customer:wishlists-list')
コード例 #38
0
ファイル: test_alert.py プロジェクト: zyyettie/django-oscar
 def setUp(self):
     self.user = UserFactory()
     self.product = create_product()
     create_stockrecord(self.product, num_in_stock=1)
コード例 #39
0
 def test_not_discountable_item_fails_condition(self):
     product = factories.create_product(is_discountable=False)
     add_product(self.basket, D("15"), product=product)
     assert self.condition.is_satisfied(self.offer, self.basket) is False
コード例 #40
0
 def setUp(self):
     self.client = Client()
     self.product = create_product()
コード例 #41
0
 def test_uses_default_weight_when_attribute_is_missing(self):
     scale = Scale(attribute_code='weight', default_weight=0.5)
     p = factories.create_product()
     self.assertEqual(0.5, scale.weigh_product(p))
コード例 #42
0
 def test_wrapper_availability_gets_called(self):
     product = factories.create_product(price=D('10.00'),
                                        partner="Acme",
                                        num_in_stock=10)
     stockrecord = product.stockrecords.all()[0]
     self.assertEquals(u"Dummy response", unicode(stockrecord.availability))
コード例 #43
0
 def add_product_to_basket(self):
     product = create_product(price=D('12.00'))
     self.client.post(reverse('basket:add'), {'product_id': product.id,
                                              'quantity': 1})
コード例 #44
0
 def test_all_products_includes_child_products(self):
     child_product = create_product(structure='child', parent=self.prod)
     self.assertTrue(child_product in self.range.all_products())
コード例 #45
0
 def setUp(self):
     self.range = models.Range.objects.create(name="All products",
                                              includes_all_products=True)
     self.prod = create_product()
コード例 #46
0
 def test_cant_create_a_child_product(self):
     parent_product = create_product(structure='parent')
     url = reverse('dashboard:catalogue-product-create-child',
                   kwargs={'parent_pk': parent_product.pk})
     response = self.get(url, status='*')
     self.assertEqual(http_client.FORBIDDEN, response.status_code)
コード例 #47
0
 def setUp(self, empty_basket, value_condition, mock_offer):
     self.basket = empty_basket
     self.condition = value_condition
     self.offer = mock_offer
     self.item = factories.create_product(price=D("5.00"))
     self.expensive_item = factories.create_product(price=D("15.00"))
コード例 #48
0
 def setUp(self):
     self.request = RequestFactory().get('/')
     self.product = factories.create_product(num_in_stock=10)
     self.stock_record = self.product.stockrecords.first()
コード例 #49
0
 def setUp(self):
     super().setUp()
     self.product = create_product()
     self.wishlists_url = reverse('customer:wishlists-list')
コード例 #50
0
ファイル: test_alert.py プロジェクト: zyyettie/django-oscar
 def setUp(self):
     self.user = UserFactory()
     self.product = create_product(num_in_stock=0)
コード例 #51
0
 def test_wrapper_dispatch_date_gets_called(self):
     product = factories.create_product(price=D('10.00'),
                                        partner="Acme",
                                        num_in_stock=10)
     stockrecord = product.stockrecords.all()[0]
     self.assertEquals("Another dummy response", stockrecord.dispatch_date)
コード例 #52
0
 def test_returns_zero_line_quantity_for_missing_product_and_stockrecord(
         self):
     product = factories.create_product()
     record = factories.create_stockrecord(product,
                                           price_excl_tax=D('5.00'))
     self.assertEqual(0, self.basket.line_quantity(product, record))
コード例 #53
0
def products_some():
    return [factories.create_product(), factories.create_product()]
コード例 #54
0
 def test_raises_exception_when_attribute_is_missing(self):
     scale = Scale(attribute_code='weight')
     p = factories.create_product()
     with self.assertRaises(ValueError):
         scale.weigh_product(p)
コード例 #55
0
 def setUp(self):
     self.product = factories.create_product()
     self.stockrecord = factories.create_stockrecord(
         self.product, price_excl_tax=D('10.00'), num_in_stock=10)
コード例 #56
0
 def setUp(self):
     self.product = create_product()