1+ from datetime import timedelta
2+
3+ from django .utils import timezone
4+
5+ from conferences .tests .factories import ConferenceFactory
6+
7+
18def test_dashboard_requires_authentication (client ):
29 response = client .get ("/dashboard" )
310 inertia_response = client .get ("/dashboard" , headers = {"X-Inertia" : "true" })
11+ conference_response = client .get ("/dashboard/pycon-2026" )
412
513 assert response .status_code == 302
614 assert response .url == "/dashboard/login?next=/dashboard"
715 assert inertia_response .status_code == 302
816 assert inertia_response .url == "/dashboard/login?next=/dashboard"
17+ assert conference_response .status_code == 302
18+ assert conference_response .url == "/dashboard/login?next=/dashboard/pycon-2026"
919
1020
1121def test_dashboard_renders_inertia_page (client , user ):
@@ -27,6 +37,8 @@ def test_dashboard_supports_inertia_requests(client, user):
2737 assert response .headers ["X-Inertia" ] == "true"
2838 assert response .json ()["component" ] == "Dashboard"
2939 assert response .json ()["props" ]["user" ]["email" ] == "simulated@user.it"
40+ assert response .json ()["props" ]["conferences" ] == []
41+ assert response .json ()["props" ]["selectedConference" ] is None
3042
3143
3244def test_dashboard_shares_authenticated_user (client , user ):
@@ -41,6 +53,51 @@ def test_dashboard_shares_authenticated_user(client, user):
4153 }
4254
4355
56+ def test_dashboard_redirects_to_latest_conference (client , user ):
57+ client .force_login (user )
58+ ConferenceFactory (
59+ code = "pycon-2025" ,
60+ start = timezone .now () - timedelta (days = 365 ),
61+ )
62+ latest_conference = ConferenceFactory (
63+ code = "pycon-2026" ,
64+ start = timezone .now (),
65+ )
66+
67+ response = client .get ("/dashboard" )
68+
69+ assert response .status_code == 302
70+ assert response .url == f"/dashboard/{ latest_conference .code } "
71+
72+
73+ def test_dashboard_uses_conference_from_url (client , user ):
74+ client .force_login (user )
75+ selected_conference = ConferenceFactory (code = "pycon-2025" )
76+ ConferenceFactory (code = "pycon-2026" )
77+
78+ response = client .get (
79+ f"/dashboard/{ selected_conference .code } " ,
80+ headers = {"X-Inertia" : "true" },
81+ )
82+
83+ assert response .status_code == 200
84+ assert response .json ()["props" ]["selectedConference" ]["code" ] == "pycon-2025"
85+ assert {
86+ conference ["code" ] for conference in response .json ()["props" ]["conferences" ]
87+ } == {
88+ "pycon-2025" ,
89+ "pycon-2026" ,
90+ }
91+
92+
93+ def test_dashboard_returns_404_for_unknown_conference (client , user ):
94+ client .force_login (user )
95+
96+ response = client .get ("/dashboard/unknown" )
97+
98+ assert response .status_code == 404
99+
100+
44101def test_dashboard_login_renders_inertia_page (client ):
45102 response = client .get ("/dashboard/login" )
46103
0 commit comments