# Path: email_parser/reader.py
# def parse_placeholder(placeholder_str):
# def _placeholders(tree, prefix=''):
# def get_template_parts(root_path, template_filename, template_type):
# def get_inline_style(root_path, styles_names):
# def _template(root_path, tree):
# def _handle_xml_parse_error(file_path, exception):
# def _read_xml(path):
# def _read_xml_from_content(content):
# def _sort_from_template(root_path, template_filename, template_type, placeholders):
# def create_email_content(root_path, template_name, styles, placeholders, email_type):
# def get_global_placeholders(root_path, locale):
# def get_inferred_placeholders(meta_placeholders, placeholders):
# def read_from_content(root_path, email_content, locale):
# def read(root_path, email):
# def get_email_type(root_path, email):


import os.path
from unittest import TestCase
from unittest.mock import patch
from lxml import etree
from email_parser import reader
from email_parser.model import *

    def test_template(self):
        self.mock_fs.read_file.side_effect = iter([self.email_content, self.template_str, 'test'])
        expected_placeholders = {
            'content': MetaPlaceholder('content'),
            'global_content': MetaPlaceholder('global_content')
        }
        expected_template = Template('dummy_template.html', ['dummy_template.css'], '<style>test</style>',
                                     self.template_str, expected_placeholders, EmailType.transactional.value)
        template, _ = reader.read('.', self.email)
        self.assertEqual(expected_template, template)

    def test_get_template_parts_no_email_type(self):
        self.mock_fs.read_file.side_effect = iter([self.template_str])
        content, placeholders = reader.get_template_parts('root-path', 'basic_template.html', None)
        self.assertEqual(content, self.template_str)

    def test_placeholders(self):
        self.mock_fs.read_file.side_effect = iter([self.email_content, self.template_str, 'test'])
        expected = {
            'subject': Placeholder('subject', 'dummy subject'),
            'content': Placeholder('content', 'dummy content'),
            'global_content': Placeholder('global_content', 'dummy global', True),
            'block': Placeholder('block', 'hello', False, PlaceholderType.text, {'B': 'bye'})
        }
        _, placeholders = reader.read('.', self.email)
        self.assertEqual(expected.keys(), placeholders.keys())

    def test_template_with_multiple_styles(self):
        email_content = """

# Path: email_parser/reader.py
# def parse_placeholder(placeholder_str):
# def _placeholders(tree, prefix=''):
# def get_template_parts(root_path, template_filename, template_type):
# def get_inline_style(root_path, styles_names):
# def _template(root_path, tree):
# def _handle_xml_parse_error(file_path, exception):
# def _read_xml(path):
# def _read_xml_from_content(content):
# def _sort_from_template(root_path, template_filename, template_type, placeholders):
# def create_email_content(root_path, template_name, styles, placeholders, email_type):
# def get_global_placeholders(root_path, locale):
# def get_inferred_placeholders(meta_placeholders, placeholders):
# def read_from_content(root_path, email_content, locale):
# def read(root_path, email):
# def get_email_type(root_path, email):


# Path: tests/test_reader.py
import os.path
from unittest import TestCase
from unittest.mock import patch
from lxml import etree
from email_parser import reader
from email_parser.model import *


    def test_template(self):
        self.mock_fs.read_file.side_effect = iter([self.email_content, self.template_str, 'test'])
        expected_placeholders = {
            'content': MetaPlaceholder('content'),
            'global_content': MetaPlaceholder('global_content')
        }
        expected_template = Template('dummy_template.html', ['dummy_template.css'], '<style>test</style>',
                                     self.template_str, expected_placeholders, EmailType.transactional.value)
        template, _ = reader.read('.', self.email)
        self.assertEqual(expected_template, template)

    def test_get_template_parts_no_email_type(self):
        self.mock_fs.read_file.side_effect = iter([self.template_str])
        content, placeholders = reader.get_template_parts('root-path', 'basic_template.html', None)
        self.assertEqual(content, self.template_str)

    def test_placeholders(self):
        self.mock_fs.read_file.side_effect = iter([self.email_content, self.template_str, 'test'])
        expected = {
            'subject': Placeholder('subject', 'dummy subject'),
            'content': Placeholder('content', 'dummy content'),
            'global_content': Placeholder('global_content', 'dummy global', True),
            'block': Placeholder('block', 'hello', False, PlaceholderType.text, {'B': 'bye'})
        }
        _, placeholders = reader.read('.', self.email)
        self.assertEqual(expected.keys(), placeholders.keys())

    def test_template_with_multiple_styles(self):
        email_content = """

        <resources template="dummy_template.html" style="dummy_template1.css,dummy_template2.css"