# Path: email_parser/placeholder.py
# def _extract_placeholders(text):
# def expected_placeholders_file(root_path):
# def _email_placeholders(root_path, email):
# def get_email_validation(root_path, email):
# def generate_config(root_path):
# 
# 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 collections import Counter
from email_parser import placeholder, fs
from email_parser.model import *
        self.mock_reader.read.return_value = ('', {'segment': Placeholder('segment', '{{test_placeholder}}')})

        self.patch_config = patch('email_parser.placeholder.expected_placeholders_file')
        self.mock_config = self.patch_config.start()
        self.mock_config.return_value = {self.email.name: {'test_placeholder': 1}}

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

    def test_happy_path(self):
        actual = placeholder.get_email_validation('.', self.email, )
        expected = {'valid': True, 'errors': None}
        self.assertEqual(expected, actual)

    def test_missing_placeholder(self):
        self.mock_reader.read.return_value = ('', {'segment': Placeholder('segment', 'content')})
        actual = placeholder.get_email_validation('.', self.email)
        expected = {'valid': False, 'errors': {'missing': ['test_placeholder'], 'extra': [], 'diff_number': []}}
        self.assertEqual(expected, actual)

    def test_extra_placeholder(self):
        self.mock_config.return_value = {self.email.name: {}}
        actual = placeholder.get_email_validation('.', self.email)
        expected = {'valid': False, 'errors': {'missing': [], 'extra': ['test_placeholder'], 'diff_number': []}}
        self.assertEqual(expected, actual)

    def test_diffrent_placeholder_count(self):
        self.mock_reader.read.return_value = ('', {'segment': Placeholder('segment',
                                                                          '{{test_placeholder}}{{test_placeholder}}')})

# Path: email_parser/placeholder.py
# def _extract_placeholders(text):
# def expected_placeholders_file(root_path):
# def _email_placeholders(root_path, email):
# def get_email_validation(root_path, email):
# def generate_config(root_path):
# 
# 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_placeholder.py
from unittest import TestCase
from unittest.mock import patch
from collections import Counter
from email_parser import placeholder, fs
from email_parser.model import *

        self.mock_reader.read.return_value = ('', {'segment': Placeholder('segment', '{{test_placeholder}}')})

        self.patch_config = patch('email_parser.placeholder.expected_placeholders_file')
        self.mock_config = self.patch_config.start()
        self.mock_config.return_value = {self.email.name: {'test_placeholder': 1}}

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

    def test_happy_path(self):
        actual = placeholder.get_email_validation('.', self.email, )
        expected = {'valid': True, 'errors': None}
        self.assertEqual(expected, actual)

    def test_missing_placeholder(self):
        self.mock_reader.read.return_value = ('', {'segment': Placeholder('segment', 'content')})
        actual = placeholder.get_email_validation('.', self.email)
        expected = {'valid': False, 'errors': {'missing': ['test_placeholder'], 'extra': [], 'diff_number': []}}
        self.assertEqual(expected, actual)

    def test_extra_placeholder(self):
        self.mock_config.return_value = {self.email.name: {}}
        actual = placeholder.get_email_validation('.', self.email)
        expected = {'valid': False, 'errors': {'missing': [], 'extra': ['test_placeholder'], 'diff_number': []}}
        self.assertEqual(expected, actual)

    def test_diffrent_placeholder_count(self):
        self.mock_reader.read.return_value = ('', {'segment': Placeholder('segment',
                                                                          '{{test_placeholder}}{{test_placeholder}}')})

        actual = placeholder.get_email_validation('.', self.email)