Пример #1
0
    def test_placeholders(self, mock_tree):
        mock_tree.parse.return_value = ElementTree.ElementTree(self.email_element)
        expected = OrderedDict([('subject', 'dummy subject'), ('content', 'dummy content')])

        _, placeholders, _ = reader.read('dummy_path')

        self.assertEqual(expected, placeholders)
Пример #2
0
    def test_placeholders(self, mock_tree):
        mock_tree.parse.return_value = ElementTree.ElementTree(self.email_element)
        expected = OrderedDict([('subject', 'dummy subject'), ('content', 'dummy content')])

        _, placeholders, _ = reader.read('dummy_path')

        self.assertEqual(expected, placeholders)
Пример #3
0
    def test_template(self, mock_tree):
        mock_tree.parse.return_value = ElementTree.ElementTree(self.email_element)

        template, _, _ = reader.read('dummy_path')

        self.assertEqual('dummy_template.html', template.name)
        self.assertEqual(['dummy_template.css'], template.styles)
Пример #4
0
    def test_template(self, mock_tree):
        mock_tree.parse.return_value = ElementTree.ElementTree(self.email_element)

        template, _, _ = reader.read('dummy_path')

        self.assertEqual('dummy_template.html', template.name)
        self.assertEqual(['dummy_template.css'], template.styles)
Пример #5
0
 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())
Пример #6
0
 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)
Пример #7
0
    def test_template_with_multiple_styles(self, mock_tree):
        email_element = ElementTree.fromstring("""
        <resources template="dummy_template.html" style="dummy_template1.css,dummy_template2.css">
        	<string name="subject">dummy subject</string>
            <string name="content">dummy content</string>
        </resources>
        """)
        mock_tree.parse.return_value = ElementTree.ElementTree(email_element)

        template, _, _ = reader.read('dummy_path')

        self.assertEqual(['dummy_template1.css', 'dummy_template2.css'], template.styles)
Пример #8
0
    def test_template_with_multiple_styles(self, mock_tree):
        email_element = ElementTree.fromstring("""
        <resources template="dummy_template.html" style="dummy_template1.css,dummy_template2.css">
            <string name="subject">dummy subject</string>
            <string name="content">dummy content</string>
        </resources>
        """)
        mock_tree.parse.return_value = ElementTree.ElementTree(email_element)

        template, _, _ = reader.read('dummy_path')

        self.assertEqual(['dummy_template1.css', 'dummy_template2.css'], template.styles)
Пример #9
0
    def test_ignore_non_text_elements(self, mock_tree):
        email_element = ElementTree.fromstring("""
        <resources template="dummy_template.html" style="dummy_template1.css,dummy_template2.css">
        	<string name="subject">dummy subject</string>
            <string name="content">dummy content</string>
            <string name="color" isText="false">blue</string>
        </resources>
        """)
        mock_tree.parse.return_value = ElementTree.ElementTree(email_element)

        _, _, ignored = reader.read('dummy_path')

        self.assertEqual(['color'], ignored)
Пример #10
0
    def test_ignore_non_text_elements(self, mock_tree):
        email_element = ElementTree.fromstring("""
        <resources template="dummy_template.html" style="dummy_template1.css,dummy_template2.css">
            <string name="subject">dummy subject</string>
            <string name="content">dummy content</string>
            <string name="color" isText="false">blue</string>
        </resources>
        """)
        mock_tree.parse.return_value = ElementTree.ElementTree(email_element)

        _, _, ignored = reader.read('dummy_path')

        self.assertEqual(['color'], ignored)
Пример #11
0
 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)
     self.assertEqual(self.mock_fs.read_file.call_count, 4)
Пример #12
0
 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)
     self.assertEqual(self.mock_fs.read_file.call_count, 4)
Пример #13
0
 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)
Пример #14
0
 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())
Пример #15
0
 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)
Пример #16
0
 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)