From 00b3f5273f7a1c9985d3d3562f89436182a735c1 Mon Sep 17 00:00:00 2001 From: "Kharude, Sachin" Date: Sun, 28 Feb 2021 10:45:28 +0530 Subject: [PATCH] Added tests Signed-off-by: Kharude, Sachin --- Makefile | 8 ++---- tests/test_here.py | 34 ++++++++++++++++++++++++ tests/test_mapbox.py | 61 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index b0c3d11..7411df5 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/tests/test_here.py b/tests/test_here.py index 14c9c19..d1ddc04 100644 --- a/tests/test_here.py +++ b/tests/test_here.py @@ -1,5 +1,6 @@ """Module to test HERE services.""" import json +import os from click.testing import CliRunner @@ -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( @@ -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 diff --git a/tests/test_mapbox.py b/tests/test_mapbox.py index 0617ec5..a3af35e 100644 --- a/tests/test_mapbox.py +++ b/tests/test_mapbox.py @@ -1,4 +1,6 @@ """Module to test MapBox services.""" +import os + from click.testing import CliRunner from maps.commands import maps @@ -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( @@ -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( @@ -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