diff --git a/tests/conftest.py b/tests/conftest.py index 8f4ee069..86c2d885 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -187,6 +187,28 @@ def _authenticated_user(client: FlaskClient, user: User) -> None: session["is_authenticated"] = True +@pytest.fixture() +def admin(app: Flask, user_password: str, database: str) -> User: + user = User(password=user_password, is_admin=True) + db.session.add(user) + db.session.flush() + + uuid_ish = str(uuid4())[0:12] + username = Username(user_id=user.id, _username=f"test-{uuid_ish}", is_primary=True) + db.session.add(username) + db.session.commit() + + return user + + +@pytest.fixture() +def _authenticated_admin(client: FlaskClient, admin: User) -> None: + with client.session_transaction() as session: + session["user_id"] = admin.id + session["username"] = admin.primary_username.username + session["is_authenticated"] = True + + @pytest.fixture() def _pgp_user(client: FlaskClient, user: User) -> None: with open("tests/test_pgp_key.txt") as f: diff --git a/tests/test_settings.py b/tests/test_settings.py index dfb920ea..88601ea0 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -6,7 +6,7 @@ from flask.testing import FlaskClient from hushline.db import db -from hushline.model import Message, SMTPEncryption, User, Username +from hushline.model import HostOrganization, Message, SMTPEncryption, User, Username @pytest.mark.usefixtures("_authenticated_user") @@ -478,3 +478,35 @@ def test_alias_change_directory_visibility( assert resp.status_code == 200 assert "Directory visibility updated successfully" in resp.text assert db.session.scalar(db.select(Username.show_in_directory).filter_by(id=user_alias.id)) + + +@pytest.mark.usefixtures("_authenticated_admin") +def test_update_brand_primary_color(client: FlaskClient, admin: User) -> None: + color = "#acab00" + resp = client.post( + url_for("settings.update_brand_primary_color"), + data={"brand_primary_hex_color": color}, + follow_redirects=True, + ) + assert resp.status_code == 200 + assert "Brand primary color updated successfully" in resp.text + + host_org = HostOrganization.fetch() + assert host_org + assert host_org.brand_primary_hex_color == color + + +@pytest.mark.usefixtures("_authenticated_admin") +def test_update_brand_app_name(client: FlaskClient, admin: User) -> None: + name = "h4cK3rZ" + resp = client.post( + url_for("settings.update_brand_app_name"), + data={"brand_app_name": name}, + follow_redirects=True, + ) + assert resp.status_code == 200 + assert "Brand app name updated successfully" in resp.text + + host_org = HostOrganization.fetch() + assert host_org + assert host_org.brand_app_name == name