Support demo users
Some checks failed
Run Tests / run-tests (push) Failing after 1m2s

This commit is contained in:
2026-05-01 17:41:42 +02:00
parent a88d1b4e79
commit 0632899f7a
11 changed files with 169 additions and 134 deletions

View File

@@ -2,19 +2,17 @@ import streamlit as st
import queries.crud as crud import queries.crud as crud
import themes as th import themes as th
from user import is_logged_in, is_login_enabled
is_login_enabled = hasattr(st, 'user') and hasattr(st.user, 'is_logged_in')
is_logged_in = is_login_enabled and st.user.is_logged_in
st.title("Settings") st.title("Settings")
if hasattr(st.session_state, 'user_name'): if hasattr(st.session_state, 'user_name') and st.session_state.user_name:
st.markdown(f"Currently logged in as **{st.session_state.user_name}**") st.markdown(f"Currently logged in as **{st.session_state.user_name}**")
st.header("Theme") st.header("Theme")
themes = st.session_state.themes themes = st.session_state.themes
with st.container(horizontal=True, width="stretch"): with st.container(horizontal=True, width="stretch"):
for theme in ["light", "dark"]: for theme in themes.keys():
if st.button(label=themes[theme]["button_face_label"], if st.button(label=themes[theme]["button_face_label"],
icon = themes[theme]["button_face_icon"], icon = themes[theme]["button_face_icon"],
disabled = (theme == st.session_state.current_theme), disabled = (theme == st.session_state.current_theme),
@@ -61,8 +59,9 @@ with st.container(key="settings-color-selector"):
""", width=400) """, width=400)
st.header("Actions") if is_login_enabled():
with st.container(): st.header("Actions")
if is_logged_in: with st.container():
if st.button("Logout", icon=":material/logout:", width="stretch"): if is_logged_in():
st.logout() if st.button("Logout", icon=":material/logout:", width="stretch"):
st.logout()

View File

@@ -2,9 +2,10 @@ from os import getenv
import streamlit as st import streamlit as st
from sqlalchemy.sql import text from sqlalchemy.sql import text
from streamlit.connections import BaseConnection from streamlit.connections import SQLConnection
def connection() -> BaseConnection:
def connection() -> SQLConnection:
_connection = st.connection("sql", url=getenv('DATABASE_URL'), ttl=0, autocommit=True) _connection = st.connection("sql", url=getenv('DATABASE_URL'), ttl=0, autocommit=True)
with _connection.session as configured_session: with _connection.session as configured_session:
configured_session.execute(text('PRAGMA foreign_keys=ON')) configured_session.execute(text('PRAGMA foreign_keys=ON'))

View File

@@ -139,6 +139,7 @@ def set_theme(theme:str):
logger.error(e) logger.error(e)
session.rollback() session.rollback()
def get_theme() -> str: def get_theme() -> str:
user_id = int(st.session_state.user_id) user_id = int(st.session_state.user_id)
try: try:

View File

@@ -1,6 +1,7 @@
import logging import logging
import streamlit as st import streamlit as st
from pandas import DataFrame
from sqlalchemy.sql import text from sqlalchemy.sql import text
from streamlit.user_info import UserInfoProxy from streamlit.user_info import UserInfoProxy
@@ -11,11 +12,9 @@ logger = logging.getLogger(__name__)
def find_user_by_oidc_id(oidc_user_id): def find_user_by_oidc_id(oidc_user_id):
return connection().query('SELECT * FROM users WHERE oidc_user_id = :id', params={'id': oidc_user_id}) return connection().query('SELECT * FROM users WHERE oidc_user_id = :id', params={'id': oidc_user_id})
def find_user_by_email(email): def find_user_by_email(email):
return connection().query('SELECT * FROM users WHERE email = :email', params={'email': email}) return connection().query('SELECT * FROM users WHERE email = :email', params={'email': email})
def find_default_user(): def find_default_user():
return find_user_by_email('default') return find_user_by_email('default')
@@ -30,40 +29,12 @@ def update_default_user(email, name, oidc_user_id):
raise e raise e
def create_user(email, name, oidc_user_id): def create_user(email, name, oidc_user_id) -> DataFrame:
with connection().session as session: with connection().session as session:
try: try:
logger.info("Creating new user %s", email) logger.info("Creating new user %s", email)
query = text('INSERT INTO users (email, name, oidc_user_id) VALUES (:email, :name, :user_id)') query = text('INSERT INTO users (email, name, oidc_user_id) VALUES (:email, :name, :user_id) RETURNING *')
session.execute(query, {'email': email, 'name': name, 'user_id': oidc_user_id}) return DataFrame(session.execute(query, {'email': email, 'name': name, 'user_id': oidc_user_id}))
return connection().query('SELECT * FROM users WHERE oidc_user_id = :id', params={'id': oidc_user_id})
except Exception as e: except Exception as e:
session.rollback() session.rollback()
raise e raise e
def set_user_in_session(user: UserInfoProxy):
email = user.email if hasattr(user, "email") else None
user_id = user.sub if hasattr(user, "sub") else None
name = user.name if hasattr(user, "name") else None
user_entity = find_user_by_oidc_id(user_id) if user_id else st.dataframe()
if user_entity.empty:
user_entity = find_user_by_email(email) if email else st.dataframe()
if user_entity.empty:
user_entity = find_default_user()
if user_entity.empty and email and name and user_id:
user_entity = create_user(email, name, user_id)
elif name:
update_default_user(email, name, user_id)
user_entity = find_user_by_oidc_id(user_id)
if not user_entity.empty:
st.session_state.user_id = user_entity["id"][0]
st.session_state.user_name = user_entity["name"][0]
st.session_state.user_email = user_entity["email"][0]
st.session_state.user_external_id = user_entity["oidc_user_id"][0]
st.session_state.current_theme = user_entity["theme"][0]
else:
logger.warn("No active user found!")

View File

@@ -1,10 +1,11 @@
import streamlit as st import streamlit as st
from streamlit import dialog from streamlit import dialog
import queries.user as user_queries import queries.user as user_queries
import random
from logger import init_logger from logger import init_logger
from styles import init_styles from styles import init_styles
from user import init_user, is_login_enabled, is_logged_in from user import init_user, is_login_enabled, is_logged_in, init_demo_user
from themes import init_themes from themes import init_themes
init_logger() init_logger()
@@ -12,18 +13,21 @@ init_user()
init_styles() init_styles()
init_themes() init_themes()
if is_login_enabled and not is_logged_in: if not is_login_enabled() or is_logged_in():
with st.container(width="stretch", height="stretch", horizontal_alignment="center"):
st.title("Daily Counter", width="stretch", text_alignment="center")
st.text("Please log in to use this app", width="stretch", text_alignment="center")
st.space()
if st.button("Log in"):
st.login()
else:
counters = st.Page("pages/counters.py", title="Counters", icon=":material/update:") counters = st.Page("pages/counters.py", title="Counters", icon=":material/update:")
stats = st.Page("pages/stats.py", title="Statistics", icon=":material/chart_data:") stats = st.Page("pages/stats.py", title="Statistics", icon=":material/chart_data:")
settings = st.Page("pages/settings.py", title=" ", icon=":material/menu:") settings = st.Page("pages/settings.py", title=" ", icon=":material/menu:")
pages = [counters, stats, settings] pages = [counters, stats, settings]
pg = st.navigation(position="top", pages=pages) pg = st.navigation(position="top", pages=pages)
pg.run() pg.run()
else:
with st.container(width="stretch", height="stretch", horizontal_alignment="center"):
st.title("Daily Counter", width="stretch", text_alignment="center")
st.text("Please log in to use this app", width="stretch", text_alignment="center")
st.space()
if st.button("Log in", width="stretch",icon=":material/login:"):
st.login()
if st.button("Demo", width="stretch", icon=":material/account_box:"):
init_demo_user()
st.rerun()

View File

@@ -1,6 +1,6 @@
import streamlit as st import streamlit as st
import queries
from queries import crud from queries import crud
from user import is_logged_in
def _load_css(filepath): def _load_css(filepath):
with open(filepath) as file: with open(filepath) as file:
@@ -8,16 +8,17 @@ def _load_css(filepath):
def _load_color_selector_styles(): def _load_color_selector_styles():
colors = crud.get_colors() if is_logged_in():
for idx, c in enumerate(colors.keys()): colors = crud.get_colors()
css_color = '#' + colors[c][0] for idx, c in enumerate(colors.keys()):
st.html(f""" css_color = '#' + colors[c][0]
<style> st.html(f"""
.st-key-new_counter_color_selector label:has(> input[value='{idx}']) {{ <style>
background-color: {css_color}; .st-key-new_counter_color_selector label:has(> input[value='{idx}']) {{
}} background-color: {css_color};
</style> }}
""") </style>
""")
def init_styles(): def init_styles():

View File

@@ -1,28 +1,28 @@
import streamlit as st import streamlit as st
from queries import crud from queries import crud
from user import is_logged_in, is_login_enabled
def init_themes(): def init_themes():
if 'themes' not in st.session_state: if 'themes' not in st.session_state:
st.session_state.themes = { st.session_state.themes = {
"dark": {
"theme.base": "dark",
"theme.backgroundColor": "black",
"theme.primaryColor": "#c98bdb",
"theme.secondaryBackgroundColor": "#5591f5",
"theme.textColor": "white",
"button_face_label": "Dark",
"button_face_icon": ":material/dark_mode:"
},
"light": { "light": {
"theme.base": "light", "theme.base": "light",
"theme.backgroundColor": "white", "theme.backgroundColor": "white",
"theme.primaryColor": "#5591f5", "theme.primaryColor": "#5591f5",
"theme.secondaryBackgroundColor": "#82E1D7",
"theme.textColor": "#0a1464", "theme.textColor": "#0a1464",
"button_face_label": "Light", "button_face_label": "Light",
"button_face_icon": ":material/light_mode:" "button_face_icon": ":material/light_mode:"
}, },
"dark": {
"theme.base": "dark",
"theme.backgroundColor": "black",
"theme.primaryColor": "#c98bdb",
"theme.textColor": "white",
"button_face_label": "Dark",
"button_face_icon": ":material/dark_mode:"
}
} }
if 'current_theme' not in st.session_state: if 'current_theme' not in st.session_state:
@@ -30,7 +30,10 @@ def init_themes():
change_theme('light') change_theme('light')
def change_theme(theme): def change_theme(theme):
crud.set_theme(theme) if is_logged_in():
crud.set_theme(theme)
st.session_state.current_theme = theme
for key, val in st.session_state.themes[theme].items(): for key, val in st.session_state.themes[theme].items():
if key.startswith("theme"): if key.startswith("theme"):
st._config.set_option(key, val) st._config.set_option(key, val)

View File

@@ -1,8 +1,60 @@
import logging
import random
import queries.user as user_queries import queries.user as user_queries
import streamlit as st import streamlit as st
is_login_enabled = hasattr(st, 'user') and hasattr(st.user, 'is_logged_in') from pandas import DataFrame
is_logged_in = is_login_enabled and st.user.is_logged_in from streamlit.user_info import UserInfoProxy
logger = logging.getLogger(__name__)
def is_login_enabled() -> bool:
return hasattr(st, 'user') and hasattr(st.user, 'is_logged_in')
def is_demo_user() -> bool:
return hasattr(st.session_state, 'user_is_demo') and st.session_state.user_is_demo
def is_logged_in() -> bool:
return not is_login_enabled() or is_demo_user() or (is_login_enabled() and st.user.is_logged_in)
def init_user(): def init_user():
user_queries.set_user_in_session(st.user) if not is_demo_user():
set_user_in_session(st.user)
def set_user_in_session(user: UserInfoProxy):
email = user.email if hasattr(user, "email") else None
user_id = user.sub if hasattr(user, "sub") else None
name = user.name if hasattr(user, "name") else None
user_entity = user_queries.find_user_by_oidc_id(user_id) if user_id else DataFrame()
if user_entity.empty:
user_entity = user_queries.find_user_by_email(email) if email else DataFrame()
if user_entity.empty:
user_entity = user_queries.find_default_user()
if user_entity.empty and email and name and user_id:
user_entity = user_queries.create_user(email, name, user_id)
elif name:
user_queries.update_default_user(email, name, user_id)
user_entity = user_queries.find_user_by_oidc_id(user_id)
if not user_entity.empty:
st.session_state.user_id = int(user_entity["id"][0])
st.session_state.user_name = user_entity["name"][0]
st.session_state.user_email = user_entity["email"][0]
st.session_state.user_external_id = user_entity["oidc_user_id"][0]
st.session_state.current_theme = user_entity["theme"][0]
st.session_state.user_is_demo = False
else:
logger.warning("No active user found!")
def init_demo_user():
demo_id = ''.join(random.choice('0123456789abcdefghijklmnopqrstuvwxyz') for i in range(6))
demo_user = user_queries.create_user(f"demo+{demo_id}@internal", f"Demo user {demo_id}", None)
st.session_state.user_id = int(demo_user["id"][0])
st.session_state.user_name = demo_user["name"][0]
st.session_state.user_email = demo_user["email"][0]
st.session_state.user_external_id = demo_user["oidc_user_id"][0]
st.session_state.current_theme = demo_user["theme"][0]
st.session_state.user_is_demo = True

View File

@@ -17,17 +17,17 @@ def test_all_daily_stats():
query = text(""" query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment) INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES VALUES
(1, 1, date(), 1), (1, 1, date('2026-06-15'), 1),
(1, 1, date(date(), '-1 days'), 2), (1, 1, date(date('2026-06-15'), '-1 days'), 2),
(1, 1, date(date(), '-3 days'), 3), (1, 1, date(date('2026-06-15'), '-3 days'), 3),
(2, 1, date(), 2), (2, 1, date('2026-06-15'), 2),
(2, 1, date(date(), '-1 days'), 4), (2, 1, date(date('2026-06-15'), '-1 days'), 4),
(2, 1, date(date(), '-3 days'), 6) (2, 1, date(date('2026-06-15'), '-3 days'), 6)
""") """)
session.execute(query) session.execute(query)
session.commit() session.commit()
stats = daily_stats.get_all_daily_analytics() stats = daily_stats.get_all_daily_analytics('2026-06-15')
assert json.loads(stats[::-1]["counters"].iloc[0])["Test"] == 1 assert json.loads(stats[::-1]["counters"].iloc[0])["Test"] == 1
assert json.loads(stats[::-1]["counters"].iloc[0])["Test2"] == 2 assert json.loads(stats[::-1]["counters"].iloc[0])["Test2"] == 2
assert json.loads(stats[::-1]["counters"].iloc[1])["Test"] == 2 assert json.loads(stats[::-1]["counters"].iloc[1])["Test"] == 2
@@ -43,14 +43,14 @@ def test_daily_stats():
query = text(""" query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment) INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES VALUES
(1, 1, date(), 1), (1, 1, date('2026-06-15'), 1),
(1, 1, date(date(), '-1 days'), 2), (1, 1, date(date('2026-06-15'), '-1 days'), 2),
(1, 1, date(date(), '-3 days'), 3) (1, 1, date(date('2026-06-15'), '-3 days'), 3)
""") """)
session.execute(query) session.execute(query)
session.commit() session.commit()
stats = daily_stats.get_daily_analytics(1) stats = daily_stats.get_daily_analytics(1, '2026-06-15')
assert stats["count"][0] == 1 assert stats["count"][0] == 1
assert stats["count"][1] == 2 assert stats["count"][1] == 2
assert stats["count"][2] == 0 assert stats["count"][2] == 0
@@ -64,17 +64,17 @@ def test_all_monthly_stats():
query = text(""" query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment) INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES VALUES
(1, 1, date(), 1), (1, 1, date('2026-06-15'), 1),
(1, 1, date(date(), 'start of month', '-1 month'), 2), (1, 1, date(date('2026-06-15'), 'start of month', '-1 month'), 2),
(1, 1, date(date(), 'start of month', '-3 months'), 3), (1, 1, date(date('2026-06-15'), 'start of month', '-3 months'), 3),
(2, 1, date(), 2), (2, 1, date('2026-06-15'), 2),
(2, 1, date(date(), 'start of month', '-2 months'), 4), (2, 1, date(date('2026-06-15'), 'start of month', '-2 months'), 4),
(2, 1, date(date(), 'start of month', '-3 months'), 6) (2, 1, date(date('2026-06-15'), 'start of month', '-3 months'), 6)
""") """)
session.execute(query) session.execute(query)
session.commit() session.commit()
stats = monthly_stats.get_all_monthly_analytics() stats = monthly_stats.get_all_monthly_analytics('2026-06-15')
assert json.loads(stats[::-1]["counters"].iloc[0])["Test"] == 1 assert json.loads(stats[::-1]["counters"].iloc[0])["Test"] == 1
assert json.loads(stats[::-1]["counters"].iloc[0])["Test2"] == 2 assert json.loads(stats[::-1]["counters"].iloc[0])["Test2"] == 2
assert json.loads(stats[::-1]["counters"].iloc[1])["Test"] == 2 assert json.loads(stats[::-1]["counters"].iloc[1])["Test"] == 2
@@ -89,14 +89,14 @@ def test_monthly_stats():
query = text(""" query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment) INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES VALUES
(1, 1, date(), 1), (1, 1, date('2026-06-15'), 1),
(1, 1, date(date(), '-1 months'), 2), (1, 1, date(date('2026-06-15'), '-1 months'), 2),
(1, 1, date(date(), '-3 months'), 3) (1, 1, date(date('2026-06-15'), '-3 months'), 3)
""") """)
session.execute(query) session.execute(query)
session.commit() session.commit()
stats = monthly_stats.get_monthly_analytics(1) stats = monthly_stats.get_monthly_analytics(1, '2026-06-15')
assert stats[::-1]["count"].iloc[0] == 1 assert stats[::-1]["count"].iloc[0] == 1
assert stats[::-1]["count"].iloc[1] == 2 assert stats[::-1]["count"].iloc[1] == 2
assert stats[::-1]["count"].iloc[2] == 0 assert stats[::-1]["count"].iloc[2] == 0
@@ -110,17 +110,17 @@ def test_all_yearly_stats():
query = text(""" query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment) INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES VALUES
(1, 1, date(), 1), (1, 1, date('2026-06-15'), 1),
(1, 1, date(date(), '-1 year'), 2), (1, 1, date(date('2026-06-15'), '-1 year'), 2),
(1, 1, date(date(), '-3 years'), 3), (1, 1, date(date('2026-06-15'), '-3 years'), 3),
(2, 1, date(), 2), (2, 1, date('2026-06-15'), 2),
(2, 1, date(date(), '-2 years'), 4), (2, 1, date(date('2026-06-15'), '-2 years'), 4),
(2, 1, date(date(), '-3 years'), 6) (2, 1, date(date('2026-06-15'), '-3 years'), 6)
""") """)
session.execute(query) session.execute(query)
session.commit() session.commit()
stats = yearly_stats.get_all_yearly_analytics() stats = yearly_stats.get_all_yearly_analytics('2026-06-15')
assert json.loads(stats[::-1]["counters"].iloc[0])["Test"] == 1 assert json.loads(stats[::-1]["counters"].iloc[0])["Test"] == 1
assert json.loads(stats[::-1]["counters"].iloc[0])["Test2"] == 2 assert json.loads(stats[::-1]["counters"].iloc[0])["Test2"] == 2
assert json.loads(stats[::-1]["counters"].iloc[1])["Test"] == 2 assert json.loads(stats[::-1]["counters"].iloc[1])["Test"] == 2
@@ -135,14 +135,14 @@ def test_yearly_stats():
query = text(""" query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment) INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES VALUES
(1, 1, date(), 1), (1, 1, date('2026-06-15'), 1),
(1, 1, date(date(), '-1 years'), 2), (1, 1, date(date('2026-06-15'), '-1 years'), 2),
(1, 1, date(date(), '-3 years'), 3) (1, 1, date(date('2026-06-15'), '-3 years'), 3)
""") """)
session.execute(query) session.execute(query)
session.commit() session.commit()
stats = yearly_stats.get_yearly_analytics(1) stats = yearly_stats.get_yearly_analytics(1, '2026-06-15')
assert stats[::-1]["count"].iloc[0] == 1 assert stats[::-1]["count"].iloc[0] == 1
assert stats[::-1]["count"].iloc[1] == 2 assert stats[::-1]["count"].iloc[1] == 2
assert stats[::-1]["count"].iloc[2] == 0 assert stats[::-1]["count"].iloc[2] == 0
@@ -156,17 +156,17 @@ def test_all_weekly_stats():
query = text(""" query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment) INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES VALUES
(1, 1, date(), 1), (1, 1, date('2026-06-15'), 1),
(1, 1, date(date(), '-7 days'), 2), (1, 1, date(date('2026-06-15'), '-7 days'), 2),
(1, 1, date(date(), '-21 days'), 3), (1, 1, date(date('2026-06-15'), '-21 days'), 3),
(2, 1, date(), 2), (2, 1, date('2026-06-15'), 2),
(2, 1, date(date(), '-14 days'), 4), (2, 1, date(date('2026-06-15'), '-14 days'), 4),
(2, 1, date(date(), '-21 days'), 6) (2, 1, date(date('2026-06-15'), '-21 days'), 6)
""") """)
session.execute(query) session.execute(query)
session.commit() session.commit()
stats = weekly_stats.get_all_weekly_analytics() stats = weekly_stats.get_all_weekly_analytics('2026-06-15')
assert json.loads(stats[::-1]["counters"].iloc[0])["Test"] == 1 assert json.loads(stats[::-1]["counters"].iloc[0])["Test"] == 1
assert json.loads(stats[::-1]["counters"].iloc[0])["Test2"] == 2 assert json.loads(stats[::-1]["counters"].iloc[0])["Test2"] == 2
assert json.loads(stats[::-1]["counters"].iloc[1])["Test"] == 2 assert json.loads(stats[::-1]["counters"].iloc[1])["Test"] == 2
@@ -181,14 +181,14 @@ def test_weekly_stats():
query = text(""" query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment) INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES VALUES
(1, 1, date(), 1), (1, 1, date('2026-06-15'), 1),
(1, 1, date(date(), '-7 days'), 2), (1, 1, date(date('2026-06-15'), '-7 days'), 2),
(1, 1, date(date(), '-21 days'), 3) (1, 1, date(date('2026-06-15'), '-21 days'), 3)
""") """)
session.execute(query) session.execute(query)
session.commit() session.commit()
stats = weekly_stats.get_weekly_analytics(1) stats = weekly_stats.get_weekly_analytics(1, '2026-06-15')
assert stats["count"][0] == 1 assert stats["count"][0] == 1
assert stats["count"][1] == 2 assert stats["count"][1] == 2
assert stats["count"][2] == 0 assert stats["count"][2] == 0

