1
0
Fork 0

i think that this works now

This commit is contained in:
Arthur K. 2026-03-08 09:44:33 +03:00
parent a3c843d63c
commit fc555244a8
Signed by: wzray
GPG key ID: B97F30FDC4636357
13 changed files with 715 additions and 505 deletions

View file

@ -1,4 +1,6 @@
from emails import pop_account, peek_accounts, remaining_count, _parse_line
import pytest
from emails import pop_account, has_accounts, mark_done, mark_failed, _parse_line
import emails as em
@ -25,57 +27,103 @@ def test_parse_line_malformed():
assert _parse_line("no-colon-here") is None
def test_peek_accounts(tmp_path, monkeypatch):
@pytest.mark.asyncio
async def test_has_accounts_true(tmp_path, monkeypatch):
f = tmp_path / "emails.txt"
f.write_text("a@b.com:pass1\nc@d.com:pass2\n")
monkeypatch.setattr(em, "EMAILS_FILE", f)
accounts = peek_accounts()
assert len(accounts) == 2
assert accounts[0].email == "a@b.com"
assert accounts[1].email == "c@d.com"
# peek doesn't consume
assert remaining_count() == 2
assert await has_accounts() is True
def test_pop_account(tmp_path, monkeypatch):
f = tmp_path / "emails.txt"
f.write_text("a@b.com:pass1\nc@d.com:pass2\ne@f.com:pass3\n")
monkeypatch.setattr(em, "EMAILS_FILE", f)
acc = pop_account()
assert acc is not None
assert acc.email == "a@b.com"
assert remaining_count() == 2
acc = pop_account()
assert acc is not None
assert acc.email == "c@d.com"
assert remaining_count() == 1
def test_pop_account_empty(tmp_path, monkeypatch):
@pytest.mark.asyncio
async def test_has_accounts_false(tmp_path, monkeypatch):
f = tmp_path / "emails.txt"
f.write_text("")
monkeypatch.setattr(em, "EMAILS_FILE", f)
assert pop_account() is None
assert await has_accounts() is False
def test_pop_account_missing_file(tmp_path, monkeypatch):
@pytest.mark.asyncio
async def test_has_accounts_missing_file(tmp_path, monkeypatch):
monkeypatch.setattr(em, "EMAILS_FILE", tmp_path / "nope.txt")
assert pop_account() is None
assert await has_accounts() is False
def test_pop_skips_comments(tmp_path, monkeypatch):
f = tmp_path / "emails.txt"
f.write_text("# first is comment\na@b.com:pass1\n")
monkeypatch.setattr(em, "EMAILS_FILE", f)
@pytest.mark.asyncio
async def test_pop_account_removes_from_file(tmp_path, monkeypatch):
emails_file = tmp_path / "emails.txt"
emails_file.write_text("a@b.com:pass1\nc@d.com:pass2\ne@f.com:pass3\n")
monkeypatch.setattr(em, "EMAILS_FILE", emails_file)
monkeypatch.setattr(em, "DATA_DIR", tmp_path)
monkeypatch.setattr(em, "DONE_FILE", tmp_path / "done.txt")
monkeypatch.setattr(em, "FAILED_FILE", tmp_path / "failed.txt")
acc = pop_account()
acc = await pop_account()
assert acc is not None
assert acc.email == "a@b.com"
# Comment line stays in file
remaining = f.read_text().strip()
assert remaining == "# first is comment"
remaining = emails_file.read_text()
assert "a@b.com" not in remaining
assert "c@d.com" in remaining
@pytest.mark.asyncio
async def test_pop_account_empty(tmp_path, monkeypatch):
f = tmp_path / "emails.txt"
f.write_text("")
monkeypatch.setattr(em, "EMAILS_FILE", f)
monkeypatch.setattr(em, "DATA_DIR", tmp_path)
monkeypatch.setattr(em, "DONE_FILE", tmp_path / "done.txt")
monkeypatch.setattr(em, "FAILED_FILE", tmp_path / "failed.txt")
assert await pop_account() is None
@pytest.mark.asyncio
async def test_pop_account_missing_file(tmp_path, monkeypatch):
monkeypatch.setattr(em, "EMAILS_FILE", tmp_path / "nope.txt")
assert await pop_account() is None
@pytest.mark.asyncio
async def test_mark_done(tmp_path, monkeypatch):
done_file = tmp_path / "done.txt"
monkeypatch.setattr(em, "DATA_DIR", tmp_path)
monkeypatch.setattr(em, "DONE_FILE", done_file)
await mark_done("test@example.com")
content = done_file.read_text()
assert "test@example.com" in content
@pytest.mark.asyncio
async def test_mark_failed(tmp_path, monkeypatch):
failed_file = tmp_path / "failed.txt"
monkeypatch.setattr(em, "DATA_DIR", tmp_path)
monkeypatch.setattr(em, "FAILED_FILE", failed_file)
await mark_failed("test@example.com")
content = failed_file.read_text()
assert "test@example.com" in content
@pytest.mark.asyncio
async def test_pop_all_accounts(tmp_path, monkeypatch):
f = tmp_path / "emails.txt"
f.write_text("a@b.com:pass1\n")
monkeypatch.setattr(em, "EMAILS_FILE", f)
monkeypatch.setattr(em, "DATA_DIR", tmp_path)
monkeypatch.setattr(em, "DONE_FILE", tmp_path / "done.txt")
monkeypatch.setattr(em, "FAILED_FILE", tmp_path / "failed.txt")
acc1 = await pop_account()
assert acc1.email == "a@b.com"
acc2 = await pop_account()
assert acc2 is None
assert await has_accounts() is False