Skip to content

Commit

Permalink
Merge pull request #29 from mapbox/install-fixes
Browse files Browse the repository at this point in the history
handing non json response + requirements in setup
  • Loading branch information
dnomadb authored Oct 8, 2019
2 parents 0669fab + ed16bfb commit 5c07070
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.3.2 (2019-10-08)
- Handling for non-json response from recipe validation
- Adding cligj to setup for install w/o requirements

# 0.3.1 (2019-10-01)
- Fixed bug for list tilesets

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from codecs import open as codecs_open
from setuptools import setup, find_packages

from tilesets import __version__

# Get the long description from the relevant file
with codecs_open("README.md", encoding="utf-8") as f:
Expand All @@ -14,7 +15,7 @@ def read(fname):

setup(
name="tilesets-cli",
version="0.3.1",
version=__version__,
description=u"CLI for interacting with and preparing data for the Tilesets API",
long_description=long_description,
classifiers=[],
Expand All @@ -27,6 +28,7 @@ def read(fname):
install_requires=[
"boto3",
"click~=7.0",
"cligj",
"requests",
"jsonschema~=3.0",
"jsonseq~=1.0",
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import json

from json.decoder import JSONDecodeError


@pytest.fixture(scope="function")
def token_environ(monkeypatch):
Expand All @@ -18,6 +20,10 @@ def MockResponse(self):
return self

def json(self):
# 201 currently do not have a json response
if self.status_code == 201:
raise JSONDecodeError("Expecting value", "", 0)

return self._json


Expand Down
13 changes: 11 additions & 2 deletions tests/test_cli_update_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from unittest import mock
import pytest

from json.decoder import JSONDecodeError

from tilesets.scripts.cli import update_recipe


Expand All @@ -19,7 +21,7 @@ def test_cli_update_recipe(mock_request_patch, MockResponse):
runner = CliRunner()

# sends expected request
mock_request_patch.return_value = MockResponse("", status_code=201)
mock_request_patch.return_value = MockResponse({}, status_code=201)
result = runner.invoke(update_recipe, ["test.id", "tests/fixtures/recipe.json"])
mock_request_patch.assert_called_with(
"https://api.mapbox.com/tilesets/v1/test.id/recipe?access_token=fake-token",
Expand All @@ -32,7 +34,8 @@ def test_cli_update_recipe(mock_request_patch, MockResponse):
@mock.patch("requests.patch")
def test_cli_update_recipe2(mock_request_patch, MockResponse):
runner = CliRunner()
mock_request_patch.return_value = MockResponse("", status_code=201)

mock_request_patch.return_value = MockResponse({}, status_code=201)
# Provides the flag --token
result = runner.invoke(
update_recipe,
Expand All @@ -43,3 +46,9 @@ def test_cli_update_recipe2(mock_request_patch, MockResponse):
json={"minzoom": 0, "maxzoom": 10, "layer_name": "test_layer"},
)
assert result.exit_code == 0


def test_201_mocking(MockResponse):
mocker = MockResponse({}, status_code=201)
with pytest.raises(JSONDecodeError):
mocker.json()
7 changes: 7 additions & 0 deletions tests/test_version_documentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from tilesets import __version__


def test_versions():
mod_version = __version__
with open("./CHANGELOG.md") as src:
assert len([l in l for l in src if mod_version in l]) == 1
2 changes: 1 addition & 1 deletion tilesets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""tilesets package"""

__version__ = "0.3.1"
__version__ = "0.3.2"
2 changes: 1 addition & 1 deletion tilesets/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def update_recipe(tileset, recipe, token=None, indent=None):
r = requests.patch(url, json=recipe_json)
if r.status_code == 201:
click.echo("Updated recipe.", err=True)
click.echo(json.dumps(r.json(), indent=indent))
click.echo(r.text)
else:
raise errors.TilesetsError(r.text)

Expand Down

0 comments on commit 5c07070

Please sign in to comment.