# Path: email_parser/fs.py
# def _parse_params(pattern):
# def _has_correct_ext(path, pattern):
# def _emails(root_path, pattern, params):
# def get_email_filepath(email_name, locale):
# def get_template_filepath(root_path, template_name, template_type):
# def get_template_resources_filepaths(root_path, template):
# def emails(root_path, email_name=None, locale=None):
# def email(root_path, email_name, locale):
# def global_email(root_path, locale):
# def read_file(*path_parts):
# def save_file(content, *path_parts):
# def delete_file(*path_parts):
# def save_email(root_path, content, email_name, locale):
# def save_template(root_path, template_filename, template_type, template_content):
# def save_parsed_email(root_path, email, subject, text, html):
# def resources(root_path):
# def get_html_sections_map(root_path):


from unittest import TestCase
from unittest.mock import patch
from email_parser import fs
from email_parser.model import *


class TestFs(TestCase):
    def setUp(self):
        self.patch_path = patch('email_parser.fs.Path')
        self.mock_path = self.patch_path.start()
        self.showDiff = True

    def tearDown(self):
        super().tearDown()
        self.patch_path.stop()

    def test_emails_happy_path(self):
        expected = Email('name1', 'locale1', 'locale1/name1.xml')
        self.mock_path.return_value.glob.return_value = [MockPath(expected.path)]
        actual = list(fs.emails('.'))
        self.assertEqual([expected], actual)

    def test_emails_correct_size(self):
        self.mock_path.return_value.glob.return_value = [MockPath('locale1/name1.xml'), MockPath('locale2/name2.xml')]
        actual = list(fs.emails('.'))
        self.assertEqual(2, len(actual))

    def test_emails_ignore_dirs(self):
        self.mock_path.return_value.glob.return_value = [MockPath('locale1/name1.xml'), MockPath('locale1', True)]
        actual = list(fs.emails('.'))
        self.assertEqual(1, len(actual))

    def test_emails_ignore_global_by_default(self):
        self.mock_path.return_value.glob.return_value = [MockPath('locale1/name1.xml'), MockPath('locale1/global.xml')]

# Path: email_parser/fs.py
# def _parse_params(pattern):
# def _has_correct_ext(path, pattern):
# def _emails(root_path, pattern, params):
# def get_email_filepath(email_name, locale):
# def get_template_filepath(root_path, template_name, template_type):
# def get_template_resources_filepaths(root_path, template):
# def emails(root_path, email_name=None, locale=None):
# def email(root_path, email_name, locale):
# def global_email(root_path, locale):
# def read_file(*path_parts):
# def save_file(content, *path_parts):
# def delete_file(*path_parts):
# def save_email(root_path, content, email_name, locale):
# def save_template(root_path, template_filename, template_type, template_content):
# def save_parsed_email(root_path, email, subject, text, html):
# def resources(root_path):
# def get_html_sections_map(root_path):


# Path: tests/test_fs.py
from unittest import TestCase
from unittest.mock import patch
from email_parser import fs
from email_parser.model import *



class TestFs(TestCase):
    def setUp(self):
        self.patch_path = patch('email_parser.fs.Path')
        self.mock_path = self.patch_path.start()
        self.showDiff = True

    def tearDown(self):
        super().tearDown()
        self.patch_path.stop()

    def test_emails_happy_path(self):
        expected = Email('name1', 'locale1', 'locale1/name1.xml')
        self.mock_path.return_value.glob.return_value = [MockPath(expected.path)]
        actual = list(fs.emails('.'))
        self.assertEqual([expected], actual)

    def test_emails_correct_size(self):
        self.mock_path.return_value.glob.return_value = [MockPath('locale1/name1.xml'), MockPath('locale2/name2.xml')]
        actual = list(fs.emails('.'))
        self.assertEqual(2, len(actual))

    def test_emails_ignore_dirs(self):
        self.mock_path.return_value.glob.return_value = [MockPath('locale1/name1.xml'), MockPath('locale1', True)]
        actual = list(fs.emails('.'))
        self.assertEqual(1, len(actual))

    def test_emails_ignore_global_by_default(self):
        self.mock_path.return_value.glob.return_value = [MockPath('locale1/name1.xml'), MockPath('locale1/global.xml')]

        actual = list(fs.emails('.'))