diff --git a/tests/test_apicep.py b/tests/test_apicep.py index bf999bb..74bd3ea 100644 --- a/tests/test_apicep.py +++ b/tests/test_apicep.py @@ -5,11 +5,13 @@ from brazilcep import WebService, exceptions, get_address_from_cep IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true" +SKIP_REAL_TEST = os.getenv("SKIP_REAL_TEST", False) +@pytest.mark.skipif(SKIP_REAL_TEST, reason="Skip real teste API.") @pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.") def test_fetch_address_success_real(): - # Realizamos a consulta de CEP + address = get_address_from_cep("37.503-130", webservice=WebService.APICEP) assert address["district"] == "Santo Antônio" @@ -21,6 +23,7 @@ def test_fetch_address_success_real(): def test_fetch_address_success(requests_mock): + req_mock_text = """{ "status":200, "ok":true, @@ -34,7 +37,6 @@ def test_fetch_address_success(requests_mock): requests_mock.get("https://ws.apicep.com/cep/37503130.json", text=req_mock_text) - # Realizamos a consulta de CEP address = get_address_from_cep("37.503-130", webservice=WebService.APICEP, timeout=5) assert address["district"] == "Santo Antônio" @@ -59,10 +61,7 @@ def test_fetch_address_success(requests_mock): proxies = {"https": "00.00.000.000", "http": "00.00.000.000"} - # Realizamos a consulta de CEP - address = get_address_from_cep( - "99999-999", webservice=WebService.APICEP, timeout=5, proxies=proxies - ) + address = get_address_from_cep("99999-999", webservice=WebService.APICEP, timeout=5, proxies=proxies) assert address["district"] == "" assert address["cep"] == "99999-999" @@ -79,7 +78,6 @@ def test_fetch_address_cep_not_found(requests_mock): requests_mock.get("https://ws.apicep.com/cep/00000000.json", text=req_mock_text) - # Realizamos a consulta de CEP with pytest.raises(exceptions.CEPNotFound): get_address_from_cep("00000-000", webservice=WebService.APICEP) @@ -109,7 +107,7 @@ def test_fetch_address_blocked_by_flood(requests_mock): def test_fetch_address_404(requests_mock): - requests_mock.get("https://ws.apicep.com/cep/37503130.json", status_code=404) # noqa + requests_mock.get("https://ws.apicep.com/cep/37503130.json", status_code=404) with pytest.raises(exceptions.BrazilCEPException): get_address_from_cep("37503-130", webservice=WebService.APICEP) diff --git a/tests/test_client.py b/tests/test_client.py index 0f013b5..a5f0104 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -5,6 +5,7 @@ from brazilcep import WebService, get_address_from_cep from brazilcep.client import _format_cep + def test_search_error(): with pytest.raises(KeyError): get_address_from_cep("37.503-130", webservice=5) @@ -44,6 +45,7 @@ def test_format_cep_fail(): with pytest.raises(ValueError): _format_cep(True) + def test_a_deprecated_enum_value(): with catch_warnings(record=True) as w: @@ -55,4 +57,4 @@ def test_a_deprecated_enum_value(): get_address_from_cep("37.503-130", webservice=WebService.CORREIOS) assert len(w) == 1 assert issubclass(w[0].category, DeprecationWarning) - assert str(w[0].message) == 'CORREIOS is going to be deprecated. Please, use other webservice.' + assert str(w[0].message) == "CORREIOS is going to be deprecated. Please, use other webservice." diff --git a/tests/test_opencep.py b/tests/test_opencep.py index 5d751f2..cb25778 100644 --- a/tests/test_opencep.py +++ b/tests/test_opencep.py @@ -5,11 +5,13 @@ from brazilcep import WebService, exceptions, get_address_from_cep IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true" +SKIP_REAL_TEST = os.getenv("SKIP_REAL_TEST", False) +@pytest.mark.skipif(SKIP_REAL_TEST, reason="Skip real teste API.") @pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.") def test_fetch_address_success_real(): - # Realizamos a consulta de CEP + address = get_address_from_cep("37.503-130", webservice=WebService.OPENCEP) assert address["district"] == "Santo Antônio" @@ -33,7 +35,6 @@ def test_fetch_address_success(requests_mock): requests_mock.get("https://opencep.com/v1/37503130", text=req_mock_text, status_code=200) - # Realizamos a consulta de CEP address = get_address_from_cep("37.503-130", webservice=WebService.OPENCEP, timeout=5) assert address["district"] == "Santo Antônio" @@ -58,10 +59,7 @@ def test_fetch_address_success(requests_mock): proxies = {"https": "00.00.000.000", "http": "00.00.000.000"} - # Realizamos a consulta de CEP - address = get_address_from_cep( - "99999-999", webservice=WebService.OPENCEP, timeout=6, proxies=proxies - ) + address = get_address_from_cep("99999-999", webservice=WebService.OPENCEP, timeout=6, proxies=proxies) assert address["district"] == "Jardim Centro Cívico" assert address["cep"] == "99999-999" @@ -75,7 +73,6 @@ def test_fetch_address_cep_not_found(requests_mock): requests_mock.get("https://opencep.com/v1/00000000", status_code=404) - # Realizamos a consulta de CEP with pytest.raises(exceptions.CEPNotFound): get_address_from_cep("00000-000", webservice=WebService.OPENCEP) diff --git a/tests/test_viacep.py b/tests/test_viacep.py index fafd7f9..13515a1 100644 --- a/tests/test_viacep.py +++ b/tests/test_viacep.py @@ -9,11 +9,13 @@ logger = logging.getLogger(__name__) IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true" +SKIP_REAL_TEST = os.getenv("SKIP_REAL_TEST", False) +@pytest.mark.skipif(SKIP_REAL_TEST, reason="Skip real teste API.") @pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.") def test_get_address_from_cep_success_real(): - # Realizamos a consulta de CEP + try: address = get_address_from_cep("37.503-130", webservice=WebService.VIACEP) @@ -47,7 +49,6 @@ def test_get_address_from_cep_success(requests_mock): proxies = {"https": "00.00.000.000", "http": "00.00.000.000"} - # Realizamos a consulta de CEP address = get_address_from_cep("37.503-130", webservice=WebService.VIACEP, timeout=10, proxies=proxies) assert address["district"] == "Santo Antônio" @@ -78,7 +79,6 @@ def test_get_address_from_cep_not_found(requests_mock): def test_get_address_invalid_cep(requests_mock): requests_mock.get("http://www.viacep.com.br/ws/3750313/json", status_code=400) - # Realizamos a consulta de CEP with pytest.raises(exceptions.InvalidCEP): get_address_from_cep("37503-13", webservice=WebService.VIACEP)