コード例 #1
0
def test_process_order_by_charge_unexpected_error(charge_mock, request_mock):
    charge_mock.side_effect = Exception('Error that will never occur ;)')
    order = OrderFactory(recurrent=True)
    result = OrderProcessing(request_mock, order).process()
    order.refresh_from_db()
    charge_mock.assert_called_once()
    assert order.status == Order.ERROR
    assert result.get('processed_by') is None
    assert result['error'] == (
        "Critical Stripe error: Exception(u'Error that will never occur ;)',)")
コード例 #2
0
def test_intercom_event(request_mock, add_event_mock, _factory, event,
                        order_id):
    data = {'old_status': 'Active', 'new_status': 'Shipped', 'error': None}
    if order_id:
        order = _factory(id=order_id)
    else:
        order = _factory()
        data.update({'gear-order': order.id})
    result = OrderProcessing(request_mock, order).process()
    data.update({'stripe_charge': result.get('charge', {}).get('id')})
    add_event_mock.assert_called_once_with(customer_id=order.customer.id,
                                           event=event,
                                           order_id=order_id,
                                           data=data)
コード例 #3
0
def test_process_order_by_charge_and_credits_declined(request_mock,
                                                      charge_mock):
    charge_mock.side_effect = _raise_card_was_declined
    order = OrderFactory(recurrent=True, amount=20, customer__amount=5)
    result = OrderProcessing(request_mock, order).process()
    order.refresh_from_db()
    order.customer.refresh_from_db()
    charge_mock.assert_called_once_with(amount=1500,
                                        currency='SGD',
                                        customer=order.customer.stripe_id,
                                        description=str(order.coffee),
                                        metadata={'order_id': order.id})
    assert order.status == Order.DECLINED
    assert result.get('processed_by') is None
    # after a declined payment, the amount of credits on customer's account
    # and the order amount needs to be restored to its original value
    assert order.customer.amount == 5
    assert order.amount == 20
コード例 #4
0
def test_process_order_by_charge_declined(charge_mock, request_mock,
                                          mailoutbox):
    charge_mock.side_effect = _raise_card_was_declined
    order = OrderFactory(recurrent=True)
    result = OrderProcessing(request_mock, order).process()
    order.refresh_from_db()
    charge_mock.assert_called_once()
    assert order.status == Order.DECLINED
    assert result.get('processed_by') is None
    assert result['declined'] is True
    assert result['error'] == 'Your card was declined.'

    # check email which sent when card was declined
    assert len(mailoutbox) == 1
    m = mailoutbox[0]
    assert m.subject == OrderProcessing.EMAIL_DECLINED_SUBJECT
    assert m.template_name == OrderProcessing.EMAIL_DECLINED_SUBJECT
    assert m.from_email == 'Hook Coffee <*****@*****.**>'
    assert list(m.to) == [order.customer.user.email]
コード例 #5
0
def test_order_correct_status(request_mock, charge_mock, status, error):
    order = OrderFactory(status=status)
    result = OrderProcessing(request_mock, order).process()
    charge_mock.assert_called_once()
    assert result.get('error') is error