From 8b7bc53a3cfeaf66643fa30c3d16cc623e78cdd1 Mon Sep 17 00:00:00 2001 From: Scott Yargeau Date: Fri, 15 Jun 2018 01:08:44 -0400 Subject: [PATCH 1/2] Add FT for unranked players on leaderboard --- functional_tests/test_home_page.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/functional_tests/test_home_page.py b/functional_tests/test_home_page.py index b083245..bef9b9d 100644 --- a/functional_tests/test_home_page.py +++ b/functional_tests/test_home_page.py @@ -10,6 +10,7 @@ from django.contrib.sessions.backends.db import SessionStore from selenium import webdriver from selenium.webdriver.support.ui import Select +from selenium.common.exceptions import NoSuchElementException from leaderboard.models import Player, Match @@ -286,7 +287,7 @@ def test_leaderboard(self): losing_score=10 ) - # Bob loads PongBoard and sees him ranked first, and Sue in second + # Bob loads PongBoard and sees him above Sue self.browser.get(self.live_server_url) player_rankings = self.browser.find_elements_by_id('player-ranking') self.assertEqual(len(player_rankings), 2) @@ -295,4 +296,26 @@ def test_leaderboard(self): self.assertIn('Sue Hope', player_rankings[1].text) self.assertIn('985', player_rankings[1].text) + # However, he realizes they are unranked + self.assertIn('N/A', player_rankings[0].text) + unranked_warning = self.browser.find_element_by_id('unranked-warning') + self.assertEqual( + unranked_warning.text, + 'Note: you must play a minimum of 5 games before being ranked.' + ) + + # Submit 4 more matches, and reload + for _ in range(4): + Match.objects.create( + winner=bob, + loser=sue, + winning_score=21, + losing_score=19 + ) + self.browser.get(self.live_server_url) + + # They are now ranked, and the warning is no longer there + with self.assertRaises(NoSuchElementException): + self.browser.find_element_by_id('unranked-warning') + # TODO: test each line in leaderboard for specific stats From c55de5be8dc200c7340728921e19134b35af7443 Mon Sep 17 00:00:00 2001 From: Scott Yargeau Date: Fri, 15 Jun 2018 01:09:28 -0400 Subject: [PATCH 2/2] Put unranked players at bottom of leaderboard --- leaderboard/templates/home.html | 35 ++++++++++++++++++++++++--------- leaderboard/views.py | 7 +++++-- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/leaderboard/templates/home.html b/leaderboard/templates/home.html index 3519d78..8dbc343 100644 --- a/leaderboard/templates/home.html +++ b/leaderboard/templates/home.html @@ -46,21 +46,38 @@

PongBoard

PPG AvgDiff - {% for ranking in leaderboard %} + {% for ranked_player in ranked_players %} {{ forloop.counter }} - {{ ranking.player.full_name }} - {{ ranking.rating }} - {{ ranking.games_played }} - {{ ranking.wins }} - {{ ranking.losses }} - {{ ranking.win_percent|percentage:1 }} - {{ ranking.points_per_game|floatformat }} - {{ ranking.avg_point_differential|stringformat:"+.1f" }} + {{ ranked_player.player.full_name }} + {{ ranked_player.rating }} + {{ ranked_player.games_played }} + {{ ranked_player.wins }} + {{ ranked_player.losses }} + {{ ranked_player.win_percent|percentage:1 }} + {{ ranked_player.points_per_game|floatformat }} + {{ ranked_player.avg_point_differential|stringformat:"+.1f" }} + + {% endfor %} + {% for unranked_player in unranked_players %} + + N/A + {{ unranked_player.player.full_name }} + {{ unranked_player.rating }} + {{ unranked_player.games_played }} + {{ unranked_player.wins }} + {{ unranked_player.losses }} + {{ unranked_player.win_percent|percentage:1 }} + {{ unranked_player.points_per_game|floatformat }} + {{ unranked_player.avg_point_differential|stringformat:"+.1f" }} {% endfor %} + {% if unranked_players %} +

Note: you must play a minimum of 5 games before being ranked.

+ {% endif %} +