Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kharude, Sachin <[email protected]>
  • Loading branch information
Kharude, Sachin committed Feb 28, 2021
1 parent 394f949 commit 00b3f52
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
.PHONY: all build install typing lint test
.PHONY: all install lint test

all: black build install typing lint test
all: black install lint test

black:
black -l 99 maps tests
isort --atomic .

#build:
# python3 -m pip install -r requirements.txt

clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts

Expand Down Expand Up @@ -36,8 +34,6 @@ clean-test: ## remove test and coverage artifacts
install:
python3 -m pip install -e .

#typing:
# pytest -v -s --mypy maps

lint:
isort --check --diff maps tests
Expand Down
34 changes: 34 additions & 0 deletions tests/test_here.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Module to test HERE services."""
import json
import os

from click.testing import CliRunner

Expand Down Expand Up @@ -42,6 +43,19 @@ def test_geocoding_reverse():
assert raw_result.exit_code == 0


def test_geocoding_exception():
api_key = os.environ["HERE_APIKEY"]
try:
del os.environ["HERE_APIKEY"]
runner = CliRunner()
result = runner.invoke(
maps, ["here", "geocoding", "--forward", "springfield"], catch_exceptions=False
)
finally:
os.environ["HERE_APIKEY"] = api_key
assert result.exit_code == 2


def test_discover():
runner = CliRunner()
result = runner.invoke(
Expand Down Expand Up @@ -78,3 +92,23 @@ def test_discover():
)
assert result3.exit_code == 0
assert "Starbucks, Am Ostbahnhof, 10243 Berlin, Germany" in result3.output


def test_discover_exception():
api_key = os.environ["HERE_APIKEY"]
try:
del os.environ["HERE_APIKEY"]
runner = CliRunner()
result = runner.invoke(
maps,
[
"here",
"discover",
"starbucks",
"--coordinates=72.8526,19.1663",
"--country_codes=IND",
],
)
finally:
os.environ["HERE_APIKEY"] = api_key
assert result.exit_code == 2
61 changes: 61 additions & 0 deletions tests/test_mapbox.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Module to test MapBox services."""
import os

from click.testing import CliRunner

from maps.commands import maps
Expand Down Expand Up @@ -39,6 +41,19 @@ def test_geocoding_reverse():
assert raw_result.exit_code == 0


def test_geocoding_exception():
api_key = os.environ["MAPBOX_APIKEY"]
try:
del os.environ["MAPBOX_APIKEY"]
runner = CliRunner()
result = runner.invoke(
maps, ["mapbox", "geocoding", "--forward", "springfield"], catch_exceptions=False
)
finally:
os.environ["MAPBOX_APIKEY"] = api_key
assert result.exit_code == 2


def test_isochrone():
runner = CliRunner()
result = runner.invoke(
Expand All @@ -58,6 +73,29 @@ def test_isochrone():
assert "FeatureCollection" in result.output


def test_isochrone_exception():
api_key = os.environ["MAPBOX_APIKEY"]
try:
del os.environ["MAPBOX_APIKEY"]
runner = CliRunner()
result = runner.invoke(
maps,
[
"mapbox",
"isochrone",
"--profile=driving",
"--coordinates=-118.22258,33.99038",
"--contours_minutes=5",
"--contours_colors=6706ce",
"--polygons",
],
catch_exceptions=False,
)
finally:
os.environ["MAPBOX_APIKEY"] = api_key
assert result.exit_code == 2


def test_matrix():
runner = CliRunner()
result = runner.invoke(
Expand All @@ -75,3 +113,26 @@ def test_matrix():
)
assert result.exit_code == 0
assert '"code": "Ok"' in result.output


def test_matrix_exception():
api_key = os.environ["MAPBOX_APIKEY"]
try:
del os.environ["MAPBOX_APIKEY"]
runner = CliRunner()
result = runner.invoke(
maps,
[
"mapbox",
"matrix",
"--profile=driving",
"--coordinates=-122.42,37.78;-122.45,37.91;-122.48,37.73",
"--annotations=distance,duration",
"--approaches=curb;curb;curb",
"--destinations=all",
],
catch_exceptions=False,
)
finally:
os.environ["MAPBOX_APIKEY"] = api_key
assert result.exit_code == 2

0 comments on commit 00b3f52

Please sign in to comment.