Repository: mapbox/tilesets-cli

Issue:
Modify `status` command to rely on the `/jobs` API endpoint
Now that the `/jobs` endpoint supports `limit`, we can switch the `tileset status` command to rely on the `/jobs` endpoint under the hood. We can also add more information to the output of `tileset status`, like the [latest modified timestamp](https://github.com/mapbox/tilesets-cli/issues/81) and any warnings associated with the latest job.

cc/ @dianeschulze 

Comments:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b19be25..a363530 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
 # Unreleased
 
+# 1.4.1 (2020-08-06)
+- Use the `/jobs` endpoint in the `status` command
+
 # 1.4.0 (2020-08-04)
 - Create upload-source command to replace add-source, with extra `--replace` option
 
diff --git a/README.md b/README.md
index 1fab177..6628b5d 100644
--- a/README.md
+++ b/README.md
@@ -264,7 +264,7 @@ Flags:
 
 ### status
 
-View the status of a tileset. This includes how many jobs are queued, processing, and complete.
+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.
 
 ```
 tilesets status <tileset_id>
diff --git a/mapbox_tilesets/__init__.py b/mapbox_tilesets/__init__.py
index ec7e72a..43d023b 100644
--- a/mapbox_tilesets/__init__.py
+++ b/mapbox_tilesets/__init__.py
@@ -1,3 +1,3 @@
 """mapbox_tilesets package"""
 
-__version__ = "1.4.0"
+__version__ = "1.4.1"
diff --git a/mapbox_tilesets/scripts/cli.py b/mapbox_tilesets/scripts/cli.py
index 07eb99a..6fbecc8 100644
--- a/mapbox_tilesets/scripts/cli.py
+++ b/mapbox_tilesets/scripts/cli.py
@@ -232,12 +232,18 @@ def status(tileset, token=None, indent=None):
     mapbox_api = utils._get_api()
     mapbox_token = utils._get_token(token)
     s = utils._get_session()
-    url = "{0}/tilesets/v1/{1}/status?access_token={2}".format(
+    url = "{0}/tilesets/v1/{1}/jobs?limit=1&access_token={2}".format(
         mapbox_api, tileset, mapbox_token
     )
     r = s.get(url)
 
-    click.echo(json.dumps(r.json(), indent=indent))
+    status = {}
+    for job in r.json():
+        status["id"] = job["tilesetId"]
+        status["latest_job"] = job["id"]
+        status["status"] = job["stage"]
+
+    click.echo(json.dumps(status, indent=indent))
 
 
 @cli.command("tilejson")


Test patch:
diff --git a/tests/test_cli_status.py b/tests/test_cli_status.py
index 7cdb53c..c032f89 100644
--- a/tests/test_cli_status.py
+++ b/tests/test_cli_status.py
@@ -13,27 +13,37 @@ def test_cli_status(mock_request_get, MockResponse):
     runner = CliRunner()
 
     # sends expected request
-    message = {"message": "mock message"}
+    message = [{"id": "a123", "stage": "processing", "tilesetId": "test.id"}]
     mock_request_get.return_value = MockResponse(message)
     result = runner.invoke(status, ["test.id"])
     mock_request_get.assert_called_with(
-        "https://api.mapbox.com/tilesets/v1/test.id/status?access_token=fake-token"
+        "https://api.mapbox.com/tilesets/v1/test.id/jobs?limit=1&access_token=fake-token"
     )
     assert result.exit_code == 0
-    assert json.loads(result.output) == message
+    expected_status = {
+        "id": "test.id",
+        "status": "processing",
+        "latest_job": "a123",
+    }
+    assert json.loads(result.output) == expected_status
 
 
 @pytest.mark.usefixtures("token_environ")
 @mock.patch("requests.Session.get")
 def test_cli_status_use_token_flag(mock_request_get, MockResponse):
     runner = CliRunner()
-    message = {"message": "mock message"}
+    message = [{"id": "a123", "stage": "processing", "tilesetId": "test.id"}]
     mock_request_get.return_value = MockResponse(message)
     # Provides the flag --token
     result = runner.invoke(status, ["test.id", "--token", "flag-token"])
     mock_request_get.assert_called_with(
-        "https://api.mapbox.com/tilesets/v1/test.id/status?access_token=flag-token"
+        "https://api.mapbox.com/tilesets/v1/test.id/jobs?limit=1&access_token=flag-token"
     )
 
     assert result.exit_code == 0
-    assert json.loads(result.output) == {"message": "mock message"}
+    expected_status = {
+        "id": "test.id",
+        "status": "processing",
+        "latest_job": "a123",
+    }
+    assert json.loads(result.output) == expected_status