mirror of
https://github.com/chatmail/relay.git
synced 2026-05-15 19:14:44 +00:00
refactor dovecot tests, move online tests one level up
This commit is contained in:
33
online-tests/conftest.py
Normal file
33
online-tests/conftest.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import imaplib
|
||||
import itertools
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def imap():
|
||||
return ImapConn("c1.testrun.org")
|
||||
|
||||
|
||||
class ImapConn:
|
||||
def __init__(self, host):
|
||||
self.host = host
|
||||
|
||||
def connect(self):
|
||||
print(f"imap-connect {self.host}")
|
||||
self.conn = imaplib.IMAP4_SSL(self.host)
|
||||
|
||||
def login(self, user, password):
|
||||
print(f"imap-login {user!r} {password!r}")
|
||||
self.conn.login(user, password)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def gencreds():
|
||||
count = itertools.count()
|
||||
|
||||
def gen():
|
||||
while 1:
|
||||
num = next(count)
|
||||
yield f"user{num}", f"password{num}"
|
||||
|
||||
return lambda: next(gen())
|
||||
18
online-tests/test_login.py
Normal file
18
online-tests/test_login.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import pytest
|
||||
import imaplib
|
||||
|
||||
|
||||
class TestDovecot:
|
||||
def test_login_ok(self, imap, gencreds):
|
||||
user, password = gencreds()
|
||||
imap.connect()
|
||||
imap.login(user, password)
|
||||
|
||||
def test_login_fail(self, imap, gencreds):
|
||||
user, password = gencreds()
|
||||
imap.connect()
|
||||
imap.login(user, password)
|
||||
imap.connect()
|
||||
with pytest.raises(imaplib.IMAP4.error) as excinfo:
|
||||
imap.login(user, password + "wrong")
|
||||
assert "AUTHENTICATIONFAILED" in str(excinfo)
|
||||
Reference in New Issue
Block a user