|
| 1 | +import pytest |
| 2 | + |
| 3 | +from fullcontact import FullContactClient |
| 4 | +from fullcontact.config.client_config import Session |
| 5 | +from .utils.error_messages import ErrorMessages |
| 6 | +from .utils.mock_request import MockRequest |
| 7 | +from .utils.mock_response import MockResponse |
| 8 | + |
| 9 | +REQUEST_TYPE = "verification" |
| 10 | +METHOD_EMAIL = "email" |
| 11 | +SCENARIO_POSITIVE = "positive" |
| 12 | + |
| 13 | + |
| 14 | +# MOCK API CALLS ####################################################################################################### |
| 15 | + |
| 16 | +@pytest.fixture |
| 17 | +def mock_good_response(monkeypatch): |
| 18 | + def mock_get(*args, **kwargs): |
| 19 | + return MockResponse.get_mock_response( |
| 20 | + REQUEST_TYPE, |
| 21 | + method=METHOD_EMAIL, |
| 22 | + test_scenario=SCENARIO_POSITIVE |
| 23 | + ) |
| 24 | + |
| 25 | + monkeypatch.setattr(Session, "get", mock_get) |
| 26 | + |
| 27 | + |
| 28 | +######################################################################################################################## |
| 29 | + |
| 30 | + |
| 31 | +class TestVerificationApi(object): |
| 32 | + |
| 33 | + def setup(self): |
| 34 | + self.fullcontact_client = FullContactClient(MockRequest.MOCK_TOKEN) |
| 35 | + |
| 36 | + # Empty query provided) |
| 37 | + def test_empty_query(self): |
| 38 | + with pytest.raises(TypeError) as fc_exception: |
| 39 | + self.fullcontact_client.verification.email() |
| 40 | + |
| 41 | + assert str(fc_exception.value).startswith(ErrorMessages.VERIFICATION_EMAIL_MISSING_ARGUMENT) |
| 42 | + |
| 43 | + # Send a good request |
| 44 | + def test_good_requests(self, mock_good_response): |
| 45 | + query = MockRequest.get_mock_request(REQUEST_TYPE, METHOD_EMAIL, SCENARIO_POSITIVE) |
| 46 | + expected_result = MockResponse.get_mock_response( |
| 47 | + REQUEST_TYPE, METHOD_EMAIL, SCENARIO_POSITIVE |
| 48 | + ) |
| 49 | + result = self.fullcontact_client.verification.email(**query) |
| 50 | + assert result.is_successful and \ |
| 51 | + result.get_status_code() == expected_result.status_code |
0 commit comments