'Test auth_transaction'

@patch('r2.lib.authorize.interaction.request')
@patch('r2.lib.authorize.interaction.api.create_authorization_hold')
@patch('r2.lib.authorize.interaction.CustomerID.get_id')
@patch('r2.lib.authorize.interaction.PayID.get_ids')
def test_auth_transaction(self, get_ids, get_id, create_authorization_hold, request):

    link = Mock(spec=Link)
    link._id = 99
    amount = 100
    payment_method_id = 50
    campaign_id = 99
    request.ip = '127.0.0.1'
    transaction_id = 123
    get_ids.return_value = []
    return_value = auth_transaction(amount, self.user, payment_method_id, link, campaign_id)
    self.assertEqual(return_value, (None, 'invalid    payment    method'))
    get_ids.return_value.append(payment_method_id)
    get_id.return_value = 1000
    create_authorization_hold.return_value = transaction_id
    duplicate_transaction_error = DuplicateTransactionError(transaction_id=transaction_id)
    create_authorization_hold.side_effect = duplicate_transaction_error
    with patch('r2.lib.authorize.interaction.Bid.one') as one:
        one.side_effect = NotFound()
        return_value = auth_transaction(amount, self.user, payment_method_id, link, campaign_id)
        self.assertEqual(return_value, (transaction_id, None))
    with patch('r2.lib.authorize.interaction.Bid._new') as _new:
        return_value = auth_transaction(amount, self.user, payment_method_id, link, campaign_id)
        self.assertTrue(_new.called)
        self.assertEqual(return_value, (transaction_id, None))
    create_authorization_hold.side_effect = TransactionError('')
    return_value = auth_transaction(amount, self.user, payment_method_id, link, campaign_id)
    self.assertEqual(return_value[0], None)
