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
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"
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"
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'
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"
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
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
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
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
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"
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
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
def test_unit__check_value__ok(self): mail_parts = BodyMailParts() a = BodyMailPart("a", BodyMailPartType.Main) mail_parts._check_value(a)