Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklvsa committed Oct 17, 2024
1 parent 46e9bbf commit 7dcd0e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def token_environ(monkeypatch):
monkeypatch.setenv("MAPBOX_ACCESS_TOKEN", "pk.eyJ1IjoidGVzdC11c2VyIn0K")
monkeypatch.setenv("MapboxAccessToken", "test-token")


@pytest.fixture(scope="function")
def api_environ(monkeypatch):
monkeypatch.setenv("MAPBOX_API", "https://api.mapbox.com")
Expand Down
19 changes: 12 additions & 7 deletions tests/test_cli_estimate_cu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@
from click.testing import CliRunner

from mapbox_tilesets.scripts.cli import estimate_cu
from utils import clean_runner_output


@pytest.mark.usefixtures("token_environ")
@pytest.mark.usefixtures("api_environ")
@mock.patch("requests.Session.get")
def test_cli_estimate_cu_tileset_no_sources(mock_request_get, MockResponse):
runner = CliRunner()

tileset_id = "my.tileset"
msg = {"message": "mock message"}

mock_request_get.return_value = MockResponse(msg)
result = runner.invoke(estimate_cu, [tileset_id])
mock_request_get.assert_called_with(
f"https://api.mapbox.com/tilesets/v1/{tileset_id}/estimate",
params={"band_count": 15, "access_token": "pk.eyJ1IjoidGVzdC11c2VyIn0K"}
params={"band_count": 15, "access_token": "pk.eyJ1IjoidGVzdC11c2VyIn0K"},
)

assert result.exit_code == 1
assert result.output == f"[warning] estimating '{tileset_id}' with a default global bounds\nError: {json.dumps(msg)}\n"
assert (
result.output
== f"[warning] estimating '{tileset_id}' with a default global bounds\nError: {json.dumps(msg)}\n"
)


@pytest.mark.usefixtures("token_environ")
Expand All @@ -33,16 +36,18 @@ def test_cli_estimate_cu_tileset_no_sources(mock_request_get, MockResponse):
@mock.patch("glob.glob")
def test_cli_estimate_cu_tilese_with_sources(mock_glob, mock_request_get, MockResponse):
runner = CliRunner()

tileset_id = "my.tileset"
msg = {"cu": "5"}

mock_request_get.return_value = MockResponse(msg)
mock_glob.return_value = ["myfile.grib2"]
result = runner.invoke(estimate_cu, [tileset_id, "-s", "/my/sources/*.grib2", "--raw"])
result = runner.invoke(
estimate_cu, [tileset_id, "-s", "/my/sources/*.grib2", "--raw"]
)
mock_request_get.assert_called_with(
f"https://api.mapbox.com/tilesets/v1/{tileset_id}/estimate",
params={"band_count": 15, "access_token": "pk.eyJ1IjoidGVzdC11c2VyIn0K"}
params={"band_count": 15, "access_token": "pk.eyJ1IjoidGVzdC11c2VyIn0K"},
)

assert result.exit_code == 0
Expand Down

0 comments on commit 7dcd0e6

Please sign in to comment.