def test_next(create_transaction, status, expected_transition): transaction = create_transaction(status) if status else None TransactionStatusTransition.next(transaction, TransactionAction.complete, '_manual') if expected_transition == 'initial': assert TransactionStatusTransition._next_from_initial.called elif expected_transition == 'successful': assert TransactionStatusTransition._next_from_successful.called elif expected_transition == 'pending': assert TransactionStatusTransition._next_from_pending.called
def test_next_providers(create_transaction, provider, manual): action = TransactionAction.complete initial_transaction = create_transaction(TransactionStatus.cancelled) successful_transaction = create_transaction(TransactionStatus.successful) pending_transaction = create_transaction(TransactionStatus.pending) # Test initial statuses TransactionStatusTransition.next(initial_transaction, action, provider) TransactionStatusTransition._next_from_initial.assert_called_with(action, manual) # Test successful statuses TransactionStatusTransition.next(successful_transaction, action, provider) TransactionStatusTransition._next_from_successful.assert_called_with(action, manual) # Test pending statuses TransactionStatusTransition.next(pending_transaction, action, provider) TransactionStatusTransition._next_from_pending.assert_called_with(action, manual)
def test_next_invalid(): transaction = MagicMock(status=1337) with pytest.raises(InvalidTransactionStatus): TransactionStatusTransition.next(transaction, TransactionAction.complete, '')