# Path: tests/common.py
# class MHTestSuite(unittest.TestSuite):
#     def setUpSuite(self):
#     def tearDownSuite(self):
#     def run(self, result):
# def skip_unless_has_mod(module, submodule):
# def get_test_id(size=4):
# def random_string(size=5):
# def temp_file(name=None):
# def make_tmp_file(text=None, tdir=None):
# def get_conf_file():
# def get_orig_settings():
# def get_settings(conf=None):
# def get_types_by_string():
# def get_types_by_id():
# def get_pushover_api():
# def get_pushbullet_api():
# def get_google_api():
# def remove_file(file_path):
# 
# Path: tests/common.py
# class MHTestSuite(unittest.TestSuite):
# 
#     def setUpSuite(self):
#         # Back up current config
#         curr_config = get_conf_file()
#         backup = '{0}.orig'.format(curr_config)
#         if not os.path.exists(backup):
#             shutil.move(curr_config, backup)
#         # Make new config for testing
#         Config.make_config()
# 
#     def tearDownSuite(self):
#         # Restore original config
#         curr_config = get_conf_file()
#         backup = '{0}.orig'.format(curr_config)
#         if os.path.exists(backup):
#             shutil.move(backup, curr_config)
# 
#     def run(self, result):
#         # Before tests
#         self.setUpSuite()
#         # Set buffering
#         result.buffer = True
#         # Run tests
#         super(MHTestSuite, self).run(result)
#         # After tests
#         self.tearDownSuite()
# 
# Path: mediahandler/util/config.py
# def parse_config(file_path):
#     """Reads and parses a yaml mediahandler configuration file.
# 
#     Optional argument:
#         - file_path
#             Path to a valid yaml mediahandler configuration file.
# 
#     Uses settings.yml validation structure to build missing and default
#     values. Sends values to the correct _get_valid_<type>() function
#     for validation.
#     """
# 
#     # Read yaml files
#     parsed = _get_yaml(file_path)
#     struct = _get_yaml(os.path.join(mh.__mediaextras__, 'settings.yml'))
# 
#     # Loop through config & validate
#     settings = {}
#     for item in struct['items']:
#         section = item['section']
# 
#         # Populate hash
#         settings[section] = _process_section(
#             section, item['options'], parsed)
# 
#     # Check that appropriate modules are installed
#     _check_modules(settings)
# 
#     return settings


import os
import sys
import shutil
import tests.common as common
import mediahandler.util.args as Args
import mediahandler.util.torrent as Torrent
from tests.common import unittest
from tests.common import MHTestSuite
from mediahandler.util.config import parse_config
        from twisted.internet import reactor
            'no_push': False,
            'single_track': False,
            'query': None,
            'type': 1,
            'stype': 'TV'
        }
        # Run test
        sys.argv = ['', 'hash', os.path.basename(self.tmp_file), self.folder]
        (config, args) = Args.get_deluge_arguments()
        self.assertEqual(config, self.conf)
        self.assertDictEqual(args, expected)

    def test_get_bad_args(self):
        # Test 1
        sys.argv = ['', 'hash', 'name']
        regex = r'(too few arguments|the following arguments are required: TORRENT PATH)'
        self.assertRaisesRegexp(SystemExit, regex, Args.get_deluge_arguments)
        # Test 2
        sys.argv = ['', 'hash', 'name', '/path/to/file']
        regex = r'File or directory provided for {0} {1}: {2}'.format(
            'path', 'does not exist', '/path/to/file')
        self.assertRaisesRegexp(
            SystemExit, regex, Args.get_deluge_arguments)


class RemoveTorrentTests(unittest.TestCase):

    @common.skip_unless_has_mod('twisted', 'internet')
    def setUp(self):
        self.conf = common.get_conf_file()

# Path: tests/common.py
# class MHTestSuite(unittest.TestSuite):
#     def setUpSuite(self):
#     def tearDownSuite(self):
#     def run(self, result):
# def skip_unless_has_mod(module, submodule):
# def get_test_id(size=4):
# def random_string(size=5):
# def temp_file(name=None):
# def make_tmp_file(text=None, tdir=None):
# def get_conf_file():
# def get_orig_settings():
# def get_settings(conf=None):
# def get_types_by_string():
# def get_types_by_id():
# def get_pushover_api():
# def get_pushbullet_api():
# def get_google_api():
# def remove_file(file_path):
# 
# Path: tests/common.py
# class MHTestSuite(unittest.TestSuite):
# 
#     def setUpSuite(self):
#         # Back up current config
#         curr_config = get_conf_file()
#         backup = '{0}.orig'.format(curr_config)
#         if not os.path.exists(backup):
#             shutil.move(curr_config, backup)
#         # Make new config for testing
#         Config.make_config()
# 
#     def tearDownSuite(self):
#         # Restore original config
#         curr_config = get_conf_file()
#         backup = '{0}.orig'.format(curr_config)
#         if os.path.exists(backup):
#             shutil.move(backup, curr_config)
# 
#     def run(self, result):
#         # Before tests
#         self.setUpSuite()
#         # Set buffering
#         result.buffer = True
#         # Run tests
#         super(MHTestSuite, self).run(result)
#         # After tests
#         self.tearDownSuite()
# 
# Path: mediahandler/util/config.py
# def parse_config(file_path):
#     """Reads and parses a yaml mediahandler configuration file.
# 
#     Optional argument:
#         - file_path
#             Path to a valid yaml mediahandler configuration file.
# 
#     Uses settings.yml validation structure to build missing and default
#     values. Sends values to the correct _get_valid_<type>() function
#     for validation.
#     """
# 
#     # Read yaml files
#     parsed = _get_yaml(file_path)
#     struct = _get_yaml(os.path.join(mh.__mediaextras__, 'settings.yml'))
# 
#     # Loop through config & validate
#     settings = {}
#     for item in struct['items']:
#         section = item['section']
# 
#         # Populate hash
#         settings[section] = _process_section(
#             section, item['options'], parsed)
# 
#     # Check that appropriate modules are installed
#     _check_modules(settings)
# 
#     return settings


# Path: tests/test_torrent.py
import os
import sys
import shutil
import tests.common as common
import mediahandler.util.args as Args
import mediahandler.util.torrent as Torrent
from tests.common import unittest
from tests.common import MHTestSuite
from mediahandler.util.config import parse_config
        from twisted.internet import reactor

            'no_push': False,
            'single_track': False,
            'query': None,
            'type': 1,
            'stype': 'TV'
        }
        # Run test
        sys.argv = ['', 'hash', os.path.basename(self.tmp_file), self.folder]
        (config, args) = Args.get_deluge_arguments()
        self.assertEqual(config, self.conf)
        self.assertDictEqual(args, expected)

    def test_get_bad_args(self):
        # Test 1
        sys.argv = ['', 'hash', 'name']
        regex = r'(too few arguments|the following arguments are required: TORRENT PATH)'
        self.assertRaisesRegexp(SystemExit, regex, Args.get_deluge_arguments)
        # Test 2
        sys.argv = ['', 'hash', 'name', '/path/to/file']
        regex = r'File or directory provided for {0} {1}: {2}'.format(
            'path', 'does not exist', '/path/to/file')
        self.assertRaisesRegexp(
            SystemExit, regex, Args.get_deluge_arguments)


class RemoveTorrentTests(unittest.TestCase):

    @common.skip_unless_has_mod('twisted', 'internet')
    def setUp(self):
        self.conf = common.get_conf_file()

        self.settings = parse_config(self.conf)['Deluge']