Skip to content

Commit

Permalink
app branding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brassy-endomorph committed Sep 28, 2024
1 parent 5d2c99f commit c4b06fa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
22 changes: 22 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 33 additions & 1 deletion tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

0 comments on commit c4b06fa

Please sign in to comment.