Add user color settings
Some checks failed
Run Tests / run-tests (push) Failing after 1m3s

This commit is contained in:
2026-04-30 14:16:57 +02:00
parent bd9ff7191a
commit 8ae8bc7a24
12 changed files with 291 additions and 68 deletions

View File

@@ -5,6 +5,7 @@ import pytest
from alembic import config
from pytest_alembic.config import Config
from streamlit.testing.v1 import AppTest
import streamlit as st
logger = logging.getLogger(__name__)
@@ -18,11 +19,20 @@ def setup_database(alembic_runner):
@pytest.fixture
def alembic_config() -> Config:
logging.info("Setting up alembic config")
logger.info("Setting up alembic config")
alembic_cfg = config.Config(toml_file="pyproject.toml")
alembic_cfg.set_main_option("sqlalchemy.url", os.getenv("DATABASE_URL", ""))
return Config(alembic_config=alembic_cfg)
@pytest.fixture(autouse=True)
def user_config():
logger.info("Setting up test user")
st.user = None
st.session_state.user_id = 1
st.session_state.user_name = "Test User"
st.session_state.user_email = "test@test.local"
st.session_state.user_external_id = "111-2222-3333"
@pytest.fixture
def app() -> AppTest:
return AppTest.from_file("app/streamlit_app.py")

View File

@@ -14,6 +14,7 @@ def test_create_counter():
assert counters["type"][0] == CounterType.SIMPLE
assert counters["color"][0] == '020122'
def test_remove_counter():
crud.create_counter("Test", CounterType.SIMPLE, "020122")
assert len(crud.get_counters()) == 1
@@ -37,3 +38,22 @@ def test_increment_counter():
assert daily_stats["count"][0] == 2
def test_get_color_palettes():
palettes = crud.get_color_palettes()
assert len(palettes) == 5
assert palettes['name'][0] == "Flames"
def test_get_user_colors():
palettes = crud.get_color_palettes()
palette_id = crud.get_color_palette()
assert palette_id == 1
assert palettes.loc[palettes['id'] == palette_id]["color1"][0] == 'F2F3AE'
crud.set_color_palette(2)
palettes = crud.get_color_palettes()
palette_id = crud.get_color_palette()
assert palette_id == 2
assert palettes.loc[palettes['id'] == palette_id]["color1"][1] == '2B4141'

View File

