Exemplo n.º 1
0
    def test_correctly_allocates_stock(self):
        factories.create_order(basket=self.basket)

        record = StockRecord.objects.get(product=self.product)
        self.assertEqual(5, record.num_in_stock)
        self.assertEqual(1, record.num_allocated)
        self.assertEqual(4, record.net_stock_level)
Exemplo n.º 2
0
 def test_downloads_to_csv_without_error(self):
     address = ShippingAddressFactory()
     create_order(shipping_address=address)
     page = self.get(reverse('dashboard:order-list'))
     form = page.forms['orders_form']
     form['selected_order'].checked = True
     form.submit('download_selected')
Exemplo n.º 3
0
    def test_only_raises_an_alert_once(self):
        self.set_threshold(5)
        StockAlert.objects.create(stockrecord=self.stockrecord, threshold=10)
        factories.create_order(basket=self.basket)

        alerts = StockAlert.objects.filter(stockrecord=self.stockrecord)
        self.assertEqual(1, len(alerts))
Exemplo n.º 4
0
 def setUp(self):
     self.order = factories.create_order()
     self.handler = EventHandler()
     basket = factories.create_basket(empty=True)
     add_product(basket, D('10.00'), 5)
     self.order = factories.create_order(basket=basket)
     self.settled = models.PaymentEventType.objects.create(name='Settled')
Exemplo n.º 5
0
    def test_includes_hourly_report_with_orders(self):
        create_order(
            total=prices.Price('GBP', excl_tax=D('34.05'), tax=D('0.00')))
        create_order(
            total=prices.Price('GBP', excl_tax=D('21.90'), tax=D('0.00')))
        report = IndexView().get_hourly_report()

        self.assertEqual(len(report['order_total_hourly']), 12)
        self.assertEqual(len(report['y_range']), 11)
        self.assertEqual(report['max_revenue'], D('60'))
Exemplo n.º 6
0
    def test_closes_open_alert(self):
        # Set threshold as same as current level
        self.set_threshold(5)
        factories.create_order(basket=self.basket)

        alert = StockAlert.objects.get(stockrecord=self.stockrecord)
        self.assertEqual(StockAlert.OPEN, alert.status)

        # Restock product
        self.stockrecord.num_in_stock = 15
        self.stockrecord.save()

        alert = StockAlert.objects.get(stockrecord=self.stockrecord)
        self.assertEqual(StockAlert.CLOSED, alert.status)
        self.assertIsNotNone(alert.date_closed)
Exemplo n.º 7
0
 def test_redirects_to_detail_page(self):
     order = create_order()
     page = self.get(reverse('dashboard:order-list'))
     form = page.forms['search_form']
     form['order_number'] = order.number
     response = form.submit()
     self.assertEqual(http_client.FOUND, response.status_code)
Exemplo n.º 8
0
 def test_can_be_created_with_a_voucher(self):
     voucher = create_voucher()
     order = create_order(number='100002')
     discount = OrderDiscount.objects.create(order=order, amount=D('10.00'),
                                             voucher_id=voucher.id)
     self.assertEqual(voucher.id, discount.voucher.id)
     self.assertEqual(voucher.code, discount.voucher_code)
Exemplo n.º 9
0
 def test_can_be_created_with_an_offer(self):
     offer = create_offer()
     order = create_order(number='100002')
     discount = OrderDiscount.objects.create(order=order, amount=D('10.00'),
                                             offer_id=offer.id)
     self.assertEqual(offer.id, discount.offer.id)
     self.assertEqual(offer.name, discount.offer_name)
Exemplo n.º 10
0
 def test_gets_404_when_using_incorrect_hash(self):
     order = create_order()
     path = reverse('customer:anon-order',
                    kwargs={'order_number': order.number,
                            'hash': 'bad'})
     response = self.app.get(path, status="*")
     self.assertEqual(http_client.NOT_FOUND, response.status_code)
Exemplo n.º 11
0
 def setUp(self):
     Line.pipeline = {'A': ('B', 'C'),
                      'B': ('C',)}
     self.order = create_order()
     self.line = self.order.lines.all()[0]
     self.line.status = 'A'
     self.line.save()
