Skip to content

Commit

Permalink
Merge pull request #83 from questionlp/develop
Browse files Browse the repository at this point in the history
Add retrieve random methods for guests, hosts, locations, panelists, scorekeepers and shows
  • Loading branch information
questionlp authored Feb 1, 2025
2 parents 19c0551 + 4ab81ec commit a9972c2
Show file tree
Hide file tree
Showing 14 changed files with 799 additions and 64 deletions.
24 changes: 24 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
Changes
*******

2.16.0
======

Application Changes
-------------------

* Add ``retrieve_random()``, ``retrieve_random_id()``, ``retrieve_random_slug()``, ``retrieve_random_date()`` and ``retrieve_random_details()`` to the following classes that mirror the corresponding feature in the `Wait Wait Stats Page`_

* :py:class:`wwdtm.guest.Guest`
* :py:class:`wwdtm.host.Host`
* :py:class:`wwdtm.location.Location`
* :py:class:`wwdtm.panelist.Panelist`
* :py:class:`wwdtm.scorekeeper.Scorekeeper`
* :py:class:`wwdtm.show.Show`

Development Changes
-------------------

* Add corresponding tests for the new series of retrieve random items
* Fixed typos in docstrings or testing assertion messages

2.15.0
======

Expand Down Expand Up @@ -588,3 +609,6 @@ Application Changes
* More detailed documentation, including changes from the previous library to
``wwdtm`` version 2, is available under ``docs/`` and is published at:
https://docs.wwdt.me/en/latest/migrating/index.html


.. _Wait Wait Stats Page: https://stats.wwdt.me/
39 changes: 38 additions & 1 deletion tests/guest/test_guest_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_guest_retrieve_details_by_id(guest_id: int):
info = guest.retrieve_details_by_id(guest_id)

assert info, f"Guest ID {guest_id} not found"
assert "name" in info, f"'name' attribute was returned for ID {guest_id}"
assert "name" in info, f"'name' attribute was not returned for ID {guest_id}"
assert "appearances" in info, f"'appearances' was not returned for ID {guest_id}"


Expand All @@ -120,3 +120,40 @@ def test_guest_guest_retrieve_details_by_slug(guest_slug: str):
assert "appearances" in info, (
f"'appearances' was not returned for slug {guest_slug}"
)


def test_guest_retrieve_random_id() -> None:
"""Testing for :py:meth`wwdtm.guest.Guest.retrieve_random_id`."""
guest = Guest(connect_dict=get_connect_dict())
_id = guest.retrieve_random_id()

assert _id, "Returned random guest ID is not valid"
assert isinstance(_id, int), "Returned random guest ID is not an integer"


def test_guest_retrieve_random_slug() -> None:
"""Testing for :py:meth`wwdtm.guest.Guest.retrieve_random_slug`."""
guest = Guest(connect_dict=get_connect_dict())
_slug = guest.retrieve_random_slug()

assert _slug, "Returned random guest slug string is not valid"
assert isinstance(_slug, str), "Returned random guest slug string is not a string"


def test_guest_retrieve_random() -> None:
"""Testing for :py:meth:`wwdtm.guest.Guest.retrieve_random`."""
guest = Guest(connect_dict=get_connect_dict())
info = guest.retrieve_random()

assert info, "Random guest not found"
assert "name" in info, "'name' attribute was not returned for a random guest"


def test_guest_retrieve_random_details() -> None:
"""Testing for :py:meth:`wwdtm.guest.Guest.retrieve_random_details`."""
guest = Guest(connect_dict=get_connect_dict())
info = guest.retrieve_random_details()

assert info, "Random guest not found"
assert "name" in info, "'name' attribute was not returned for a random guest"
assert "appearances" in info, "'appearances' was not returned for a random guest"
41 changes: 41 additions & 0 deletions tests/host/test_host_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,44 @@ def test_host_retrieve_details_by_slug(host_slug: str):
assert "slug" in info, f"'slug' was not returned for ID {host_slug}"
assert "pronouns" in info, f"'pronouns' was not returned for ID {host_slug}"
assert "appearances" in info, f"'appearances' was not returned for slug {host_slug}"


