<s> import unittest2 as unittest <EOL> from slimta . policy . split import RecipientSplit , RecipientDomainSplit <EOL> from slimta . envelope import Envelope <EOL> class TestPoliySplit ( unittest . TestCase ) : <EOL> def test_recipientsplit_apply ( self ) : <EOL> env = Envelope ( '<STR_LIT>' , [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> env . parse ( b"""<STR_LIT>""" ) <EOL> policy = RecipientSplit ( ) <EOL> env1 , env2 = policy . apply ( env ) <EOL> self . assertEqual ( '<STR_LIT>' , env1 . sender ) <EOL> self . assertEqual ( [ '<STR_LIT>' ] , env1 . recipients ) <EOL> self . assertEqual ( '<STR_LIT>' , env1 . headers [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> env1 . headers . get_all ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( b'<STR_LIT>' , env1 . message ) <EOL> self . assertEqual ( '<STR_LIT>' , env2 . sender ) <EOL> self . assertEqual ( [ '<STR_LIT>' ] , env2 . recipients ) <EOL> self . assertEqual ( '<STR_LIT>' , env2 . headers [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> env2 . headers . get_all ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( b'<STR_LIT>' , env2 . message ) <EOL> def test_recipientsplit_apply_onercpt ( self ) : <EOL> env = Envelope ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> policy = RecipientSplit ( ) <EOL> self . assertFalse ( policy . apply ( env ) ) <EOL> def test_recipientdomainsplit_get_domain ( self ) : <EOL> policy = RecipientDomainSplit ( ) <EOL> self . assertEqual ( '<STR_LIT>' , policy . _get_domain ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( '<STR_LIT>' , policy . _get_domain ( '<STR_LIT>' ) ) <EOL> self . assertRaises ( ValueError , policy . _get_domain , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , policy . _get_domain , '<STR_LIT>' ) <EOL> def test_recipientdomainsplit_get_domain_groups ( self ) : <EOL> policy = RecipientDomainSplit ( ) <EOL> groups , bad_rcpts = policy . _get_domain_groups ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( { '<STR_LIT>' : [ '<STR_LIT>' ] } , groups ) <EOL> self . assertEqual ( [ ] , bad_rcpts ) <EOL> groups , bad_rcpts = policy . _get_domain_groups ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } , groups ) <EOL> self . assertEqual ( [ ] , bad_rcpts ) <EOL> groups , bad_rcpts = policy . _get_domain_groups ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] } , groups ) <EOL> self . assertEqual ( [ ] , bad_rcpts ) <EOL> groups , bad_rcpts = policy . _get_domain_groups ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( { '<STR_LIT>' : [ '<STR_LIT>' ] } , groups ) <EOL> self . assertEqual ( [ '<STR_LIT>' ] , bad_rcpts ) <EOL> def test_recipientdomainsplit_apply ( self ) : <EOL> env = Envelope ( '<STR_LIT>' , [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> env . parse ( b"""<STR_LIT>""" ) <EOL> policy = RecipientDomainSplit ( ) <EOL> env1 , env2 = policy . apply ( env ) <EOL> self . assertEqual ( '<STR_LIT>' , env1 . sender ) <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , env1 . recipients ) <EOL> self . assertEqual ( b'<STR_LIT>' , env1 . message ) <EOL> self . assertEqual ( '<STR_LIT>' , env2 . sender ) <EOL> self . assertEqual ( [ '<STR_LIT>' ] , env2 . recipients ) <EOL> self . assertEqual ( b'<STR_LIT>' , env2 . message ) <EOL> def test_recipientdomainsplit_apply_allbadrcpts ( self ) : <EOL> env = Envelope ( '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> env . parse ( b"""<STR_LIT>""" ) <EOL> policy = RecipientDomainSplit ( ) <EOL> env1 , env2 = policy . apply ( env ) <EOL> self . assertEqual ( '<STR_LIT>' , env1 . sender ) <EOL> self . assertEqual ( [ '<STR_LIT>' ] , env1 . recipients ) <EOL> self . assertEqual ( b'<STR_LIT>' , env1 . message ) <EOL> self . assertEqual ( '<STR_LIT>' , env2 . sender ) <EOL> self . assertEqual ( [ '<STR_LIT>' ] , env2 . recipients ) <EOL> self . assertEqual ( b'<STR_LIT>' , env2 . message ) <EOL> def test_recipientdomainsplit_apply_onedomain ( self ) : <EOL> env = Envelope ( '<STR_LIT>' , [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> env . parse ( b'<STR_LIT>' ) <EOL> policy = RecipientDomainSplit ( ) <EOL> self . assertFalse ( policy . apply ( env ) ) </s>
