Skip to content

Commit

Permalink
delete user test
Browse files Browse the repository at this point in the history
  • Loading branch information
brassy-endomorph committed Sep 24, 2024
1 parent 6e74cbf commit 11eb524
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
10 changes: 9 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from hushline import create_app
from hushline.crypto import _SCRYPT_PARAMS
from hushline.db import db
from hushline.model import User, Username
from hushline.model import Message, User, Username

CONN_FMT_STR = "postgresql+psycopg://hushline:hushline@postgres:5432/{database}"
TEMPLATE_DB_NAME = "app_db_template"
Expand Down Expand Up @@ -163,3 +163,11 @@ def _pgp_user(client: FlaskClient, user: User) -> None:
with open("tests/test_pgp_key.txt") as f:
user.pgp_key = f.read()
db.session.commit()


@pytest.fixture()
def message(app: Flask, user: User) -> Message:
msg = Message(content=str(uuid4()), username_id=user.primary_username.id)
db.session.add(msg)
db.session.commit()
return msg
2 changes: 1 addition & 1 deletion tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask.testing import FlaskClient

from hushline.db import db
from hushline.model import Message, User
from hushline.model import Message, User, Username


def get_captcha_from_session(client: FlaskClient, username: str) -> str:
Expand Down
18 changes: 17 additions & 1 deletion tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from unittest.mock import ANY, MagicMock, patch
from uuid import uuid4

import pytest
from flask import url_for
from flask.testing import FlaskClient

from hushline.db import db
from hushline.model import SMTPEncryption, User, Username
from hushline.model import Message, SMTPEncryption, User, Username


@pytest.mark.usefixtures("_authenticated_user")
Expand Down Expand Up @@ -301,3 +302,18 @@ def test_update_smtp_settings_default_forwarding(
assert updated_user.smtp_password is None
assert updated_user.smtp_encryption.value == SMTPEncryption.default().value
assert updated_user.smtp_sender is None


@pytest.mark.usefixtures("_authenticated_user")
def test_delete_account(client: FlaskClient, user: User, message: Message) -> None:
# save these because SqlAlchemy is too smart about nullifying them on deletion
user_id = user.id
username_id = user.primary_username.id
msg_id = message.id

resp = client.post(url_for("settings.delete_account"), follow_redirects=True)
assert resp.status_code == 200
assert "Your account and all related information have been deleted." in resp.text
assert db.session.scalars(db.select(User).filter_by(id=user_id)).one_or_none() is None
assert db.session.scalars(db.select(Username).filter_by(id=username_id)).one_or_none() is None
assert db.session.scalars(db.select(Message).filter_by(id=msg_id)).one_or_none() is None

0 comments on commit 11eb524

Please sign in to comment.