Skip to content

Commit

Permalink
Add mock test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yao-Wen-Chang committed May 31, 2024
1 parent 6eb7e2a commit 020d5e4
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tests/test_pypistats.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,21 @@ def test_format_pandas(self) -> None:
assert isinstance(output, pandas.DataFrame)
assert str(output).strip() == expected_output.strip()

def test__package_not_exist(self) -> None:
@respx.mock
def test_package_not_exist(self) -> None:
# Arrange
package = "a" * 100
result = pypistats.python_major(package)
mocked_response = """{
"data":[],
"package":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"type":"python_major_downloads"
}"""
mocked_url = f"https://pypistats.org/api/packages/{package}/python_major"
expected_output = f"The package '{package}' does not exist"

# Act
respx.get(mocked_url).respond(content=mocked_response)
output = pypistats.python_major(package)

# Assert
assert result == f"The package '{package}' does not exist"
assert output == expected_output

0 comments on commit 020d5e4

Please sign in to comment.