def test_email_dump(): """ Test that Email.dump() dumps a single email. """ body = "Test email." sendmail("*****@*****.**", "*****@*****.**", body) assert Email.count() == 1 stdout = io.StringIO() Email.dump(file=stdout) content = stdout.getvalue() assert "== Email #1 ==" in content
def test_request_post_deletion_autoaccept(client: TestClient, auser: User, pkgbase: PackageBase, caplog: pytest.LogCaptureFixture): """ Test the request route for deletion as maintainer. """ caplog.set_level(DEBUG) now = time.utcnow() auto_delete_age = config.getint("options", "auto_delete_age") with db.begin(): pkgbase.ModifiedTS = now - auto_delete_age + 100 endpoint = f"/pkgbase/{pkgbase.Name}/request" data = {"comments": "Test request.", "type": "deletion"} with client as request: resp = request.post(endpoint, data=data, cookies=auser.cookies) assert resp.status_code == int(HTTPStatus.SEE_OTHER) pkgreq = db.query(PackageRequest).filter( PackageRequest.PackageBaseName == pkgbase.Name).first() assert pkgreq is not None assert pkgreq.ReqTypeID == DELETION_ID assert pkgreq.Status == ACCEPTED_ID # A RequestOpenNotification should've been sent out. assert Email.count() == 2 Email.dump() # Check the content of the open notification. email = Email(1) expr = r"^\[PRQ#%d\] Deletion Request for [^ ]+$" % pkgreq.ID assert re.match(expr, email.headers.get("Subject")) # Check the content of the close notification. email = Email(2) expr = r"^\[PRQ#%d\] Deletion Request for [^ ]+ Accepted$" % pkgreq.ID assert re.match(expr, email.headers.get("Subject")) # Check logs. expr = r"New request #\d+ is marked for auto-deletion." assert re.search(expr, caplog.text)