Skip to content

Commit

Permalink
Add tests for download_content function
Browse files Browse the repository at this point in the history
  • Loading branch information
rocktimsaikia committed Sep 2, 2024
1 parent b711e8d commit d893cff
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
19 changes: 18 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ emoji = "^2.12.1"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.2"
requests-mock = "^1.12.1"

[build-system]
requires = ["poetry-core"]
Expand Down
27 changes: 27 additions & 0 deletions tests/download_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import shutil

from github_dlr.source import download_content


def test_download_content_succes(requests_mock):
download_url = "https://github.com/AnimeChan/animechan/tree/main/client/public"
mock_content = b"This is an image content"

requests_mock.get(download_url, content=mock_content)

# Create a temp dir `tmp` to store the test files
output_dir = "tmp"
output_file = os.path.join(output_dir, "foo.txt")
os.makedirs(output_dir)

# Download the file content and save it locally
download_content(download_url, output_file)

try:
# Verify the file was written correctly
with open(output_file, "rb") as file:
assert file.read() == mock_content
finally:
if os.path.exists(output_file):
shutil.rmtree(output_dir)
File renamed without changes.

0 comments on commit d893cff

Please sign in to comment.