def test_host_retrieve_random_id() -> None:
"""Testing for :py:meth`wwdtm.host.Host.retrieve_random_id`."""
host = Host(connect_dict=get_connect_dict())
_id = host.retrieve_random_id()

assert _id, "Returned random host ID is not valid"
assert isinstance(_id, int), "Returned random host ID is not an integer"


def test_host_retrieve_random_slug() -> None:
"""Testing for :py:meth`wwdtm.host.Host.retrieve_random_slug`."""
host = Host(connect_dict=get_connect_dict())
_slug = host.retrieve_random_slug()

assert _slug, "Returned random host slug string is not valid"
assert isinstance(_slug, str), "Returned random host slug string is not a string"


def test_host_retrieve_random() -> None:
"""Testing for :py:meth:`wwdtm.host.Host.retrieve_random`."""
host = Host(connect_dict=get_connect_dict())
info = host.retrieve_random()

assert info, "Random host not found"
assert "name" in info, "'name' attribute was not returned for a random host"
assert "slug" in info, "'slug' was not returned for a random host"
assert "pronouns" in info, "'pronouns' was not returned for a random host"


def test_host_retrieve_random_details() -> None:
"""Testing for :py:meth:`wwdtm.host.Host.retrieve_random_details`."""
host = Host(connect_dict=get_connect_dict())
info = host.retrieve_random_details()

assert info, "Random host not found"
assert "name" in info, "'name' attribute was not returned for a random host"
assert "slug" in info, "'slug' was not returned for a random host"
assert "pronouns" in info, "'pronouns' was not returned for a random host"
assert "appearances" in info, "'appearances' was not returned for a random host"
153 changes: 96 additions & 57 deletions tests/location/test_location_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ def test_location_retrieve_all():
assert locations, "No locations could be retrieved"
assert "id" in locations[0], "'id' was not returned for the first list item"
assert "venue" in locations[0], "'venue' was not returned for the first list item"
assert (
"coordinates" in locations[0]
), "'coordinates' was not returned for the first list item"
assert "coordinates" in locations[0], (
"'coordinates' was not returned for the first list item"
)
if locations[0]["coordinates"]:
assert (
"latitude" in locations[0]["coordinates"]
), "'latitude' was not returned for the first list item"
assert (
"longitude" in locations[0]["coordinates"]
), "'longitude' was not returned for the first list item"
assert "latitude" in locations[0]["coordinates"], (
"'latitude' was not returned for the first list item"
)
assert "longitude" in locations[0]["coordinates"], (
"'longitude' was not returned for the first list item"
)


def test_location_retrieve_all_details():
Expand All @@ -56,19 +56,19 @@ def test_location_retrieve_all_details():
assert locations, "No locations could be retrieved"
assert "id" in locations[0], "'id' was not returned for first list item"
assert "venue" in locations[0], "'venue' was not returned for the first list item"
assert (
"coordinates" in locations[0]
), "'coordinates' was not returned for the first list item"
assert "coordinates" in locations[0], (
"'coordinates' was not returned for the first list item"
)
if locations[0]["coordinates"]:
assert (
"latitude" in locations[0]["coordinates"]
), "'latitude' was not returned for the first list item"
assert (
"longitude" in locations[0]["coordinates"]
), "'longitude' was not returned for the first list item"
assert (
"recordings" in locations[0]
), "'recordings' was not returned for the first list item"
assert "latitude" in locations[0]["coordinates"], (
"'latitude' was not returned for the first list item"
)
assert "longitude" in locations[0]["coordinates"], (
"'longitude' was not returned for the first list item"
)
assert "recordings" in locations[0], (
"'recordings' was not returned for the first list item"
)


