# 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):
#     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 _find_app(settings, app):
#     """Looks for an installed application in the user's local $PATH.
# 
#     Raises an ImportError if the application is not found.
#     """
# 
#     # Save in settings
#     name = app['name'].lower()
#     settings[name] = None
# 
#     # Retrieve local paths
#     split_token = ';' if mh.__iswin__ else ':'
#     local_paths = os.environ['PATH'].rsplit(split_token)
# 
#     # Look for app in local paths
#     for local_path in local_paths:
#         path = os.path.join(local_path, app['exec'])
# 
#         # If the path exists, store & exit the loop
#         if os.path.isfile(path):
#             settings[name] = path
#             break
# 
#         # Try .exe for windows
#         if mh.__iswin__:
#             win_path = path + '.exe'
#             if os.path.isfile(win_path):
#                 settings[name] = win_path
#                 break
# 
#     # If app not found, raise ImportError
#     if settings[name] is None:
#         error = '{0} application not found'.format(app['name'])
#         raise ImportError(error)


import os
import re
import sys
import shutil
import tests.common as common
import mediahandler.handler as MH
import mediahandler.util.notify as Notify
from tests.common import unittest
from tests.common import tempfile
from tests.common import MHTestSuite
from mediahandler.util.config import _find_app
        self.assertFalse(new_handler.single_file)

    def test_missing_args(self):
        # Build arguments
        new_handler = MH.MHandler(None)
        # Run Test 
        self.assertEqual(new_handler.config, common.get_conf_file())
        self.assertIsInstance(new_handler.push, Notify.MHPush)
        self.assertIsInstance(new_handler, MH.MHandler)
        self.assertIsNone(new_handler.extracted)
        self.assertFalse(new_handler.single_file)


class HandlerTestClass(unittest.TestCase):

    def setUp(self):
        # Conf
        self.conf = common.get_conf_file()
        # Dummy args
        self.name = "test-{0}".format(common.get_test_id())
        self.args = {
            'name': self.name,
            'type': 1,
            'stype': 'TV',
            'single_track': False,
        }
        # Set up handler
        self.handler = MH.MHandler(self.conf)
        self.handler.set_settings(self.args)
        # Make a dummy folder

# 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):
#     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 _find_app(settings, app):
#     """Looks for an installed application in the user's local $PATH.
# 
#     Raises an ImportError if the application is not found.
#     """
# 
#     # Save in settings
#     name = app['name'].lower()
#     settings[name] = None
# 
#     # Retrieve local paths
#     split_token = ';' if mh.__iswin__ else ':'
#     local_paths = os.environ['PATH'].rsplit(split_token)
# 
#     # Look for app in local paths
#     for local_path in local_paths:
#         path = os.path.join(local_path, app['exec'])
# 
#         # If the path exists, store & exit the loop
#         if os.path.isfile(path):
#             settings[name] = path
#             break
# 
#         # Try .exe for windows
#         if mh.__iswin__:
#             win_path = path + '.exe'
#             if os.path.isfile(win_path):
#                 settings[name] = win_path
#                 break
# 
#     # If app not found, raise ImportError
#     if settings[name] is None:
#         error = '{0} application not found'.format(app['name'])
#         raise ImportError(error)


# Path: tests/test_handler.py
import os
import re
import sys
import shutil
import tests.common as common
import mediahandler.handler as MH
import mediahandler.util.notify as Notify
from tests.common import unittest
from tests.common import tempfile
from tests.common import MHTestSuite
from mediahandler.util.config import _find_app

        self.assertFalse(new_handler.single_file)

    def test_missing_args(self):
        # Build arguments
        new_handler = MH.MHandler(None)
        # Run Test 
        self.assertEqual(new_handler.config, common.get_conf_file())
        self.assertIsInstance(new_handler.push, Notify.MHPush)
        self.assertIsInstance(new_handler, MH.MHandler)
        self.assertIsNone(new_handler.extracted)
        self.assertFalse(new_handler.single_file)


class HandlerTestClass(unittest.TestCase):

    def setUp(self):
        # Conf
        self.conf = common.get_conf_file()
        # Dummy args
        self.name = "test-{0}".format(common.get_test_id())
        self.args = {
            'name': self.name,
            'type': 1,
            'stype': 'TV',
            'single_track': False,
        }
        # Set up handler
        self.handler = MH.MHandler(self.conf)
        self.handler.set_settings(self.args)
        # Make a dummy folder

        self.dir = tempfile.mkdtemp(