From c8cd59f6d392f6cb1605998d4b4bf7cf636d996d Mon Sep 17 00:00:00 2001 From: Antoine Albertelli <antoinealb@google.com> Date: Tue, 11 Jun 2024 17:32:19 +0200 Subject: [PATCH] Work around flaky test The test that we are modifying here was flakey as it would stop working if the PlayerFactory picked a short first name, which in turn would get mangled when running through clean_name. The workaround for now is to force-set the name to use in this test. I also left a TODO to properly address this in the clean_name function, as I cannot really do it for now. --- api/tests/test_event_results.py | 7 +++++-- championship/views/results.py | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/api/tests/test_event_results.py b/api/tests/test_event_results.py index f969a632..38159b7f 100644 --- a/api/tests/test_event_results.py +++ b/api/tests/test_event_results.py @@ -108,7 +108,7 @@ class TestEventResultsAPI(APITestCase): self.assertTrue(player.eventplayerresult_set.exists()) def test_send_results_player_clean_name(self): - player = PlayerFactory() + player = PlayerFactory(name="Antoine Albertelli") self.client.login(**self.credentials) data = { "results": [ @@ -124,7 +124,10 @@ class TestEventResultsAPI(APITestCase): resp = self.client.patch(self.url, data=data, format="json") # Check that the event got associated with the player - self.assertTrue(player.eventplayerresult_set.exists()) + self.assertTrue( + player.eventplayerresult_set.exists(), + f"Should have results for {player.name}", + ) def test_upload_deletes_old_results(self): player = PlayerFactory() diff --git a/championship/views/results.py b/championship/views/results.py index da368d9c..f76c84f4 100644 --- a/championship/views/results.py +++ b/championship/views/results.py @@ -122,12 +122,16 @@ def clean_name(name: str) -> str: >>> clean_name('antoine albertelli') 'Antoine Albertelli' - Note lower case words are only capitalized if the word has more than 3 letters (Short terms like "van", ""der", "da" shouldn't be capital). >>> clean_name('Antoine van Albertelli') 'Antoine van Albertelli' + #Â TODO: Shorter first names like Joe will not be capitalized correctly for + now as they are assumed to be particles, like "von", "de" or "van". + #Â >>> clean_name('joe uldry') + #Â 'Joe Uldry' + >>> clean_name('Antoine J. Albertelli') 'Antoine J. Albertelli' """ -- GitLab