Add beginning of archiver

This commit is contained in:
Serene-Arc
2021-03-13 20:18:30 +10:00
committed by Ali Parlakci
parent a93813ca45
commit 959b55a939
8 changed files with 198 additions and 5 deletions

View File

@@ -0,0 +1,32 @@
#!/usr/bin/env python3
# coding=utf-8
import praw
import pytest
from bulkredditdownloader.archive_entry import ArchiveEntry
@pytest.mark.online
@pytest.mark.reddit
@pytest.mark.parametrize(('test_submission_id', 'min_comments'), (
('m3reby', 27),
))
def test_get_comments(test_submission_id: str, min_comments: int, reddit_instance: praw.Reddit):
test_submission = reddit_instance.submission(id=test_submission_id)
test_archive_entry = ArchiveEntry(test_submission)
test_archive_entry._get_comments()
assert len(test_archive_entry.comments) >= min_comments
@pytest.mark.online
@pytest.mark.reddit
@pytest.mark.parametrize(('test_submission_id', 'expected_dict'), (
('m3reby', {'author': 'sinjen-tos', 'id': 'm3reby', 'link_flair_text': 'image'}),
('m3kua3', {'author': 'DELETED'}),
))
def test_get_post_details(test_submission_id: str, expected_dict: dict, reddit_instance: praw.Reddit):
test_submission = reddit_instance.submission(id=test_submission_id)
test_archive_entry = ArchiveEntry(test_submission)
test_archive_entry._get_post_details()
assert all([test_archive_entry.post_details[key] == expected_dict[key] for key in expected_dict.keys()])

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env python3
# coding=utf-8
from pathlib import Path
from unittest.mock import MagicMock
import praw
import pytest
from bulkredditdownloader.archive_entry import ArchiveEntry
from bulkredditdownloader.archiver import Archiver
@pytest.mark.online
@pytest.mark.reddit
@pytest.mark.parametrize('test_submission_id', (
'm3reby',
))
def test_write_submission_json(test_submission_id: str, tmp_path: Path, reddit_instance: praw.Reddit):
archiver_mock = MagicMock()
test_path = Path(tmp_path, 'test.json')
test_submission = reddit_instance.submission(id=test_submission_id)
archiver_mock.file_name_formatter.format_path.return_value = test_path
test_entry = ArchiveEntry(test_submission)
Archiver._write_submission_json(archiver_mock, test_entry)
assert test_path.exists()
@pytest.mark.skip
def test_write_submission_xml():
raise NotImplementedError
@pytest.mark.skip
def test_write_submission_yaml():
raise NotImplementedError

View File

@@ -88,7 +88,7 @@ def test_format_full(
reddit_submission: praw.models.Submission):
test_resource = Resource(reddit_submission, 'i.reddit.com/blabla.png')
test_formatter = FileNameFormatter(format_string_file, format_string_directory)
result = test_formatter._format_path(test_resource, Path('test'))
result = test_formatter.format_path(test_resource, Path('test'))
assert str(result) == expected
@@ -109,7 +109,7 @@ def test_format_full_with_index_suffix(
reddit_submission: praw.models.Submission):
test_resource = Resource(reddit_submission, 'i.reddit.com/blabla.png')
test_formatter = FileNameFormatter(format_string_file, format_string_directory)
result = test_formatter._format_path(test_resource, Path('test'), index)
result = test_formatter.format_path(test_resource, Path('test'), index)
assert str(result) == expected
@@ -150,6 +150,6 @@ def test_shorten_filenames(reddit_instance: praw.Reddit, tmp_path: Path):
test_submission.id = 'BBBBBB'
test_resource = Resource(test_submission, 'www.example.com/empty', '.jpeg')
test_formatter = FileNameFormatter('{REDDITOR}_{TITLE}_{POSTID}', '{SUBREDDIT}')
result = test_formatter._format_path(test_resource, tmp_path)
result = test_formatter.format_path(test_resource, tmp_path)
result.parent.mkdir(parents=True)
result.touch()