@@ -12,50 +12,55 @@ def get_config(configfile='login.cfg'):
1212 return configfile
1313
1414@pytest .fixture (scope = 'module' )
15- def imapclient (request ):
16- host = getattr (request .module , 'host' , 'imap. naver.com' )
17- imapclient = EmailClient (host , ssl = True )
18- imapclient .login (configfile = get_config ())
19- return imapclient
15+ def mailclient (request ):
16+ host = getattr (request .module , 'host' , 'naver.com' )
17+ mailclient = EmailClient (host )
18+ mailclient .login (configfile = get_config ())
19+ return mailclient
2020
2121def test_create_emailclient ():
22- assert EmailClient ('imap. naver.com' , ssl = True ) != None
22+ assert EmailClient ('naver.com' ) != None
2323
2424def test_login ():
25- host = 'imap. naver.com'
26- imapclient = EmailClient (host , ssl = True )
27- assert imapclient .login (configfile = get_config ())
25+ host = 'naver.com'
26+ mailclient = EmailClient (host )
27+ assert mailclient .login (configfile = get_config ())
2828
29- def test_search (imapclient ):
30- message_ids = imapclient .search (['SUBJECT' , '빅파이' ])
31- for header in imapclient .get_subjects (message_ids ):
29+ def test_search (mailclient ):
30+ message_ids = mailclient .search (['SUBJECT' , '빅파이' ])
31+ for header in mailclient .get_subjects (message_ids ):
3232 assert '빅파이' in header ['Subject' ]
3333
34- def test_get_text (imapclient ):
35- message_ids = imapclient .search (['SUBJECT' , '빅파이' ])
34+ def test_get_text (mailclient ):
35+ message_ids = mailclient .search (['SUBJECT' , '빅파이' ])
3636 for mid in message_ids :
37- for content_type , text in imapclient .get_text (mid ):
37+ for content_type , text in mailclient .get_text (mid ):
3838 assert content_type .startswith ('text' )
3939
40- def test_download_attachments (imapclient ):
41- message_ids = imapclient .search (['SUBJECT' , '빅파이' ])
40+ def test_download_attachments (mailclient ):
41+ message_ids = mailclient .search (['SUBJECT' , '빅파이' ])
4242
4343 download_files = []
4444
4545 for mid in message_ids :
46- attachment_list = imapclient .download_attachments (mid )
46+ attachment_list = mailclient .download_attachments (mid )
4747 for filepath in attachment_list :
4848 assert os .path .exists (filepath )
4949 download_files .append (filepath )
5050
5151 for mid in message_ids :
5252 userhome = os .path .expanduser ('~' )
5353 target_dir = os .path .join (userhome , 'Downloads' )
54- attachment_list = imapclient .download_attachments (mid , target_dir = target_dir )
54+ attachment_list = mailclient .download_attachments (mid , target_dir = target_dir )
5555 for filepath in attachment_list :
5656 assert os .path .exists (filepath )
5757 download_files .append (filepath )
5858
59-
6059 for filepath in download_files :
6160 os .unlink (filepath )
61+
62+
63+ def test_sendmail (mailclient ):
64+ msg = 'Subject: I am seongjoo\n Thank you.'
65+ result = mailclient .send_message ('seongjoo@codebasic.co' , msg )
66+ assert not result
0 commit comments