@@ -15,14 +15,14 @@ def test_all_daily_stats():
crud.create_counter("Test2", CounterType.SIMPLE, "020122")
with connection().session as session:
query = text("""
INSERT INTO entries (counter_id, "timestamp", increment)
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(1, date(), 1),
(1, date(date(), '-1 days'), 2),
(1, date(date(), '-3 days'), 3),
(2, date(), 2),
(2, date(date(), '-1 days'), 4),
(2, date(date(), '-3 days'), 6)
(1, 1, date(), 1),
(1, 1, date(date(), '-1 days'), 2),
(1, 1, date(date(), '-3 days'), 3),
(2, 1, date(), 2),
(2, 1, date(date(), '-1 days'), 4),
(2, 1, date(date(), '-3 days'), 6)
""")
session.execute(query)
session.commit()
@@ -41,11 +41,11 @@ def test_daily_stats():
crud.create_counter("Test", CounterType.SIMPLE, "020122")
with connection().session as session:
query = text("""
INSERT INTO entries (counter_id, "timestamp", increment)
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(1, date(), 1),
(1, date(date(), '-1 days'), 2),
(1, date(date(), '-3 days'), 3)
(1, 1, date(), 1),
(1, 1, date(date(), '-1 days'), 2),
(1, 1, date(date(), '-3 days'), 3)
""")
session.execute(query)
session.commit()
@@ -62,14 +62,14 @@ def test_all_monthly_stats():
crud.create_counter("Test2", CounterType.SIMPLE, "020122")
with connection().session as session:
query = text("""
INSERT INTO entries (counter_id, "timestamp", increment)
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(1, date(), 1),
(1, date(date(), '-1 month'), 2),
(1, date(date(), '-3 months'), 3),
(2, date(), 2),
(2, date(date(), '-2 months'), 4),
(2, date(date(), '-3 months'), 6)
(1, 1, date(), 1),
(1, 1, date(date(), 'start of month', '-1 month'), 2),
(1, 1, date(date(), 'start of month', '-3 months'), 3),
(2, 1, date(), 2),
(2, 1, date(date(), 'start of month', '-2 months'), 4),
(2, 1, date(date(), 'start of month', '-3 months'), 6)
""")
session.execute(query)
session.commit()
@@ -87,11 +87,11 @@ def test_monthly_stats():
crud.create_counter("Test", CounterType.SIMPLE, "020122")
with connection().session as session:
query = text("""
INSERT INTO entries (counter_id, "timestamp", increment)
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(1, date(), 1),
(1, date(date(), '-1 months'), 2),
(1, date(date(), '-3 months'), 3)
(1, 1, date(), 1),
(1, 1, date(date(), '-1 months'), 2),
(1, 1, date(date(), '-3 months'), 3)
""")
session.execute(query)
session.commit()
@@ -108,14 +108,14 @@ def test_all_yearly_stats():
crud.create_counter("Test2", CounterType.SIMPLE, "020122")
with connection().session as session:
query = text("""
INSERT INTO entries (counter_id, "timestamp", increment)
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(1, date(), 1),
(1, date(date(), '-1 year'), 2),
(1, date(date(), '-3 years'), 3),
(2, date(), 2),
(2, date(date(), '-2 years'), 4),
(2, date(date(), '-3 years'), 6)
(1, 1, date(), 1),
(1, 1, date(date(), '-1 year'), 2),
(1, 1, date(date(), '-3 years'), 3),
(2, 1, date(), 2),
(2, 1, date(date(), '-2 years'), 4),
(2, 1, date(date(), '-3 years'), 6)
""")
session.execute(query)
session.commit()
@@ -133,11 +133,11 @@ def test_yearly_stats():
crud.create_counter("Test", CounterType.SIMPLE, "020122")
with connection().session as session:
query = text("""
INSERT INTO entries (counter_id, "timestamp", increment)
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(1, date(), 1),
(1, date(date(), '-1 years'), 2),
(1, date(date(), '-3 years'), 3)
(1, 1, date(), 1),
(1, 1, date(date(), '-1 years'), 2),
(1, 1, date(date(), '-3 years'), 3)
""")
session.execute(query)
session.commit()
@@ -154,14 +154,14 @@ def test_all_weekly_stats():
crud.create_counter("Test2", CounterType.SIMPLE, "020122")
with connection().session as session:
query = text("""
INSERT INTO entries (counter_id, "timestamp", increment)
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(1, date(), 1),
(1, date(date(), '-7 days'), 2),
(1, date(date(), '-21 days'), 3),
(2, date(), 2),
(2, date(date(), '-14 days'), 4),
(2, date(date(), '-21 days'), 6)
(1, 1, date(), 1),
(1, 1, date(date(), '-7 days'), 2),
(1, 1, date(date(), '-21 days'), 3),
(2, 1, date(), 2),
(2, 1, date(date(), '-14 days'), 4),
(2, 1, date(date(), '-21 days'), 6)
""")
session.execute(query)
session.commit()
@@ -179,11 +179,11 @@ def test_weekly_stats():
crud.create_counter("Test", CounterType.SIMPLE, "020122")
with connection().session as session:
query = text("""
INSERT INTO entries (counter_id, "timestamp", increment)
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(1, date(), 1),
(1, date(date(), '-7 days'), 2),
(1, date(date(), '-21 days'), 3)
(1, 1, date(), 1),
(1, 1, date(date(), '-7 days'), 2),
(1, 1, date(date(), '-21 days'), 3)
""")
session.execute(query)
session.commit()

View File

@@ -0,0 +1,15 @@
def test_change_color_palette(app):
app.run()
app.switch_page("pages/settings.py").run()
assert app.button[0].disabled == True
assert app.button[0].label == "Flames **(selected)**"
app.button[1].click().run()
assert app.button[0].disabled == False
assert app.button[0].label == "Flames"
assert app.button[1].disabled == True
assert app.button[1].label == "Water **(selected)**"