@@ -390,3 +390,80 @@ def test_accept_404s_under_wrong_election(self):
390390
391391 def test_edit_still_works_under_own_election (self ):
392392 self .assertEqual (self .client .get (self ._url ("nominations:nomination_edit" , self .election )).status_code , 200 )
393+
394+
395+ class NomineeListPreviewTests (TestCase ):
396+ """While nominations are open, the list previews the nominees relevant to the user."""
397+
398+ def setUp (self ):
399+ self .nominator = UserFactory (first_name = "Alan" , last_name = "Turing" )
400+ self .election = open_election ("2026 Board Election" )
401+ self .other_election = open_election ("2026 Packaging Council Election" , kind = packaging_council_kind ())
402+
403+ self .nominee = self ._nominee (self .election , "Grace" , "Hopper" )
404+ self ._nomination (self .election , self .nominator , self .nominee )
405+
406+ # The same user is a candidate in an unrelated election.
407+ self .nominator_as_nominee = Nominee .objects .create (user = self .nominator , election = self .other_election )
408+ self ._nomination (
409+ self .other_election , UserFactory (first_name = "Barbara" , last_name = "Liskov" ), self .nominator_as_nominee
410+ )
411+
412+ # Somebody else's nomination in the election under test.
413+ self .unrelated_nominee = self ._nominee (self .election , "Ada" , "Lovelace" )
414+ self ._nomination (self .election , UserFactory (first_name = "Ken" , last_name = "Thompson" ), self .unrelated_nominee )
415+
416+ def _nominee (self , election , first_name , last_name ):
417+ user = UserFactory (first_name = first_name , last_name = last_name )
418+ return Nominee .objects .create (user = user , election = election )
419+
420+ def _nomination (self , election , nominator , nominee ):
421+ return Nomination .objects .create (
422+ election = election ,
423+ nominator = nominator ,
424+ nominee = nominee ,
425+ name = f"{ nominee .user .first_name } { nominee .user .last_name } " ,
426+ email = nominee .user .email ,
427+ nomination_statement = "A strong candidate." ,
428+ )
429+
430+ def _url (self , election ):
431+ return reverse ("nominations:nominees_list" , kwargs = {"election" : election .slug })
432+
433+ def test_preview_lists_people_the_user_nominated (self ):
434+ self .client .force_login (self .nominator )
435+ response = self .client .get (self ._url (self .election ))
436+ self .assertEqual (response .status_code , 200 )
437+ self .assertIn (self .nominee , response .context ["object_list" ])
438+
439+ def test_preview_excludes_other_elections (self ):
440+ self .client .force_login (self .nominator )
441+ response = self .client .get (self ._url (self .election ))
442+ self .assertNotIn (self .nominator_as_nominee , response .context ["object_list" ])
443+
444+ def test_preview_excludes_nominations_by_other_people (self ):
445+ self .client .force_login (self .nominator )
446+ response = self .client .get (self ._url (self .election ))
447+ self .assertNotIn (self .unrelated_nominee , response .context ["object_list" ])
448+
449+ def test_preview_ignores_nominations_filed_under_another_election (self ):
450+ # A nomination whose election disagrees with its nominee's (possible via the admin).
451+ self ._nomination (self .other_election , self .nominator , self .unrelated_nominee )
452+ self .client .force_login (self .nominator )
453+ response = self .client .get (self ._url (self .election ))
454+ self .assertNotIn (self .unrelated_nominee , response .context ["object_list" ])
455+
456+ def test_preview_includes_the_user_as_a_candidate (self ):
457+ self .client .force_login (self .nominator )
458+ response = self .client .get (self ._url (self .other_election ))
459+ self .assertIn (self .nominator_as_nominee , response .context ["object_list" ])
460+
461+ def test_nominator_can_open_the_nominee_they_nominated (self ):
462+ self .client .force_login (self .nominator )
463+ response = self .client .get (self .nominee .get_absolute_url ())
464+ self .assertEqual (response .status_code , 200 )
465+
466+ def test_other_users_still_cannot_open_the_nominee (self ):
467+ self .client .force_login (UserFactory (first_name = "Guido" , last_name = "van Rossum" ))
468+ response = self .client .get (self .nominee .get_absolute_url ())
469+ self .assertEqual (response .status_code , 404 )
0 commit comments