Exemplo n.º 12
0
 def test_can_see_order_status(self):
     order = create_order()
     path = reverse('customer:anon-order',
                    kwargs={'order_number': order.number,
                            'hash': order.verification_hash()})
     response = self.app.get(path)
     self.assertEqual(http_client.OK, response.status_code)
Exemplo n.º 13
0
    def test_allows_date_placed_to_be_changed_and_set_explicitly(self):
        order = create_order(number='100003')
        tzinfo = timezone.get_current_timezone()
        order.date_placed = datetime(2012, 8, 11, 16, 14, tzinfo=tzinfo)
        order.save()

        self.assertEqual(order.date_placed, datetime(2012, 8, 11, 16, 14, tzinfo=tzinfo))
Exemplo n.º 14
0
 def setUp(self):
     super().setUp()
     # ensures that initial statuses are as expected
     self.order = create_order()
     self.event_type = PaymentEventType.objects.create(name='foo')
     url = reverse('dashboard:order-detail',
                   kwargs={'number': self.order.number})
     self.page = self.get(url)
Exemplo n.º 15
0
 def test_can_be_created_with_an_offer_and_specified_offer_name(self):
     offer = create_offer(name="My offer")
     order = create_order(number='100002')
     discount = OrderDiscount.objects.create(order=order, amount=D('10.00'),
                                             offer_id=offer.id,
                                             offer_name="Your offer")
     self.assertEqual(offer.id, discount.offer.id)
     self.assertEqual("Your offer", discount.offer_name)
Exemplo n.º 16
0
    def test_can_be_created_without_offer_or_voucher(self):
        order = create_order(number='100002')
        discount = OrderDiscount.objects.create(order=order, amount=D('10.00'))

        self.assertTrue(discount.voucher is None)
        self.assertTrue(discount.offer is None)

        self.assertEqual(discount.description(), '')
Exemplo n.º 17
0
 def test_can_be_created_with_a_voucher_and_specidied_voucher_code(self):
     voucher = create_voucher()
     order = create_order(number='100002')
     discount = OrderDiscount.objects.create(order=order, amount=D('10.00'),
                                             voucher_id=voucher.id,
                                             voucher_code="anothercode")
     self.assertEqual(voucher.id, discount.voucher.id)
     self.assertEqual('anothercode', discount.voucher_code)
Exemplo n.º 18
0
 def setUp(self):
     self.order = create_order()
     self.line = self.order.lines.all()[0]
     self.url = reverse('dashboard:order-line-detail',
                        kwargs={
                            'number': self.order.number,
                            'line_id': self.line.id
                        })
     super().setUp()
Exemplo n.º 19
0
    def setUp(self):
        super().setUp()
        self.user = UserFactory()
        self.order = create_order(number='000042', user=self.user)

        LegalEntityAddressFactory(
            legal_entity=LegalEntityFactory(),
            country=CountryFactory(),
        )
Exemplo n.º 20
0
    def setUp(self):
        """
        Creates two orders. order_in has self.user in it's partner users list.
        """
        super().setUp()
        self.address = ShippingAddressFactory()
        self.basket_in = create_basket()
        self.basket_out = create_basket()
        # replace partner with one that has the user in it's users list
        self.partner_in = PartnerFactory(users=[self.user])
        stockrecord = self.basket_in.lines.all()[0].stockrecord
        stockrecord.partner = self.partner_in
        stockrecord.save()

        self.order_in = create_order(basket=self.basket_in,
                                     shipping_address=self.address)
        self.order_out = create_order(basket=self.basket_out,
                                      shipping_address=self.address)
Exemplo n.º 21
0
 def setUp(self):
     basket = create_basket(empty=True)
     add_product(basket, D('10.00'), 4)
     self.order = create_order(number='100002', basket=basket)
     self.line = self.order.lines.all()[0]
     self.order_placed, __ = ShippingEventType.objects.get_or_create(
         code='order_placed', name='Order placed')
     self.dispatched, __ = ShippingEventType.objects.get_or_create(
         code='dispatched', name='Dispatched')
