|
| 1 | +import certifi |
| 2 | +import pytest |
| 3 | +from mock import patch |
| 4 | + |
| 5 | +from pyproj.network import set_ca_bundle_path |
| 6 | + |
| 7 | + |
| 8 | +@patch.dict("os.environ", {}, clear=True) |
| 9 | +@patch("pyproj.network._set_ca_bundle_path") |
| 10 | +def test_ca_bundle_path__default(c_set_ca_bundle_path_mock): |
| 11 | + set_ca_bundle_path() |
| 12 | + c_set_ca_bundle_path_mock.assert_called_with(certifi.where()) |
| 13 | + |
| 14 | + |
| 15 | +@pytest.mark.parametrize( |
| 16 | + "env_var", ["PROJ_CURL_CA_BUNDLE", "CURL_CA_BUNDLE", "SSL_CERT_FILE"] |
| 17 | +) |
| 18 | +@patch("pyproj.network._set_ca_bundle_path") |
| 19 | +def test_ca_bundle_path__always_certifi(c_set_ca_bundle_path_mock, env_var): |
| 20 | + with patch.dict("os.environ", {env_var: "/tmp/dummy/path/cacert.pem"}, clear=True): |
| 21 | + set_ca_bundle_path(True) |
| 22 | + c_set_ca_bundle_path_mock.assert_called_with(certifi.where()) |
| 23 | + |
| 24 | + |
| 25 | +@patch.dict("os.environ", {}, clear=True) |
| 26 | +@patch("pyproj.network._set_ca_bundle_path") |
| 27 | +def test_ca_bundle_path__skip(c_set_ca_bundle_path_mock): |
| 28 | + set_ca_bundle_path(False) |
| 29 | + c_set_ca_bundle_path_mock.assert_not_called() |
| 30 | + |
| 31 | + |
| 32 | +@pytest.mark.parametrize( |
| 33 | + "env_var", ["PROJ_CURL_CA_BUNDLE", "CURL_CA_BUNDLE", "SSL_CERT_FILE"] |
| 34 | +) |
| 35 | +@patch("pyproj.network._set_ca_bundle_path") |
| 36 | +def test_ca_bundle_path__env_var_skip(c_set_ca_bundle_path_mock, env_var): |
| 37 | + with patch.dict("os.environ", {env_var: "/tmp/dummy/path/cacert.pem"}, clear=True): |
| 38 | + set_ca_bundle_path() |
| 39 | + c_set_ca_bundle_path_mock.assert_not_called() |
| 40 | + |
| 41 | + |
| 42 | +@pytest.mark.parametrize( |
| 43 | + "env_var", ["PROJ_CURL_CA_BUNDLE", "CURL_CA_BUNDLE", "SSL_CERT_FILE"] |
| 44 | +) |
| 45 | +@patch("pyproj.network._set_ca_bundle_path") |
| 46 | +def test_ca_bundle_path__custom_path(c_set_ca_bundle_path_mock, env_var): |
| 47 | + with patch.dict("os.environ", {env_var: "/tmp/dummy/path/cacert.pem"}, clear=True): |
| 48 | + set_ca_bundle_path("/my/path/to/cacert.pem") |
| 49 | + c_set_ca_bundle_path_mock.assert_called_with("/my/path/to/cacert.pem") |
0 commit comments