Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests suite #120

Merged
merged 18 commits into from
Apr 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: Add tests for get_city_station_options
  • Loading branch information
lahdjirayhan committed Apr 21, 2022
commit 8c9b01fa64e6a67e7f9279c75bb045b9fdcee2b1
55 changes: 55 additions & 0 deletions tests/test_get_city_station_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pandas
import pandas.api.types as pd_types
import pytest

from utils import api, DEFAULT_OUTPUT_FOLDER


@pytest.mark.vcr
def test_return_value_and_format():
result = api.get_city_station_options("ukraine")
assert isinstance(result, pandas.DataFrame)
assert len(result) > 0 # Shouldn't be empty for 'ukraine'...


@pytest.mark.vcr
def test_columns():
result = api.get_city_station_options("ukraine")

# Check all columns exist
COLUMNS = ["city_id", "country_code", "station_name", "city_url", "score"]
assert all([col in result for col in COLUMNS])


@pytest.mark.vcr
def test_score_column():
result = api.get_city_station_options("ukraine")

# Make sure score is numeric
assert pd_types.is_numeric_dtype(result["score"])

# Make sure score is descending
score = result["score"].tolist()
assert score == sorted(score, reverse=True)


@pytest.mark.vcr
def test_nonexistent_city():
# Shouldn't raise Exception, instead ...
result = api.get_city_station_options("gibberish_nonexistent_place_name")

# ... should return a dataframe but with length 0 ...
assert isinstance(result, pandas.DataFrame)
assert len(result) == 0

# ... and with all columns just like usual.
COLUMNS = ["city_id", "country_code", "station_name", "city_url", "score"]
assert all([col in result for col in COLUMNS])


@pytest.mark.vcr
def test_no_output_directory():
api.get_city_station_options("ukraine")

# There shouldn't be an output folder after calling this method
assert not DEFAULT_OUTPUT_FOLDER.exists()