Skip to content

Commit

Permalink
Merge pull request #37 from dbatten5/imdb-id
Browse files Browse the repository at this point in the history
Imdb id
  • Loading branch information
dbatten5 authored Nov 18, 2021
2 parents 5d4fedc + ffd2c58 commit 04b67ad
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "phylm"
version = "4.2.0"
version = "4.2.1"
description = "Phylm"
authors = ["Dom Batten <[email protected]>"]
license = "MIT"
Expand Down
12 changes: 12 additions & 0 deletions src/phylm/sources/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ def title(self) -> Optional[str]:

return str(self._imdb_data.get("title"))

@property
def id(self) -> Optional[str]:
"""Return the IMDb id.
Returns:
the id of the movie
"""
if not self._imdb_data:
return None

return str(self._imdb_data.movieID)

def genres(self, limit: int = 3) -> List[str]:
"""Return the genres.
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/sources/test_imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,36 @@ def test_no_results(self, mock_ia: MagicMock) -> None:
assert imdb.runtime is None


class TestId:
"""Tests for the `id` property."""

@patch(IMDB_IA_PATH)
def test_year(self, mock_ia: MagicMock, the_matrix: Movie) -> None:
"""
Given a match with id,
When the year is retrieved,
Then the id is returned
"""
mock_ia.search_movie.return_value = [the_matrix]

imdb = Imdb("The Matrix")

assert imdb.id == "0133093"

@patch(IMDB_IA_PATH)
def test_no_results(self, mock_ia: MagicMock) -> None:
"""
Given no search results,
When the id is retrieved,
Then `None` is returned
"""
mock_ia.search_movie.return_value = []

imdb = Imdb("The Matrix")

assert imdb.id is None


class TestYear:
"""Tests for the `year` method."""

Expand Down

0 comments on commit 04b67ad

Please sign in to comment.