# 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()


import os
import shutil
import zipfile as zf
import contextlib
import tests.common as common
import mediahandler.util.extract as Extract
import mediahandler.handler as MH
from tests.common import unittest
from tests.common import tempfile
from tests.common import MHTestSuite

    def test_good_extract(self):
        files = Extract.get_files(self.filebot, self.zip_name)
        self.assertEqual(files, self.folder)
        self.assertTrue(os.path.exists(files))

    def test_good_handler_zip_tv(self):
        # Run handler
        files = self.handler.extract_files(self.zip_name)
        self.assertEqual(files, self.folder)
        self.assertTrue(os.path.exists(files))
        self.assertEqual(self.handler.extracted, self.zip_name)

    def test_good_handler_zip_movies(self):
        delattr(self.handler.tv, 'filebot')
        # Run handler
        files = self.handler.extract_files(self.zip_name)
        self.assertEqual(files, self.folder)
        self.assertTrue(os.path.exists(files))
        self.assertEqual(self.handler.extracted, self.zip_name)

    def test_good_handler_zip_found(self):
        # Run handler
        regex = r'Folder for TV not found: .*TV'
        self.assertRaisesRegexp(
            SystemExit, regex,
            self.handler._find_zipped, self.zip_name)


def suite():

# 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: tests/test_extract.py
import os
import shutil
import zipfile as zf
import contextlib
import tests.common as common
import mediahandler.util.extract as Extract
import mediahandler.handler as MH
from tests.common import unittest
from tests.common import tempfile
from tests.common import MHTestSuite


    def test_good_extract(self):
        files = Extract.get_files(self.filebot, self.zip_name)
        self.assertEqual(files, self.folder)
        self.assertTrue(os.path.exists(files))

    def test_good_handler_zip_tv(self):
        # Run handler
        files = self.handler.extract_files(self.zip_name)
        self.assertEqual(files, self.folder)
        self.assertTrue(os.path.exists(files))
        self.assertEqual(self.handler.extracted, self.zip_name)

    def test_good_handler_zip_movies(self):
        delattr(self.handler.tv, 'filebot')
        # Run handler
        files = self.handler.extract_files(self.zip_name)
        self.assertEqual(files, self.folder)
        self.assertTrue(os.path.exists(files))
        self.assertEqual(self.handler.extracted, self.zip_name)

    def test_good_handler_zip_found(self):
        # Run handler
        regex = r'Folder for TV not found: .*TV'
        self.assertRaisesRegexp(
            SystemExit, regex,
            self.handler._find_zipped, self.zip_name)


def suite():

    s = MHTestSuite()