|
| 1 | +# coding: utf-8 |
1 | 2 | import os |
2 | 3 |
|
| 4 | +import pytest |
3 | 5 | from bigpython.mail import EmailClient |
4 | 6 |
|
5 | | -def test_create_emailclient(): |
6 | | - mail = EmailClient('imap.naver.com', ssl=True) |
7 | | - configfile = 'login.cfg' |
| 7 | +def get_config(configfile='login.cfg'): |
8 | 8 | configfile = os.path.join(os.path.dirname(__file__), configfile) |
9 | 9 | if not os.path.exists(configfile): |
10 | 10 | raise FileNotFoundError('로그인 설정 파일 경로 문제: {}'.format( |
11 | 11 | os.path.abspath(configfile))) |
12 | | - mail.login(configfile=configfile) |
| 12 | + return configfile |
| 13 | + |
| 14 | +@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 |
| 20 | + |
| 21 | +def test_create_emailclient(): |
| 22 | + assert EmailClient('imap.naver.com', ssl=True) != None |
| 23 | + |
| 24 | +def test_login(): |
| 25 | + host = 'imap.naver.com' |
| 26 | + imapclient = EmailClient(host, ssl=True) |
| 27 | + assert imapclient.login(configfile=get_config()) |
| 28 | + |
| 29 | +def test_search(imapclient): |
| 30 | + message_ids = imapclient.search(['SUBJECT', '빅파이']) |
| 31 | + for header in imapclient.get_subjects(message_ids): |
| 32 | + assert '빅파이' in header['Subject'] |
0 commit comments