View File

@@ -1,40 +1,41 @@
import streamlit import streamlit
import queries.user as user import queries.user as user_query
import user
def test_get_default_user(): def test_get_default_user():
users = user.find_default_user() users = user_query.find_default_user()
assert len(users) == 1 assert len(users) == 1
assert users["email"][0] == "default" assert users["email"][0] == "default"
def test_update_default_user_and_find_user(): def test_update_default_user_and_find_user():
user.update_default_user(email="test@testbase.com", name="Test User", oidc_user_id="1111-2222-3333") user_query.update_default_user(email="test@testbase.com", name="Test User", oidc_user_id="1111-2222-3333")
users = user.find_default_user() users = user_query.find_default_user()
assert len(users) == 0 assert len(users) == 0
users = user.find_user_by_oidc_id("1111-2222-3333") users = user_query.find_user_by_oidc_id("1111-2222-3333")
assert len(users) == 1 assert len(users) == 1
assert users["email"][0] == "test@testbase.com" assert users["email"][0] == "test@testbase.com"
assert users["name"][0] == "Test User" assert users["name"][0] == "Test User"
assert users["oidc_user_id"][0] == "1111-2222-3333" assert users["oidc_user_id"][0] == "1111-2222-3333"
users = user.find_user_by_email("test@testbase.com") users = user_query.find_user_by_email("test@testbase.com")
assert len(users) == 1 assert len(users) == 1
assert users["email"][0] == "test@testbase.com" assert users["email"][0] == "test@testbase.com"
assert users["name"][0] == "Test User" assert users["name"][0] == "Test User"
assert users["oidc_user_id"][0] == "1111-2222-3333" assert users["oidc_user_id"][0] == "1111-2222-3333"
def test_add_user(): def test_add_user():
user.create_user(email="test@testbase.com", name="Test User", oidc_user_id="333-4444-5555") user_query.create_user(email="test@testbase.com", name="Test User", oidc_user_id="333-4444-5555")
users = user.find_user_by_oidc_id("333-4444-5555") users = user_query.find_user_by_oidc_id("333-4444-5555")
assert len(users) == 1 assert len(users) == 1
assert users["email"][0] == "test@testbase.com" assert users["email"][0] == "test@testbase.com"
assert users["name"][0] == "Test User" assert users["name"][0] == "Test User"
assert users["oidc_user_id"][0] == "333-4444-5555" assert users["oidc_user_id"][0] == "333-4444-5555"
users = user.find_user_by_email("test@testbase.com") users = user_query.find_user_by_email("test@testbase.com")
assert len(users) == 1 assert len(users) == 1
assert users["email"][0] == "test@testbase.com" assert users["email"][0] == "test@testbase.com"
assert users["name"][0] == "Test User" assert users["name"][0] == "Test User"

View File

@@ -5,7 +5,7 @@ def test_change_theme(app):
app.run() app.run()
app.switch_page("pages/settings.py").run() app.switch_page("pages/settings.py").run()
assert app.session_state.current_theme =="light", "Light theme should be default" assert app.session_state.current_theme == "light", "Light theme should be default"
assert app.button[0].label == "Light" assert app.button[0].label == "Light"
assert app.button[0].disabled == True, "Light theme should be selected" assert app.button[0].disabled == True, "Light theme should be selected"
@@ -16,6 +16,8 @@ def test_change_theme(app):
app.button[1].click().run() app.button[1].click().run()
assert "dark" == crud.get_theme() assert "dark" == crud.get_theme()
assert app.button[0].disabled == False, "Light theme should be de-selected"
assert app.button[1].disabled == True, "Dark theme should be selected"
def test_change_color_palette(app): def test_change_color_palette(app):
app.run() app.run()