# 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 *
                <item variant="B">YYY</item>
            </array>
        </resources>
        """
        template_str = '<html><head></head><body>{{image:MYIMAGE:max_width=160}}</body></html>'
        self.mock_fs.read_file.side_effect = iter([email_content, template_str, 'test'])
        template, placeholders = reader.read_from_content('.', email_content, 'en')
        self.assertTrue('MY_IMAGE' in placeholders.keys())

    def test_read_by_content(self):
        self.mock_fs.read_file.return_value = self.template_str
        template, _ = reader.read_from_content('.', self.email_content, 'en')
        self.assertEqual(template.name, 'dummy_template.html')

    def test_on_missing_content_return_fallback(self):
        self.mock_fs.read_file.return_value = None
        template, _ = reader.read('.', self.email)
        self.assertEqual(self.mock_fs.read_file.call_count, 2)

    def test_on_malformed_content_return_fallback(self):
        malformed_email_content = """
        <resources template="dummy_template.html" style="dummy_template1.css,dummy_template2.css"
        email_type="marketing">
            <string name="subject"dummy subject</string>
        </resources>
        """
        self.mock_fs.read_file.side_effect = iter([malformed_email_content,
                                                   self.email_content,
                                                   self.template_str,
                                                   'test'])

# 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 *

                <item variant="B">YYY</item>
            </array>
        </resources>
        """
        template_str = '<html><head></head><body>{{image:MYIMAGE:max_width=160}}</body></html>'
        self.mock_fs.read_file.side_effect = iter([email_content, template_str, 'test'])
        template, placeholders = reader.read_from_content('.', email_content, 'en')
        self.assertTrue('MY_IMAGE' in placeholders.keys())

    def test_read_by_content(self):
        self.mock_fs.read_file.return_value = self.template_str
        template, _ = reader.read_from_content('.', self.email_content, 'en')
        self.assertEqual(template.name, 'dummy_template.html')

    def test_on_missing_content_return_fallback(self):
        self.mock_fs.read_file.return_value = None
        template, _ = reader.read('.', self.email)
        self.assertEqual(self.mock_fs.read_file.call_count, 2)

    def test_on_malformed_content_return_fallback(self):
        malformed_email_content = """
        <resources template="dummy_template.html" style="dummy_template1.css,dummy_template2.css"
        email_type="marketing">
            <string name="subject"dummy subject</string>
        </resources>
        """
        self.mock_fs.read_file.side_effect = iter([malformed_email_content,
                                                   self.email_content,
                                                   self.template_str,
                                                   'test'])

        template, _ = reader.read('.', self.email)