Exemplo n.º 22
0
    def setUp(self):
        basket = create_basket(empty=True)
        add_product(basket, D('10.00'), 4)
        self.order = create_order(number='100002', basket=basket)
        self.line = self.order.lines.all()[0]

        self.shipped, __ = ShippingEventType.objects.get_or_create(
            name='Shipped')
        self.returned, __ = ShippingEventType.objects.get_or_create(
            name='Returned')
Exemplo n.º 23
0
    def test_contains_offer_details_after_offer_is_deleted(self):
        offer = create_offer(name="Get 200% off")
        order = create_order(number='100002')
        discount = OrderDiscount.objects.create(order=order, amount=D('10.00'),
                                                offer_id=offer.id)
        offer.delete()

        self.assertTrue(discount.voucher is None)
        self.assertTrue(discount.offer is None)

        self.assertEqual(discount.description(), 'Get 200% off')
Exemplo n.º 24
0
    def test_has_discount_recorded_correctly_when_order_is_placed(self):
        order = factories.create_order(basket=self.basket)

        discounts = order.discounts.all()
        self.assertEqual(1, len(discounts))
        self.assertEqual(1, len(order.post_order_actions))

        discount = discounts[0]
        self.assertTrue(discount.is_post_order_action)
        self.assertEqual(D('0.00'), discount.amount)
        self.assertEqual('Something happened', discount.message)
Exemplo n.º 25
0
    def test_prevents_event_quantities_higher_than_original_line(self):
        basket = factories.create_basket(empty=True)
        add_product(basket, D('10.00'), 5)
        order = factories.create_order(basket=basket)

        # First shipping event
        lines = order.lines.all()
        self.handler.handle_shipping_event(order, self.shipped, lines, [4])

        with self.assertRaises(exceptions.InvalidShippingEvent):
            self.handler.handle_shipping_event(order, self.shipped, lines, [4])
Exemplo n.º 26
0
    def test_contains_voucher_details_after_voucher_is_deleted(self):
        voucher = create_voucher()
        order = create_order(number='100002')
        discount = OrderDiscount.objects.create(order=order, amount=D('10.00'),
                                                voucher_id=voucher.id)
        voucher.delete()

        self.assertTrue(discount.voucher is None)
        self.assertTrue(discount.offer is None)

        self.assertEqual(discount.description(), voucher.code)
Exemplo n.º 27
0
    def setUp(self):
        super().setUp()

        Order.pipeline = {'A': ('B', 'C')}
        self.order = create_order(status='A')
        url = reverse('dashboard:order-detail',
                      kwargs={'number': self.order.number})

        page = self.get(url)
        form = page.forms['order_status_form']
        form['new_status'] = 'B'
        self.response = form.submit()
Exemplo n.º 28
0
    def setUp(self):
        super().setUp()

        Order.pipeline = {'A': ('B', 'C'), 'B': ('A', 'C'), 'C': ('A', 'B')}
        self.order = create_order(status='A')
        url = reverse('dashboard:order-list')

        page = self.get(url)
        form = page.forms['orders_form']
        form['new_status'] = 'B'
        form['selected_order'] = self.order.pk
        self.response = form.submit(name='action',
                                    value='change_order_statuses')
Exemplo n.º 29
0
    def test_are_stock_allocations_available_track_stock_off(self):
        product_class = factories.ProductClassFactory(requires_shipping=False,
                                                      track_stock=False)
        product = factories.ProductFactory(product_class=product_class)
        basket = factories.create_basket(empty=True)
        add_product(basket, D('10.00'), 5, product=product)
        order = factories.create_order(basket=basket)

        line = order.lines.get()
        self.assertEqual(
            self.handler.are_stock_allocations_available([line], [105]),
            True,
        )
Exemplo n.º 30
0
    def test_has_discount_recorded_correctly_when_order_is_placed(self):
        add_product(self.basket, D('12.00'), 1)
        utils.Applicator().apply(self.basket)
        methods = StubRepository().get_shipping_methods(self.basket)
        method = methods[0]
        order = factories.create_order(basket=self.basket,
                                       shipping_method=method)

        discounts = order.discounts.all()
        self.assertEqual(1, len(discounts))

        discount = discounts[0]
        self.assertTrue(discount.is_shipping_discount)
        self.assertEqual(D('9.00'), discount.amount)