Skip to content

Commit

Permalink
test(template): Update test imports after move
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatterson committed Oct 31, 2023
1 parent f64047b commit 52b4866
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 83 deletions.
7 changes: 3 additions & 4 deletions tests/prunerrtests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
import requests_mock

import prunerr
from .. import utils
from ..utils import pathlib
from prunerr.utils import pathlib


def parse_content_type(content_type): # pragma: no cover
Expand Down Expand Up @@ -242,10 +241,10 @@ def set_up_download_item_files(self, download_client_url):
torrent_list_mocks[0] / "response.json"
).open() as download_client_items_response:
self.download_client_items_responses[
utils.normalize_url(download_client_url.geturl())
prunerr.utils.normalize_url(download_client_url.geturl())
] = json.load(download_client_items_response)
for download_item in self.download_client_items_responses[
utils.normalize_url(download_client_url.geturl())
prunerr.utils.normalize_url(download_client_url.geturl())
]["arguments"]["torrents"]:
download_item_dir = (
self.tmp_path / download_item["downloadDir"].lstrip(os.path.sep)
Expand Down
8 changes: 4 additions & 4 deletions tests/prunerrtests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

from unittest import mock

import prunerr
import prunerrtests

from .. import tests
import prunerr


@mock.patch.dict(os.environ, tests.PrunerrTestCase.ENV)
class PrunerrCLITests(tests.PrunerrTestCase):
@mock.patch.dict(os.environ, prunerrtests.PrunerrTestCase.ENV)
class PrunerrCLITests(prunerrtests.PrunerrTestCase):
"""
Test the prunerr command-line interface.
"""
Expand Down
10 changes: 5 additions & 5 deletions tests/prunerrtests/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

from unittest import mock

import prunerr
import prunerrtests

from .. import tests
import prunerr

HOME = pathlib.Path(__file__).parent / "home" / "daemon"
ENV = dict(tests.PrunerrTestCase.ENV, HOME=str(HOME))
ENV = dict(prunerrtests.PrunerrTestCase.ENV, HOME=str(HOME))


class PrunerrDaemonTestException(BaseException):
Expand Down Expand Up @@ -68,7 +68,7 @@ def mock_exit_daemon_response(
"prunerr.runner.PrunerrRunner.EXAMPLE_CONFIG",
HOME / ".config" / "prunerr-example.yml",
)
class PrunerrDaemonTests(tests.PrunerrTestCase):
class PrunerrDaemonTests(prunerrtests.PrunerrTestCase):
"""
Tests covering the Prunerr `daemon` sub-command.
"""
Expand All @@ -77,7 +77,7 @@ class PrunerrDaemonTests(tests.PrunerrTestCase):
CONFIG = HOME / ".config" / "prunerr.yml"
ENV = ENV

RESPONSES_DIR = tests.PrunerrTestCase.RESPONSES_DIR.parent / "daemon"
RESPONSES_DIR = prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "daemon"

def test_daemon_command(self):
"""
Expand Down
14 changes: 8 additions & 6 deletions tests/prunerrtests/test_downloadclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@

from unittest import mock

import prunerrtests

import prunerr.runner
import prunerr.downloadclient

from .. import tests


@mock.patch.dict(os.environ, tests.PrunerrTestCase.ENV)
class PrunerrDownloadClientTests(tests.PrunerrTestCase):
@mock.patch.dict(os.environ, prunerrtests.PrunerrTestCase.ENV)
class PrunerrDownloadClientTests(prunerrtests.PrunerrTestCase):
"""
Test the aggregation of download client configurations.
"""

HOME = pathlib.Path(__file__).parent / "home" / "download-clients"
CONFIG = HOME / ".config" / "prunerr.yml"
ENV = dict(tests.PrunerrTestCase.ENV, HOME=str(HOME))
ENV = dict(prunerrtests.PrunerrTestCase.ENV, HOME=str(HOME))

RESPONSES_DIR = tests.PrunerrTestCase.RESPONSES_DIR.parent / "download-clients"
RESPONSES_DIR = (
prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "download-clients"
)

SERVARR_DOWNLOAD_CLIENT_URLS = (
# The usual case
Expand Down
12 changes: 6 additions & 6 deletions tests/prunerrtests/test_downloaditem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@

from unittest import mock

import prunerr.runner
import prunerrtests

from .. import tests
import prunerr


@mock.patch.dict(os.environ, tests.PrunerrTestCase.ENV)
class PrunerrDownloadItemTests(tests.PrunerrTestCase):
@mock.patch.dict(os.environ, prunerrtests.PrunerrTestCase.ENV)
class PrunerrDownloadItemTests(prunerrtests.PrunerrTestCase):
"""
Test the aggregation of download item configurations.
"""

HOME = pathlib.Path(__file__).parent / "home" / "download-items"
CONFIG = HOME / ".config" / "prunerr.yml"
ENV = dict(tests.PrunerrTestCase.ENV, HOME=str(HOME))
ENV = dict(prunerrtests.PrunerrTestCase.ENV, HOME=str(HOME))

RESPONSES_DIR = tests.PrunerrTestCase.RESPONSES_DIR.parent / "download-items"
RESPONSES_DIR = prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "download-items"

def test_download_item_missing_files(self):
"""
Expand Down
38 changes: 23 additions & 15 deletions tests/prunerrtests/test_free_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@

from unittest import mock

import prunerr.downloadclient
import prunerrtests

from .. import utils
from .. import tests
import prunerr


@mock.patch.dict(os.environ, tests.PrunerrTestCase.ENV)
class PrunerrFreeSpaceTests(tests.PrunerrTestCase):
@mock.patch.dict(os.environ, prunerrtests.PrunerrTestCase.ENV)
class PrunerrFreeSpaceTests(prunerrtests.PrunerrTestCase):
"""
Prunerr removes imported items to free space according to configured rules.
"""

RESPONSES_DIR = (
tests.PrunerrTestCase.RESPONSES_DIR.parent / "free-space-imported-sufficient"
prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent
/ "free-space-imported-sufficient"
)

def test_free_space_workflow(self):
Expand Down Expand Up @@ -190,21 +190,21 @@ def test_free_space_exec(self):
"Free Space results missing from `exec` sub-command results",
)
self.assertIn(
utils.normalize_url(self.download_client_urls[0]),
prunerr.utils.normalize_url(self.download_client_urls[0]),
exec_results["free-space"],
"Download client free space results missing from `exec` results",
)
self.assertIsInstance(
exec_results["free-space"][
utils.normalize_url(self.download_client_urls[0])
prunerr.utils.normalize_url(self.download_client_urls[0])
],
list,
"Download client free space results wrong type from `exec` results",
)
self.assertEqual(
len(
exec_results["free-space"][
utils.normalize_url(self.download_client_urls[0])
prunerr.utils.normalize_url(self.download_client_urls[0])
]
),
1,
Expand All @@ -225,18 +225,22 @@ def test_free_space_unregistered(self):
unregistered_results = runner.free_space()
self.assert_request_mocks(unregistered_request_mocks)
self.assertIn(
utils.normalize_url(self.download_client_urls[0]),
prunerr.utils.normalize_url(self.download_client_urls[0]),
unregistered_results,
"Download client free space results missing from unregistered item results",
)
self.assertIsInstance(
unregistered_results[utils.normalize_url(self.download_client_urls[0])],
unregistered_results[
prunerr.utils.normalize_url(self.download_client_urls[0])
],
list,
"Download client free space results wrong unregistered item results type",
)
self.assertEqual(
len(
unregistered_results[utils.normalize_url(self.download_client_urls[0])]
unregistered_results[
prunerr.utils.normalize_url(self.download_client_urls[0])
]
),
1,
"Free space unregistered item results wrong number of items",
Expand All @@ -258,17 +262,21 @@ def test_free_space_orphans(self):
orphans_results = runner.free_space()
self.assert_request_mocks(orphans_request_mocks)
self.assertIn(
utils.normalize_url(self.download_client_urls[0]),
prunerr.utils.normalize_url(self.download_client_urls[0]),
orphans_results,
"Download client free space results missing from orphan results",
)
self.assertIsInstance(
orphans_results[utils.normalize_url(self.download_client_urls[0])],
orphans_results[prunerr.utils.normalize_url(self.download_client_urls[0])],
list,
"Download client free space results wrong orphan results type",
)
self.assertEqual(
len(orphans_results[utils.normalize_url(self.download_client_urls[0])]),
len(
orphans_results[
prunerr.utils.normalize_url(self.download_client_urls[0])
]
),
1,
"Free space orphan results wrong number of items",
)
Expand Down
35 changes: 17 additions & 18 deletions tests/prunerrtests/test_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@

from unittest import mock

import prunerr.servarr
import prunerrtests

from .. import utils
from .. import tests
import prunerr


@mock.patch.dict(os.environ, tests.PrunerrTestCase.ENV)
class PrunerrMoveTests(tests.PrunerrTestCase):
@mock.patch.dict(os.environ, prunerrtests.PrunerrTestCase.ENV)
class PrunerrMoveTests(prunerrtests.PrunerrTestCase):
"""
Test moving download items that Servarr has acted on.
"""

RESPONSES_DIR = tests.PrunerrTestCase.RESPONSES_DIR.parent / "move-ungrabbed"
RESPONSES_DIR = prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "move-ungrabbed"

def test_move_usual_lifecycle(
self,
Expand Down Expand Up @@ -87,7 +86,7 @@ def test_move_usual_lifecycle(
# enough to match the item to the correct `dirId`, IOW `seriesId` or
# `movieId` so that further history lookups are much more efficient.
grabbed_request_mocks = self.mock_responses(
tests.PrunerrTestCase.RESPONSES_DIR.parent / "move-grabbed",
prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "move-grabbed",
)
prunerr.main(args=[f"--config={self.CONFIG}", "move"])
self.assert_request_mocks(grabbed_request_mocks)
Expand Down Expand Up @@ -120,7 +119,7 @@ def test_move_usual_lifecycle(
# Ensure the test fixture is correct that the download item has finished
# downloading in the download client.
completed_responses_dir = (
tests.PrunerrTestCase.RESPONSES_DIR.parent / "move-completed"
prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "move-completed"
)
download_items_response_path = (
completed_responses_dir
Expand Down Expand Up @@ -184,7 +183,7 @@ def test_move_usual_lifecycle(
# no changes.
self.mock_servarr_import_item()
completed_request_mocks = self.mock_responses(
tests.PrunerrTestCase.RESPONSES_DIR.parent / "move-completed",
prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "move-completed",
)
prunerr.main(args=[f"--config={self.CONFIG}", "move"])
self.assert_request_mocks(completed_request_mocks)
Expand Down Expand Up @@ -213,7 +212,7 @@ def test_move_usual_lifecycle(
# 5. The import event becomes visible in the Servarr API history. The item is
# moved from `downloads` to `seeding`.
import_request_mocks = self.mock_responses(
tests.PrunerrTestCase.RESPONSES_DIR.parent / "move-import",
prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "move-import",
# Insert a dynamic response mock to handle moving imported download items
{
"http://transmission:secret@localhost:9091/transmission/rpc": {
Expand Down Expand Up @@ -257,7 +256,7 @@ def test_move_usual_lifecycle(
# no changes.
self.mock_servarr_delete_file()
imported_request_mocks = self.mock_responses(
tests.PrunerrTestCase.RESPONSES_DIR.parent / "move-imported",
prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "move-imported",
)
prunerr.main(args=[f"--config={self.CONFIG}", "move"])
self.assert_request_mocks(imported_request_mocks)
Expand Down Expand Up @@ -286,7 +285,7 @@ def test_move_usual_lifecycle(
# 7. The delete event becomes visible in the Servarr API history. Running the
# `move` sub-command results in no changes.
deleted_request_mocks = self.mock_responses(
tests.PrunerrTestCase.RESPONSES_DIR.parent / "move-deleted",
prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "move-deleted",
)
prunerr.main(args=[f"--config={self.CONFIG}", "move"])
self.assert_request_mocks(deleted_request_mocks)
Expand Down Expand Up @@ -323,7 +322,7 @@ def test_move_imported_before(self):
self.mock_download_client_complete_item()
self.mock_servarr_import_item()
imported_before_request_mocks = self.mock_responses(
tests.PrunerrTestCase.RESPONSES_DIR.parent / "move-imported-before",
prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "move-imported-before",
# Insert a dynamic response mock to handle moving imported download items
{
"http://transmission:secret@localhost:9091/transmission/rpc": {
Expand Down Expand Up @@ -373,7 +372,7 @@ def test_move_exec(self):
/ "prunerr.yml",
)
self.mock_responses(
tests.PrunerrTestCase.RESPONSES_DIR.parent / "move-import",
prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "move-import",
# Insert a dynamic response mock to handle moving imported download items
{
"http://transmission:secret@localhost:9091/transmission/rpc": {
Expand All @@ -398,21 +397,21 @@ def test_move_exec(self):
"Servarr move results missing from `exec` sub-command results",
)
self.assertIn(
utils.normalize_url(self.download_client_urls[0]),
prunerr.utils.normalize_url(self.download_client_urls[0]),
exec_results["move"][self.servarr_urls[0]],
"Download client move results missing from `exec` sub-command results",
)
self.assertIsInstance(
exec_results["move"][self.servarr_urls[0]][
utils.normalize_url(self.download_client_urls[0])
prunerr.utils.normalize_url(self.download_client_urls[0])
],
list,
"Download client move results wrong type from `exec` sub-command results",
)
self.assertEqual(
len(
exec_results["move"][self.servarr_urls[0]][
utils.normalize_url(self.download_client_urls[0])
prunerr.utils.normalize_url(self.download_client_urls[0])
]
),
1,
Expand All @@ -427,7 +426,7 @@ def test_move_timeout(self):
self.mock_servarr_import_item()
runner = prunerr.runner.PrunerrRunner(config=self.CONFIG)
self.mock_responses(
tests.PrunerrTestCase.RESPONSES_DIR.parent / "move-import",
prunerrtests.PrunerrTestCase.RESPONSES_DIR.parent / "move-import",
# Insert a dynamic response mock to handle moving imported download items
{
"http://transmission:secret@localhost:9091/transmission/rpc": {
Expand Down
7 changes: 4 additions & 3 deletions tests/prunerrtests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@

from unittest import mock

import prunerrtests

import prunerr.runner
import prunerr.downloadclient
import prunerr.downloaditem
import prunerr.operations

from .. import tests
from . import test_downloaditem


@mock.patch.dict(os.environ, tests.PrunerrTestCase.ENV)
class PrunerrDownloadItemTests(tests.PrunerrTestCase):
@mock.patch.dict(os.environ, prunerrtests.PrunerrTestCase.ENV)
class PrunerrDownloadItemTests(prunerrtests.PrunerrTestCase):
"""
Test Prunerr's configurable operations.
"""
Expand Down

0 comments on commit 52b4866

Please sign in to comment.