This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user