Commit cb5dd796 authored by Maxime Emschwiller's avatar Maxime Emschwiller
Browse files

refacto(backend): code refactoring to include stats about contributions

parent a95d5f68
...@@ -15,6 +15,7 @@ class CustomAdminSite(admin.AdminSite): ...@@ -15,6 +15,7 @@ class CustomAdminSite(admin.AdminSite):
Custom admin site used to add a trigger_cron view Custom admin site used to add a trigger_cron view
on the admin site provided by django on the admin site provided by django
""" """
def get_urls(self): def get_urls(self):
urls = super().get_urls() urls = super().get_urls()
urls += [path("trigger_cron/", self.admin_view(trigger_cron))] urls += [path("trigger_cron/", self.admin_view(trigger_cron))]
......
from base_app.admin import admin_site from base_app.admin import admin_site
from stats_app.models import DailyConnections from stats_app.models import DailyConnections, DailyExchangeContributionsInfo
admin_site.register(DailyConnections) admin_site.register(DailyConnections)
admin_site.register(DailyExchangeContributionsInfo)
...@@ -3,7 +3,7 @@ from datetime import timedelta ...@@ -3,7 +3,7 @@ from datetime import timedelta
from django.test import TestCase from django.test import TestCase
from base_app.models import User from base_app.models import User
from stats_app.compute_stats import update_all_stats from stats_app.compute_stats import update_daily_connections
from stats_app.models import DailyConnections from stats_app.models import DailyConnections
from stats_app.utils import get_daily_connections, get_today_as_datetime from stats_app.utils import get_daily_connections, get_today_as_datetime
...@@ -29,7 +29,7 @@ class StatsConnectionsTest(TestCase): ...@@ -29,7 +29,7 @@ class StatsConnectionsTest(TestCase):
daily_connections = get_daily_connections() daily_connections = get_daily_connections()
self.assertEqual(daily_connections, 10) self.assertEqual(daily_connections, 10)
def test_update_all_stats(self): def test_update_daily_connections(self):
today = get_today_as_datetime() today = get_today_as_datetime()
yesterday = today - timedelta(days=1) yesterday = today - timedelta(days=1)
for i in range(10): for i in range(10):
...@@ -37,7 +37,7 @@ class StatsConnectionsTest(TestCase): ...@@ -37,7 +37,7 @@ class StatsConnectionsTest(TestCase):
username=f"{i}", defaults=dict(last_login=yesterday) username=f"{i}", defaults=dict(last_login=yesterday)
) )
update_all_stats() update_daily_connections()
yesterday_daily_connections = DailyConnections.objects.get(date=yesterday) yesterday_daily_connections = DailyConnections.objects.get(date=yesterday)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment