Wrote some unit tests to verify proper dispatching of the profile and server handling.pull/5/head
parent
47631c75c2
commit
8c31968bfc
@ -0,0 +1 @@
|
||||
from . import config, main, sonarr
|
@ -0,0 +1,25 @@
|
||||
from pathlib import Path
|
||||
|
||||
from app.logic import sonarr, config
|
||||
from app.cmd import setup_and_parse_args
|
||||
from app.logger import Logger
|
||||
from app.trash_error import TrashError
|
||||
|
||||
# --------------------------------------------------------------------------------------------------
|
||||
def main(root_directory):
|
||||
args = setup_and_parse_args()
|
||||
logger = Logger(args)
|
||||
|
||||
config.load_config(args, logger, root_directory)
|
||||
|
||||
subcommand_handlers = {
|
||||
('sonarr', 'profile'): sonarr.process_profile,
|
||||
('sonarr', 'quality'): sonarr.process_quality,
|
||||
}
|
||||
|
||||
server_name = args.type.split(':')[0]
|
||||
|
||||
try:
|
||||
subcommand_handlers[server_name, args.subcommand](args, logger)
|
||||
except KeyError:
|
||||
raise TrashError(f'{args.subcommand} support in {server_name} is not implemented yet')
|
@ -0,0 +1,20 @@
|
||||
import sys
|
||||
from app.logic import main
|
||||
|
||||
def test_main_sonarr_profile(mocker):
|
||||
test_args = ['trash.py', 'profile', 'sonarr:anime']
|
||||
mock_processor = mocker.patch('app.logic.sonarr.process_profile')
|
||||
mocker.patch.object(sys, 'argv', test_args)
|
||||
|
||||
main.main()
|
||||
|
||||
mock_processor.assert_called_once()
|
||||
|
||||
def test_main_sonarr_quality(mocker):
|
||||
test_args = ['trash.py', 'quality', 'sonarr:anime']
|
||||
mock_processor = mocker.patch('app.logic.sonarr.process_quality')
|
||||
mocker.patch.object(sys, 'argv', test_args)
|
||||
|
||||
main.main()
|
||||
|
||||
mock_processor.assert_called_once()
|
@ -1,33 +1,12 @@
|
||||
from pathlib import Path
|
||||
|
||||
from app.logic import sonarr, config
|
||||
from app.cmd import setup_and_parse_args
|
||||
from app.logger import Logger
|
||||
from app.logic.main import main
|
||||
from app.trash_error import TrashError
|
||||
|
||||
# --------------------------------------------------------------------------------------------------
|
||||
def main():
|
||||
args = setup_and_parse_args()
|
||||
logger = Logger(args)
|
||||
|
||||
config.load_config(args, logger, Path(__file__).parent)
|
||||
|
||||
if args.subcommand == 'profile':
|
||||
if args.type.startswith('sonarr:'):
|
||||
sonarr.process_profile(args, logger)
|
||||
elif args.type.startswith('radarr:'):
|
||||
raise TrashError('Radarr guide support is not implemented yet')
|
||||
|
||||
elif args.subcommand == 'quality':
|
||||
if args.type.startswith('sonarr:'):
|
||||
sonarr.process_quality(args, logger)
|
||||
elif args.type.startswith('radarr:'):
|
||||
raise TrashError('Radarr quality support is not implemented yet')
|
||||
|
||||
# --------------------------------------------------------------------------------------------------
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
main(Path(__file__).parent)
|
||||
except TrashError as e:
|
||||
print(f'ERROR: {e}')
|
||||
exit(1)
|
||||
|
Loading…
Reference in new issue