Пример #1
0
 def test_unit__append_different_type(self):
     mail_parts = BodyMailParts()
     a = BodyMailPart("a", BodyMailPartType.Main)
     mail_parts.append(a)
     b = BodyMailPart("b", BodyMailPartType.Quote)
     mail_parts._append(b)
     assert len(mail_parts) == 2
     assert mail_parts[0] == a
     assert mail_parts[1] == b
Пример #2
0
 def test_unit__str(self):
     mail_parts = BodyMailParts()
     a = BodyMailPart("a", BodyMailPartType.Main)
     mail_parts._list.append(a)
     b = BodyMailPart("b", BodyMailPartType.Quote)
     mail_parts._list.append(b)
     c = BodyMailPart("c", BodyMailPartType.Signature)
     mail_parts._list.append(c)
     assert str(mail_parts) == "abc"
Пример #3
0
 def test_unit__append_same_type(self):
     mail_parts = BodyMailParts()
     a = BodyMailPart("a", BodyMailPartType.Main)
     mail_parts._append(a)
     b = BodyMailPart("b", BodyMailPartType.Main)
     mail_parts._append(b)
     assert len(mail_parts) == 1
     assert mail_parts[0].part_type == BodyMailPartType.Main
     assert mail_parts[0].text == "ab"
Пример #4
0
 def test_unit__str(self):
     mail_parts = BodyMailParts()
     a = BodyMailPart('a', BodyMailPartType.Main)
     mail_parts._list.append(a)
     b = BodyMailPart('b', BodyMailPartType.Quote)
     mail_parts._list.append(b)
     c = BodyMailPart('c', BodyMailPartType.Signature)
     mail_parts._list.append(c)
     assert str(mail_parts) == 'abc'
Пример #5
0
 def test_unit__append_follow(self):
     mail_parts = BodyMailParts()
     mail_parts.follow = True
     a = BodyMailPart("a", BodyMailPartType.Main)
     mail_parts._append(a)
     b = BodyMailPart("b", BodyMailPartType.Quote)
     mail_parts._append(b)
     assert len(mail_parts) == 1
     assert mail_parts[0].part_type == BodyMailPartType.Main
     assert mail_parts[0].text == "ab"
Пример #6
0
 def test_unit__drop_part_type_consistence(self):
     mail_parts = BodyMailParts()
     a = BodyMailPart("a", BodyMailPartType.Main)
     mail_parts._list.append(a)
     b = BodyMailPart("b", BodyMailPartType.Quote)
     mail_parts._list.append(b)
     c = BodyMailPart("c", BodyMailPartType.Main)
     mail_parts._list.append(c)
     mail_parts.drop_part_type(BodyMailPartType.Quote)
     assert len(mail_parts) == 1
     assert mail_parts[0].text == "ac"
     assert mail_parts[0].part_type == BodyMailPartType.Main
Пример #7
0
 def test_unit__drop_part_type(self):
     mail_parts = BodyMailParts()
     a = BodyMailPart('a', BodyMailPartType.Main)
     mail_parts._list.append(a)
     b = BodyMailPart('b', BodyMailPartType.Quote)
     mail_parts._list.append(b)
     c = BodyMailPart('c', BodyMailPartType.Signature)
     mail_parts._list.append(c)
     mail_parts.drop_part_type(BodyMailPartType.Quote)
     assert len(mail_parts) == 2
     assert mail_parts[0].text == 'a'
     assert mail_parts[0].part_type == BodyMailPartType.Main
     assert len(mail_parts) == 2
     assert mail_parts[1].text == 'c'
     assert mail_parts[1].part_type == BodyMailPartType.Signature
Пример #8
0
 def test_unit__get_nb_part_type(self):
     mail_parts = BodyMailParts()
     assert mail_parts.get_nb_part_type(BodyMailPartType.Main) == 0
     assert mail_parts.get_nb_part_type(BodyMailPartType.Quote) == 0
     assert mail_parts.get_nb_part_type(BodyMailPartType.Signature) == 0
     a = BodyMailPart("a", BodyMailPartType.Main)
     mail_parts._list.append(a)
     assert mail_parts.get_nb_part_type(BodyMailPartType.Main) == 1
     b = BodyMailPart("b", BodyMailPartType.Quote)
     mail_parts._list.append(b)
     assert mail_parts.get_nb_part_type(BodyMailPartType.Quote) == 1
     c = BodyMailPart("c", BodyMailPartType.Signature)
     mail_parts._list.append(c)
     assert mail_parts.get_nb_part_type(BodyMailPartType.Main) == 1
     assert mail_parts.get_nb_part_type(BodyMailPartType.Quote) == 1
     assert mail_parts.get_nb_part_type(BodyMailPartType.Signature) == 1
Пример #9
0
 def test_unit__drop_part_type_verify_no_follow_incidence(self):
     mail_parts = BodyMailParts()
     a = BodyMailPart("a", BodyMailPartType.Main)
     mail_parts._list.append(a)
     b = BodyMailPart("b", BodyMailPartType.Quote)
     mail_parts._list.append(b)
     c = BodyMailPart("c", BodyMailPartType.Signature)
     mail_parts._list.append(c)
     mail_parts.follow = True
     mail_parts.drop_part_type(BodyMailPartType.Quote)
     assert len(mail_parts) == 2
     assert mail_parts[0].text == "a"
     assert mail_parts[0].part_type == BodyMailPartType.Main
     assert len(mail_parts) == 2
     assert mail_parts[1].text == "c"
     assert mail_parts[1].part_type == BodyMailPartType.Signature
Пример #10
0
 def test_unit__append_dont_follow_when_first(self):
     mail_parts = BodyMailParts()
     a = BodyMailPart("a", BodyMailPartType.Main)
     mail_parts._append(a, follow=True)
     assert len(mail_parts) == 1
     assert mail_parts[0].part_type == BodyMailPartType.Main
     assert mail_parts[0].text == "a"
Пример #11
0
 def test_unit__std_list_methods(self):
     mail_parts = BodyMailParts()
     assert len(mail_parts) == 0
     a = BodyMailPart("a", BodyMailPartType.Main)
     mail_parts._list.append(a)
     assert len(mail_parts) == 1
     assert mail_parts[0] == a
     del mail_parts[0]
     assert len(mail_parts) == 0
Пример #12
0
    def _distinct_elements(cls, tree: BeautifulSoup) -> HtmlBodyMailParts:
        parts = HtmlBodyMailParts()
        for elem in list(tree):
            part_txt = str(elem)
            part_type = BodyMailPartType.Main

            if HtmlMailQuoteChecker.is_quote(elem):
                part_type = BodyMailPartType.Quote
            elif HtmlMailSignatureChecker.is_signature(elem):
                part_type = BodyMailPartType.Signature

            part = BodyMailPart(part_txt, part_type)
            parts.append(part)
            # INFO - G.M - 2017-11-28 - Outlook.com special case
            # all after quote tag is quote
            if HtmlMailQuoteChecker._is_outlook_com_quote(elem):
                parts.follow = True
        return parts
Пример #13
0
 def test_unit__check_value__ok(self):
     mail_parts = BodyMailParts()
     a = BodyMailPart("a", BodyMailPartType.Main)
     mail_parts._check_value(a)