예제 #1
0
def test_view_change_order_line_quantity(admin_client,
                                         order_with_items_and_stock):
    """
    user goes to order details page
    user selects first order line with quantity 3 and changes it to 2
    """
    lines_before_quantity_change = order_with_items_and_stock.get_lines()
    lines_before_quantity_change_count = lines_before_quantity_change.count()
    line = lines_before_quantity_change.first()
    line_quantity_before_quantity_change = line.quantity

    url = reverse('dashboard:orderline-change-quantity',
                  kwargs={
                      'order_pk': order_with_items_and_stock.pk,
                      'line_pk': line.pk
                  })
    response = admin_client.get(url)
    assert response.status_code == 200
    response = admin_client.post(url, {'quantity': 2}, follow=True)
    redirected_to, redirect_status_code = response.redirect_chain[-1]
    # check redirection
    assert redirect_status_code == 302
    assert get_url_path(redirected_to) == reverse(
        'dashboard:order-details', args=[order_with_items_and_stock.pk])
    # success messages should appear after redirect
    assert response.context['messages']
    lines_after = Order.objects.get().get_lines()
    # order should have the same lines
    assert lines_before_quantity_change_count == lines_after.count()
    # stock allocation should be 2 now
    assert Stock.objects.first().quantity_allocated == 2
    line.refresh_from_db()
    # source line quantity should be decreased to 2
    assert line.quantity == 2
    # order should have the same delivery groups count
    assert order_with_items_and_stock.groups.count() == 1
    # a note in the order's history should be created
    assert OrderHistoryEntry.objects.get(
        order=order_with_items_and_stock).comment == (
            'Changed quantity for product %(product)s from'
            ' %(old_quantity)s to %(new_quantity)s') % {
                'product': line.product,
                'old_quantity': line_quantity_before_quantity_change,
                'new_quantity': 2
            }
예제 #2
0
파일: test_order.py 프로젝트: arneb/saleor
def test_view_change_order_line_quantity(admin_client, order_with_items_and_stock):
    """
    user goes to order details page
    user selects first order line with quantity 3 and changes it to 2
    """
    lines_before_quantity_change = order_with_items_and_stock.get_items()
    lines_before_quantity_change_count = lines_before_quantity_change.count()
    line = lines_before_quantity_change.first()
    line_quantity_before_quantity_change = line.quantity

    url = reverse(
        'dashboard:orderline-change-quantity', kwargs={
            'order_pk': order_with_items_and_stock.pk,
            'line_pk': line.pk})
    response = admin_client.get(url)
    assert response.status_code == 200
    response = admin_client.post(
        url, {'quantity': 2}, follow=True)
    redirected_to, redirect_status_code = response.redirect_chain[-1]
    # check redirection
    assert redirect_status_code == 302
    assert get_url_path(redirected_to) == reverse(
        'dashboard:order-details',
        args=[order_with_items_and_stock.pk])
    # success messages should appear after redirect
    assert response.context['messages']
    lines_after = Order.objects.get().get_items()
    # order should have the same lines
    assert lines_before_quantity_change_count == lines_after.count()
    # stock allocation should be 2 now
    assert Stock.objects.first().quantity_allocated == 2
    line.refresh_from_db()
    # source line quantity should be decreased to 2
    assert line.quantity == 2
    # order should have the same delivery groups count
    assert order_with_items_and_stock.groups.count() == 1
    # a note in the order's history should be created
    assert OrderHistoryEntry.objects.get(
        order=order_with_items_and_stock).comment == (
            'Changed quantity for product %(product)s from'
            ' %(old_quantity)s to %(new_quantity)s') % {
                    'product': line.product,
                    'old_quantity': line_quantity_before_quantity_change,
                    'new_quantity': 2}
