This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
soft-analytics-01/tests/test_scraper_download.py
Claudio Maggioni 07232eddcc Final version of the bug-triaging project
Commit history has been discarded to remove large files from the repo.
2024-01-03 15:22:56 +01:00

73 lines
1.9 KiB
Python

import tarfile
from collections import defaultdict
import pytest
from src.scraper.download import (
download_page,
download_issue,
download_commit_activity,
)
@pytest.fixture
def valid_github_token():
return "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"
@pytest.fixture
def invalid_github_token():
return "ghp_invalid"
@pytest.fixture
def valid_issue_id():
return 192213 # Replace with a valid issue ID
@pytest.fixture
def invalid_issue_id():
return -1
def test_download_page_normal_execution(valid_github_token):
page = 1
tar_file_name = "test_archive.tar"
with tarfile.open(tar_file_name, "w") as tar_file:
result = download_page(page, valid_github_token, tar_file)
assert result is True
def test_download_page_invalid_page(valid_github_token):
page = -1 # Invalid page number
tar_file_name = "test_archive.tar"
with pytest.raises(ValueError):
with tarfile.open(tar_file_name, "w") as tar_file:
download_page(page, valid_github_token, tar_file)
def test_download_page_ok(valid_github_token):
page = 1
tar_file_name = "test_archive.tar"
with tarfile.open(tar_file_name, "w") as tar_file:
result = download_page(page, valid_github_token, tar_file)
assert result is True
def test_download_issue_valid_issue_id(valid_issue_id, valid_github_token):
result = download_issue(valid_issue_id, valid_github_token)
assert type(result) is dict
def test_download_issue_invalid_issue_id(invalid_issue_id, valid_github_token):
with pytest.raises(IOError):
download_issue(invalid_issue_id, valid_github_token)
def test_download_commit_activity_valid_token(valid_github_token):
result = download_commit_activity(valid_github_token)
assert type(result) is defaultdict
def test_download_commit_activity_invalid_token(invalid_github_token):
with pytest.raises(IOError):
download_commit_activity(invalid_github_token)