def test_location_retrieve_all_ids():
Expand Down Expand Up @@ -101,12 +101,12 @@ def test_location_retrieve_by_id(location_id: int):
assert "venue" in info, f"'venue' was not returned for ID {location_id}"
assert "coordinates" in info, f"'coordinates' was not returned for ID {location_id}"
if info["coordinates"]:
assert (
"latitude" in info["coordinates"]
), f"'latitude' was not returned for ID {location_id}"
assert (
"longitude" in info["coordinates"]
), f"'longitude' was not returned for ID {location_id}"
assert "latitude" in info["coordinates"], (
f"'latitude' was not returned for ID {location_id}"
)
assert "longitude" in info["coordinates"], (
f"'longitude' was not returned for ID {location_id}"
)


@pytest.mark.parametrize("location_id", [95, 148])
Expand All @@ -122,12 +122,12 @@ def test_location_retrieve_details_by_id(location_id: int):
assert "venue" in info, f"'venue' was not returned for ID {location_id}"
assert "coordinates" in info, f"'coordinates' was not returned for ID {location_id}"
if info["coordinates"]:
assert (
"latitude" in info["coordinates"]
), f"'latitude' was not returned for ID {location_id}"
assert (
"longitude" in info["coordinates"]
), f"'longitude' was not returned for ID {location_id}"
assert "latitude" in info["coordinates"], (
f"'latitude' was not returned for ID {location_id}"
)
assert "longitude" in info["coordinates"], (
f"'longitude' was not returned for ID {location_id}"
)
assert "recordings" in info, f"'recordings' was not returned for ID {location_id}"


Expand All @@ -143,16 +143,16 @@ def test_location_retrieve_by_slug(location_slug: str):

assert info, f"Location slug {location_slug} not found"
assert "venue" in info, f"'venue' was not returned for slug {location_slug}"
assert (
"coordinates" in info
), f"'coordinates' was not returned for slug {location_slug}"
assert "coordinates" in info, (
f"'coordinates' was not returned for slug {location_slug}"
)
if info["coordinates"]:
assert (
"latitude" in info["coordinates"]
), f"'latitude' was not returned for slug {location_slug}"
assert (
"longitude" in info["coordinates"]
), f"'longitude' was not returned for slug {location_slug}"
assert "latitude" in info["coordinates"], (
f"'latitude' was not returned for slug {location_slug}"
)
assert "longitude" in info["coordinates"], (
f"'longitude' was not returned for slug {location_slug}"
)


@pytest.mark.parametrize("location_slug", ["the-chicago-theatre-chicago-il"])
Expand All @@ -167,19 +167,19 @@ def test_location_retrieve_details_by_slug(location_slug: str):

assert info, f"Location slug {location_slug} not found"
assert "venue" in info, f"'venue' was not returned for slug {location_slug}"
assert (
"coordinates" in info
), f"'coordinates' was not returned for slug {location_slug}"
assert "coordinates" in info, (
f"'coordinates' was not returned for slug {location_slug}"
)
if info["coordinates"]:
assert (
"latitude" in info["coordinates"]
), f"'latitude' was not returned for slug {location_slug}"
assert (
"longitude" in info["coordinates"]
), f"'longitude' was not returned for slug {location_slug}"
assert (
"recordings" in info
), f"'recordings' was not returned for slug {location_slug}"
assert "latitude" in info["coordinates"], (
f"'latitude' was not returned for slug {location_slug}"
)
assert "longitude" in info["coordinates"], (
f"'longitude' was not returned for slug {location_slug}"
)
assert "recordings" in info, (
f"'recordings' was not returned for slug {location_slug}"
)


def test_location_retrieve_postal_abbreviations():
Expand All @@ -189,6 +189,45 @@ def test_location_retrieve_postal_abbreviations():

