# 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

class FileHandlerTests(HandlerTestClass):

    def test_process_files_books(self):
        # Modify args & settings for books
        self.handler.type = 4
        self.handler.stype = 'Audiobooks'
        self.handler.audiobooks.enabled = True
        self.handler.single_file = True
        # Make a dummy file
        self.tmp_file = common.make_tmp_file('.m4b')
        # Run test
        regex = r'Folder for Audiobooks not found: .*Audiobooks'
        self.assertRaisesRegexp(
            SystemExit, regex, self.handler._file_handler, self.tmp_file)

    def test_process_files_single_video(self):
        # Modify args & settings for single video
        self.handler.type = 2
        self.handler.stype = 'Movies'
        self.handler.single_file = True
        # Make a dummy file
        self.tmp_file = common.make_tmp_file('.avi')
        # Run test
        regex = r'Folder for Movies not found: .*Movies'
        self.assertRaisesRegexp(
            SystemExit, regex, self.handler._file_handler, self.tmp_file)

    def test_process_files_single_music(self):
        # Set up beets 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):
#     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


class FileHandlerTests(HandlerTestClass):

    def test_process_files_books(self):
        # Modify args & settings for books
        self.handler.type = 4
        self.handler.stype = 'Audiobooks'
        self.handler.audiobooks.enabled = True
        self.handler.single_file = True
        # Make a dummy file
        self.tmp_file = common.make_tmp_file('.m4b')
        # Run test
        regex = r'Folder for Audiobooks not found: .*Audiobooks'
        self.assertRaisesRegexp(
            SystemExit, regex, self.handler._file_handler, self.tmp_file)

    def test_process_files_single_video(self):
        # Modify args & settings for single video
        self.handler.type = 2
        self.handler.stype = 'Movies'
        self.handler.single_file = True
        # Make a dummy file
        self.tmp_file = common.make_tmp_file('.avi')
        # Run test
        regex = r'Folder for Movies not found: .*Movies'
        self.assertRaisesRegexp(
            SystemExit, regex, self.handler._file_handler, self.tmp_file)

    def test_process_files_single_music(self):
        # Set up beets path

        _find_app(