Skip to content

Commit 63a08db

Browse files
Jake Pruittdianeschulze
andauthored
Change status command to use /jobs endpoint (#97)
Co-authored-by: Diane Schulze <[email protected]>
1 parent 9ba2d4b commit 63a08db

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Unreleased
22

3+
# 1.4.1 (2020-08-06)
4+
- Use the `/jobs` endpoint in the `status` command
5+
36
# 1.4.0 (2020-08-04)
47
- Create upload-source command to replace add-source, with extra `--replace` option
58

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Flags:
264264

265265
### status
266266

267-
View the status of a tileset. This includes how many jobs are queued, processing, and complete.
267+
View the status of the most recent job for a tileset. To get more detailed information about a tileset's jobs, including the timestamps of failed and successful jobs, use the `tilesets jobs <tileset_id>` command.
268268

269269
```
270270
tilesets status <tileset_id>

mapbox_tilesets/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""mapbox_tilesets package"""
22

3-
__version__ = "1.4.0"
3+
__version__ = "1.4.1"

mapbox_tilesets/scripts/cli.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,18 @@ def status(tileset, token=None, indent=None):
232232
mapbox_api = utils._get_api()
233233
mapbox_token = utils._get_token(token)
234234
s = utils._get_session()
235-
url = "{0}/tilesets/v1/{1}/status?access_token={2}".format(
235+
url = "{0}/tilesets/v1/{1}/jobs?limit=1&access_token={2}".format(
236236
mapbox_api, tileset, mapbox_token
237237
)
238238
r = s.get(url)
239239

240-
click.echo(json.dumps(r.json(), indent=indent))
240+
status = {}
241+
for job in r.json():
242+
status["id"] = job["tilesetId"]
243+
status["latest_job"] = job["id"]
244+
status["status"] = job["stage"]
245+
246+
click.echo(json.dumps(status, indent=indent))
241247

242248

243249
@cli.command("tilejson")

tests/test_cli_status.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,37 @@ def test_cli_status(mock_request_get, MockResponse):
1313
runner = CliRunner()
1414

1515
# sends expected request
16-
message = {"message": "mock message"}
16+
message = [{"id": "a123", "stage": "processing", "tilesetId": "test.id"}]
1717
mock_request_get.return_value = MockResponse(message)
1818
result = runner.invoke(status, ["test.id"])
1919
mock_request_get.assert_called_with(
20-
"https://api.mapbox.com/tilesets/v1/test.id/status?access_token=fake-token"
20+
"https://api.mapbox.com/tilesets/v1/test.id/jobs?limit=1&access_token=fake-token"
2121
)
2222
assert result.exit_code == 0
23-
assert json.loads(result.output) == message
23+
expected_status = {
24+
"id": "test.id",
25+
"status": "processing",
26+
"latest_job": "a123",
27+
}
28+
assert json.loads(result.output) == expected_status
2429

2530

2631
@pytest.mark.usefixtures("token_environ")
2732
@mock.patch("requests.Session.get")
2833
def test_cli_status_use_token_flag(mock_request_get, MockResponse):
2934
runner = CliRunner()
30-
message = {"message": "mock message"}
35+
message = [{"id": "a123", "stage": "processing", "tilesetId": "test.id"}]
3136
mock_request_get.return_value = MockResponse(message)
3237
# Provides the flag --token
3338
result = runner.invoke(status, ["test.id", "--token", "flag-token"])
3439
mock_request_get.assert_called_with(
35-
"https://api.mapbox.com/tilesets/v1/test.id/status?access_token=flag-token"
40+
"https://api.mapbox.com/tilesets/v1/test.id/jobs?limit=1&access_token=flag-token"
3641
)
3742

3843
assert result.exit_code == 0
39-
assert json.loads(result.output) == {"message": "mock message"}
44+
expected_status = {
45+
"id": "test.id",
46+
"status": "processing",
47+
"latest_job": "a123",
48+
}
49+
assert json.loads(result.output) == expected_status

0 commit comments

Comments
 (0)