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

@@ -17,17 +17,17 @@ def test_all_daily_stats():
query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(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)
(1, 1, date('2026-06-15'), 1),
(1, 1, date(date('2026-06-15'), '-1 days'), 2),
(1, 1, date(date('2026-06-15'), '-3 days'), 3),
(2, 1, date('2026-06-15'), 2),
(2, 1, date(date('2026-06-15'), '-1 days'), 4),
(2, 1, date(date('2026-06-15'), '-3 days'), 6)
""")
session.execute(query)
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])["Test2"] == 2
assert json.loads(stats[::-1]["counters"].iloc[1])["Test"] == 2
@@ -43,14 +43,14 @@ def test_daily_stats():
query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(1, 1, date(), 1),
(1, 1, date(date(), '-1 days'), 2),
(1, 1, date(date(), '-3 days'), 3)
(1, 1, date('2026-06-15'), 1),
(1, 1, date(date('2026-06-15'), '-1 days'), 2),
(1, 1, date(date('2026-06-15'), '-3 days'), 3)
""")
session.execute(query)
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"][1] == 2
assert stats["count"][2] == 0
@@ -64,17 +64,17 @@ def test_all_monthly_stats():
query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(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)
(1, 1, date('2026-06-15'), 1),
(1, 1, date(date('2026-06-15'), 'start of month', '-1 month'), 2),
(1, 1, date(date('2026-06-15'), 'start of month', '-3 months'), 3),
(2, 1, date('2026-06-15'), 2),
(2, 1, date(date('2026-06-15'), 'start of month', '-2 months'), 4),
(2, 1, date(date('2026-06-15'), 'start of month', '-3 months'), 6)
""")
session.execute(query)
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])["Test2"] == 2
assert json.loads(stats[::-1]["counters"].iloc[1])["Test"] == 2
@@ -89,14 +89,14 @@ def test_monthly_stats():
query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(1, 1, date(), 1),
(1, 1, date(date(), '-1 months'), 2),
(1, 1, date(date(), '-3 months'), 3)
(1, 1, date('2026-06-15'), 1),
(1, 1, date(date('2026-06-15'), '-1 months'), 2),
(1, 1, date(date('2026-06-15'), '-3 months'), 3)
""")
session.execute(query)
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[1] == 2
assert stats[::-1]["count"].iloc[2] == 0
@@ -110,17 +110,17 @@ def test_all_yearly_stats():
query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(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)
(1, 1, date('2026-06-15'), 1),
(1, 1, date(date('2026-06-15'), '-1 year'), 2),
(1, 1, date(date('2026-06-15'), '-3 years'), 3),
(2, 1, date('2026-06-15'), 2),
(2, 1, date(date('2026-06-15'), '-2 years'), 4),
(2, 1, date(date('2026-06-15'), '-3 years'), 6)
""")
session.execute(query)
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])["Test2"] == 2
assert json.loads(stats[::-1]["counters"].iloc[1])["Test"] == 2
@@ -135,14 +135,14 @@ def test_yearly_stats():
query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(1, 1, date(), 1),
(1, 1, date(date(), '-1 years'), 2),
(1, 1, date(date(), '-3 years'), 3)
(1, 1, date('2026-06-15'), 1),
(1, 1, date(date('2026-06-15'), '-1 years'), 2),
(1, 1, date(date('2026-06-15'), '-3 years'), 3)
""")
session.execute(query)
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[1] == 2
assert stats[::-1]["count"].iloc[2] == 0
@@ -156,17 +156,17 @@ def test_all_weekly_stats():
query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(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)
(1, 1, date('2026-06-15'), 1),
(1, 1, date(date('2026-06-15'), '-7 days'), 2),
(1, 1, date(date('2026-06-15'), '-21 days'), 3),
(2, 1, date('2026-06-15'), 2),
(2, 1, date(date('2026-06-15'), '-14 days'), 4),
(2, 1, date(date('2026-06-15'), '-21 days'), 6)
""")
session.execute(query)
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])["Test2"] == 2
assert json.loads(stats[::-1]["counters"].iloc[1])["Test"] == 2
@@ -181,14 +181,14 @@ def test_weekly_stats():
query = text("""
INSERT INTO entries (counter_id, user_id, "timestamp", increment)
VALUES
(1, 1, date(), 1),
(1, 1, date(date(), '-7 days'), 2),
(1, 1, date(date(), '-21 days'), 3)
(1, 1, date('2026-06-15'), 1),
(1, 1, date(date('2026-06-15'), '-7 days'), 2),
(1, 1, date(date('2026-06-15'), '-21 days'), 3)
""")
session.execute(query)
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"][1] == 2
assert stats["count"][2] == 0

View File

@@ -1,40 +1,41 @@
import streamlit
import queries.user as user
import queries.user as user_query
import user
def test_get_default_user():
users = user.find_default_user()
users = user_query.find_default_user()
assert len(users) == 1
assert users["email"][0] == "default"
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
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 users["email"][0] == "test@testbase.com"
assert users["name"][0] == "Test User"
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 users["email"][0] == "test@testbase.com"
assert users["name"][0] == "Test User"
assert users["oidc_user_id"][0] == "1111-2222-3333"
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 users["email"][0] == "test@testbase.com"
assert users["name"][0] == "Test User"
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 users["email"][0] == "test@testbase.com"
assert users["name"][0] == "Test User"