"""Functional tests for getting TransferWise transactions for a batch.""" from oto import status from collaborator.constants import error from collaborator.models.transferwise import Transferwise from tests.testutils import db, mock_auth @db.test_schema_default_seed def test_get_batch_transactions(auth_client, mocker, mock_account): """Test getting transactions for a batch.""" mock_auth(mocker, mock_account.id) get_quote_mock = mocker.patch.object(Transferwise, "get_quote") get_quote_mock.return_value = get_quote_mock.reurn_value = { "paymentOptions": [{"payIn": "BANK_TRANSFER", "price": {}}] } result = auth_client.get("/transferwise/batch/1/transactions") assert result.status_code == status.OK assert result.json == [ { "source_amount": 50.0, "target_amount": 50.0, "transferwise_batch_id": 1, "source_currency": "USD", "target_currency": "USD", "profile_id": 12341235, "quote_id": "81b5e5b0-e7d8-4112-aad9-b9189d53dcb2", "recipient_id": 22223333, "status": "outgoing_payment_sent", "id": 1, "transfer_id": 1, "wire_fee": 0.00, "transferwise_fee": 0.50, "created_date": "2020-05-04T03:02:01", "collaborator_id": 1, "conversion_rate": None, "status_updated_date": "2020-05-04T03:05:01", "price": {}, } ] @db.test_schema_default_seed def test_get_batch_transactions_not_found(auth_client, mock_account, mocker): """Test getting transactions for a batch that doesn't exist.""" mock_auth(mocker, mock_account.id) get_quote_mock = mocker.patch.object(Transferwise, "get_quote") get_quote_mock.return_value = get_quote_mock.reurn_value = { "paymentOptions": [{"payIn": "BANK_TRANSFER", "price": {}}] } result = auth_client.get("/transferwise/batch/999/transactions") assert result.status_code == status.NOT_FOUND assert result.json["code"] == error.ERROR_CODE_TRANSFERWISE_BATCH_NOT_FOUND @db.test_schema_default_seed def test_get_batch_transactions_forbidden(auth_client, mock_account, mocker): """Test getting transactions for a batch with the wrong account ID.""" mock_auth(mocker, 999) get_quote_mock = mocker.patch.object(Transferwise, "get_quote") get_quote_mock.return_value = get_quote_mock.reurn_value = { "paymentOptions": [{"payIn": "BANK_TRANSFER", "price": {}}] } result = auth_client.get("/transferwise/batch/1/transactions") assert result.status_code == status.FORBIDDEN assert result.json["code"] == error.ERROR_CODE_AUTHORIZATION