From d37c41e99fff60fdf9c6176706517f0591756406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 5 Oct 2019 13:48:29 +0200 Subject: [PATCH] kfet/test_views: more eloquent test names --- kfet/tests/test_views.py | 56 +++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/kfet/tests/test_views.py b/kfet/tests/test_views.py index 41e579bf..a5b564cb 100644 --- a/kfet/tests/test_views.py +++ b/kfet/tests/test_views.py @@ -209,14 +209,14 @@ class AccountReadViewTests(ViewTestCaseMixin, TestCase): auth_user = "team" auth_forbidden = [None, "user"] - # Forbidden users should get a 404 here, to avoid leaking trigrams + # Users with forbidden access users should get a 404 here, to avoid leaking trigrams # See issue #224 def test_forbidden(self): for user in self.auth_forbidden: - self.check_forbidden(user, self.url_expected) - self.check_forbidden(user, "/k-fet/accounts/NEX") + self.assertRedirectsToLoginOr404(user, self.url_expected) + self.assertRedirectsToLoginOr404(user, "/k-fet/accounts/NEX") - def check_forbidden(self, user, url): + def assertRedirectsToLoginOr404(self, user, url): client = Client() if user is None: response = client.get(url) @@ -315,15 +315,17 @@ class AccountUpdateViewTests(ViewTestCaseMixin, TestCase): "team1": create_team("team1", "101", perms=["kfet.change_account"]), } - # Forbidden users should get a 404 here, to avoid leaking trigrams + # Users with forbidden access users should get a 404 here, to avoid leaking trigrams # See issue #224 def test_forbidden(self): for method in ["get", "post"]: for user in self.auth_forbidden: - self.check_forbidden(user, method, self.url_expected) - self.check_forbidden(user, method, "/k-fet/accounts/NEX/edit") + self.assertRedirectsToLoginOr404(user, method, self.url_expected) + self.assertRedirectsToLoginOr404( + user, method, "/k-fet/accounts/NEX/edit" + ) - def check_forbidden(self, user, method, url): + def assertRedirectsToLoginOr404(self, user, method, url): client = Client() meth = getattr(client, method) if user is None: @@ -595,14 +597,16 @@ class AccountStatOperationListViewTests(ViewTestCaseMixin, TestCase): def get_users_extra(self): return {"user1": create_user("user1", "001")} - # Forbidden users should get a 404 here, to avoid leaking trigrams + # Users with forbidden access users should get a 404 here, to avoid leaking trigrams # See issue #224 def test_forbidden(self): for user in self.auth_forbidden: - self.check_forbidden(user, self.url_expected) - self.check_forbidden(user, "/k-fet/accounts/NEX/stat/operations/list") + self.assertRedirectsToLoginOr404(user, self.url_expected) + self.assertRedirectsToLoginOr404( + user, "/k-fet/accounts/NEX/stat/operations/list" + ) - def check_forbidden(self, user, url): + def assertRedirectsToLoginOr404(self, user, url): client = Client() if user is None: response = client.get(url) @@ -675,14 +679,16 @@ class AccountStatOperationViewTests(ViewTestCaseMixin, TestCase): auth_user = "user1" auth_forbidden = [None, "user", "team"] - # Forbidden users should get a 404 here, to avoid leaking trigrams + # Users with forbidden access users should get a 404 here, to avoid leaking trigrams # See issue #224 def test_forbidden(self): for user in self.auth_forbidden: - self.check_forbidden(user, self.url_expected) - self.check_forbidden(user, "/k-fet/accounts/NEX/stat/operations") + self.assertRedirectsToLoginOr404(user, self.url_expected) + self.assertRedirectsToLoginOr404( + user, "/k-fet/accounts/NEX/stat/operations" + ) - def check_forbidden(self, user, url): + def assertRedirectsToLoginOr404(self, user, url): client = Client() if user is None: response = client.get(url) @@ -710,14 +716,16 @@ class AccountStatBalanceListViewTests(ViewTestCaseMixin, TestCase): auth_user = "user1" auth_forbidden = [None, "user", "team"] - # Forbidden users should get a 404 here, to avoid leaking trigrams + # Users with forbidden access users should get a 404 here, to avoid leaking trigrams # See issue #224 def test_forbidden(self): for user in self.auth_forbidden: - self.check_forbidden(user, self.url_expected) - self.check_forbidden(user, "/k-fet/accounts/NEX/stat/balance/list") + self.assertRedirectsToLoginOr404(user, self.url_expected) + self.assertRedirectsToLoginOr404( + user, "/k-fet/accounts/NEX/stat/balance/list" + ) - def check_forbidden(self, user, url): + def assertRedirectsToLoginOr404(self, user, url): client = Client() if user is None: response = client.get(url) @@ -774,14 +782,14 @@ class AccountStatBalanceViewTests(ViewTestCaseMixin, TestCase): auth_user = "user1" auth_forbidden = [None, "user", "team"] - # Forbidden users should get a 404 here, to avoid leaking trigrams + # Users with forbidden access users should get a 404 here, to avoid leaking trigrams # See issue #224 def test_forbidden(self): for user in self.auth_forbidden: - self.check_forbidden(user, self.url_expected) - self.check_forbidden(user, "/k-fet/accounts/NEX/stat/balance") + self.assertRedirectsToLoginOr404(user, self.url_expected) + self.assertRedirectsToLoginOr404(user, "/k-fet/accounts/NEX/stat/balance") - def check_forbidden(self, user, url): + def assertRedirectsToLoginOr404(self, user, url): client = Client() if user is None: response = client.get(url)