"""Functional tests for subscribing to application webhooks events.""" from unittest.mock import MagicMock, patch from oto import status from collaborator.constants import error from tests.testutils import db, mock_auth from tests.testutils import transferwise_fixtures as fixtures @patch("collaborator.models.transferwise.requests") @db.test_schema_default_seed def test_create_quote(mock_transferwise, auth_client, mocker, mock_account): """Test create quote.""" mock_auth(mocker, mock_account.id) ping_api_response = MagicMock() ping_api_response.status_code = 200 ping_api_response.json.return_value = {"currentStatus": "ACTIVATED"} mock_transferwise.get.return_value = ping_api_response create_quote_mock = MagicMock() create_quote_mock.status_code = 200 create_quote_mock.json.return_value = fixtures.QUOTE_RESPONSE mock_transferwise.post.return_value = create_quote_mock mock_transferwise.get.side_effect = [ping_api_response] mock_transferwise.post.side_effect = [create_quote_mock] payload = { "quotes": [fixtures.QUOTE_REQUESTED_PARAMS], "vendor_id": mock_account.id, } result = auth_client.post("/transferwise/quote", json=payload) assert result.status_code == 200 assert result.json == {"quotes": [fixtures.QUOTE_RESPONSE]} @patch("collaborator.models.transferwise.requests") @db.test_schema_default_seed def test_create_quote_error(mock_transferwise, auth_client, mocker, mock_account): """Test create quote error.""" mock_auth(mocker, mock_account.id) mock_response = MagicMock() mock_response.status_code = 500 mock_transferwise.post.return_value = mock_response payload = {} result = auth_client.post("/transferwise/quote", json=payload) assert result.status_code == 400 @db.test_schema_default_seed def test_create_quote_missing_profile(auth_client, mocker): """Test create quote when the profile doesn't exist.""" vendor_id = 12345 mock_auth(mocker, vendor_id) result = auth_client.post( "/transferwise/quote", json={"vendor_id": vendor_id, "quotes": [{**fixtures.QUOTE_REQUESTED_PARAMS}]}, ) assert result.status_code == status.NOT_FOUND assert result.json == { "code": error.ERROR_CODE_PROFILE_NOT_FOUND, "message": error.ERROR_MESSAGE_PROFILE_NOT_FOUND, }