assert abbreviations, "Postal abbreviations not returned"
assert "OR" in abbreviations, "Postal abbreviation 'OR' not found"
assert (
"name" in abbreviations["OR"]
), "Postal abbreviation 'OR' does not contain a valid name"
assert "name" in abbreviations["OR"], (
"Postal abbreviation 'OR' does not contain a valid name"
)


def test_location_retrieve_random_id() -> None:
"""Testing for :py:meth`wwdtm.location.Location.retrieve_random_id`."""
location = Location(connect_dict=get_connect_dict())
_id = location.retrieve_random_id()

assert _id, "Returned random location ID is not valid"
assert isinstance(_id, int), "Returned random location ID is not an integer"


def test_location_retrieve_random_slug() -> None:
"""Testing for :py:meth`wwdtm.location.Location.retrieve_random_slug`."""
location = Location(connect_dict=get_connect_dict())
_slug = location.retrieve_random_slug()

assert _slug, "Returned random location slug string is not valid"
assert isinstance(_slug, str), (
"Returned random location slug string is not a string"
)


def test_location_retrieve_random() -> None:
"""Testing for :py:meth:`wwdtm.location.Location.retrieve_random`."""
location = Location(connect_dict=get_connect_dict())
info = location.retrieve_random()

assert info, "Random location not found"
assert "venue" in info, "'venue' attribute was not returned for a random location"


def test_location_retrieve_random_details() -> None:
"""Testing for :py:meth:`wwdtm.host.Location.retrieve_random_details`."""
location = Location(connect_dict=get_connect_dict())
info = location.retrieve_random_details()

assert info, "Random location not found"
assert "venue" in info, "'venue' attribute was not returned for a random location"
assert "coordinates" in info, "'coordinates' was not returned for a random location"
43 changes: 43 additions & 0 deletions tests/panelist/test_panelist_panelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,46 @@ def test_panelist_retrieve_details_by_slug(
assert "appearances" in info, (
f"'appearances' was not returned for slug {panelist_slug}"
)


def test_panelist_retrieve_random_id() -> None:
"""Testing for :py:meth`wwdtm.panelist.Panelist.retrieve_random_id`."""
panelist = Panelist(connect_dict=get_connect_dict())
_id = panelist.retrieve_random_id()

assert _id, "Returned random panelist ID is not valid"
assert isinstance(_id, int), "Returned random panelist ID is not an integer"


def test_panelist_retrieve_random_slug() -> None:
"""Testing for :py:meth`wwdtm.panelist.Panelist.retrieve_random_slug`."""
panelist = Panelist(connect_dict=get_connect_dict())
_slug = panelist.retrieve_random_slug()

assert _slug, "Returned random panelist slug string is not valid"
assert isinstance(_slug, str), (
"Returned random panelist slug string is not a string"
)


def test_panelist_retrieve_random() -> None:
"""Testing for :py:meth:`wwdtm.panelist.Panelist.retrieve_random`."""
panelist = Panelist(connect_dict=get_connect_dict())
info = panelist.retrieve_random()

assert info, "Random panelist not found"
assert "name" in info, "'name' attribute was not returned for a random panelist"
assert "slug" in info, "'slug' was not returned for a random panelist"
assert "pronouns" in info, "'pronouns' was not returned for a random panelist"


def test_panelist_retrieve_random_details() -> None:
"""Testing for :py:meth:`wwdtm.panelist.Panelist.retrieve_random_details`."""
panelist = Panelist(connect_dict=get_connect_dict())
info = panelist.retrieve_random_details()

assert info, "Random panelist not found"
assert "name" in info, "'name' attribute was not returned for a random panelist"
assert "slug" in info, "'slug' was not returned for a random panelist"
assert "pronouns" in info, "'pronouns' was not returned for a random panelist"
assert "appearances" in info, "'appearances' was not returned for a random panelist"
Loading

0 comments on commit a9972c2

Please sign in to comment.