예제 #3
0
def test_view_split_order_line(admin_client, order_with_items_and_stock):
    """
    user goes to order details page
    user selects first order line with quantity 3 and moves 2 items
      to a new shipment
    user selects the line from the new shipment and moves all items
      back to the first shipment
    """
    lines_before_split = order_with_items_and_stock.get_lines()
    lines_before_split_count = lines_before_split.count()
    line = lines_before_split.first()
    line_quantity_before_split = line.quantity
    quantity_allocated_before_split = line.stock.quantity_allocated
    old_delivery_group = DeliveryGroup.objects.get()

    url = reverse('dashboard:orderline-split',
                  kwargs={
                      'order_pk': order_with_items_and_stock.pk,
                      'line_pk': line.pk
                  })
    response = admin_client.get(url)
    assert response.status_code == 200
    response = admin_client.post(url, {
        'quantity': 2,
        'target_group': MoveLinesForm.NEW_SHIPMENT
    },
                                 follow=True)
    redirected_to, redirect_status_code = response.redirect_chain[-1]
    # check redirection
    assert redirect_status_code == 302
    assert get_url_path(redirected_to) == reverse(
        'dashboard:order-details', args=[order_with_items_and_stock.pk])
    # success messages should appear after redirect
    assert response.context['messages']
    lines_after = Order.objects.get().get_lines()
    # order should have one more line
    assert lines_before_split_count + 1 == lines_after.count()
    # stock allocation should not be changed
    assert Stock.objects.first(
    ).quantity_allocated == quantity_allocated_before_split
    line.refresh_from_db()
    # source line quantity should be decreased to 1
    assert line.quantity == line_quantity_before_split - 2
    # order should have 2 delivery groups now
    assert order_with_items_and_stock.groups.count() == 2
    # a note in the order's history should be created
    new_group = DeliveryGroup.objects.last()
    assert OrderHistoryEntry.objects.get(
        order=order_with_items_and_stock).comment == (
            'Moved 2 items %(item)s from '
            '%(old_group)s to %(new_group)s') % {
                'item': line,
                'old_group': old_delivery_group,
                'new_group': new_group
            }
    new_line = new_group.items.get()
    # the new line should contain the moved quantity
    assert new_line.quantity == 2
    url = reverse('dashboard:orderline-split',
                  kwargs={
                      'order_pk': order_with_items_and_stock.pk,
                      'line_pk': new_line.pk
                  })
    admin_client.post(url, {
        'quantity': 2,
        'target_group': old_delivery_group.pk
    })
    # an other note in the order's history should be created
    assert OrderHistoryEntry.objects.filter(
        order=order_with_items_and_stock).last().comment == (
            'Moved 2 items %(item)s from removed '
            'group to %(new_group)s') % {
                'item': line,
                'new_group': old_delivery_group
            }
    # the new shipment should be removed
    assert order_with_items_and_stock.groups.count() == 1
    # the related order line should be removed
    assert lines_before_split_count == Order.objects.get().get_lines().count()
    line.refresh_from_db()
    # the initial line should get the quantity restored to its initial value
    assert line_quantity_before_split == line.quantity
예제 #4
0
파일: test_order.py 프로젝트: arneb/saleor
def test_view_split_order_line(admin_client, order_with_items_and_stock):
    """
    user goes to order details page
    user selects first order line with quantity 3 and moves 2 items
      to a new shipment
    user selects the line from the new shipment and moves all items
      back to the first shipment
    """
    lines_before_split = order_with_items_and_stock.get_items()
    lines_before_split_count = lines_before_split.count()
    line = lines_before_split.first()
    line_quantity_before_split = line.quantity
    quantity_allocated_before_split = line.stock.quantity_allocated
    old_delivery_group = DeliveryGroup.objects.get()

    url = reverse(
        'dashboard:orderline-split', kwargs={
            'order_pk': order_with_items_and_stock.pk,
            'line_pk': line.pk})
    response = admin_client.get(url)
    assert response.status_code == 200
    response = admin_client.post(
        url,
        {'quantity': 2, 'target_group': MoveItemsForm.NEW_SHIPMENT},
        follow=True)
    redirected_to, redirect_status_code = response.redirect_chain[-1]
    # check redirection
    assert redirect_status_code == 302
    assert get_url_path(redirected_to) == reverse(
        'dashboard:order-details',
        args=[order_with_items_and_stock.pk])
    # success messages should appear after redirect
    assert response.context['messages']
    lines_after = Order.objects.get().get_items()
    # order should have one more line
    assert lines_before_split_count + 1 == lines_after.count()
    # stock allocation should not be changed
    assert Stock.objects.first().quantity_allocated == quantity_allocated_before_split
    line.refresh_from_db()
    # source line quantity should be decreased to 1
    assert line.quantity == line_quantity_before_split - 2
    # order should have 2 delivery groups now
    assert order_with_items_and_stock.groups.count() == 2
    # a note in the order's history should be created
    new_group = DeliveryGroup.objects.last()
    assert OrderHistoryEntry.objects.get(
        order=order_with_items_and_stock).comment == (
                'Moved 2 items %(item)s from '
                '%(old_group)s to %(new_group)s') % {
                    'item': line,
                    'old_group': old_delivery_group,
                    'new_group': new_group}
    new_line = new_group.items.get()
    # the new line should contain the moved quantity
    assert new_line.quantity == 2
    url = reverse(
        'dashboard:orderline-split', kwargs={
            'order_pk': order_with_items_and_stock.pk,
            'line_pk': new_line.pk})
    admin_client.post(
        url, {'quantity': 2, 'target_group': old_delivery_group.pk})
    # an other note in the order's history should be created
    assert OrderHistoryEntry.objects.filter(
        order=order_with_items_and_stock).last().comment ==(
            'Moved 2 items %(item)s from removed '
            'group to %(new_group)s') % {
                'item': line,
                'new_group': old_delivery_group}
    # the new shipment should be removed
    assert order_with_items_and_stock.groups.count() == 1
    # the related order line should be removed
    assert lines_before_split_count == Order.objects.get().get_items().count()
    line.refresh_from_db()
    # the initial line should get the quantity restored to its initial value
    assert line_quantity_before_split == line.quantity