kfet/test_views: more eloquent test names

This commit is contained in:
Martin Pépin 2019-10-05 13:48:29 +02:00
parent a4ecd344d0
commit d37c41e99f

View file

@ -209,14 +209,14 @@ class AccountReadViewTests(ViewTestCaseMixin, TestCase):
auth_user = "team" auth_user = "team"
auth_forbidden = [None, "user"] 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 # See issue #224
def test_forbidden(self): def test_forbidden(self):
for user in self.auth_forbidden: for user in self.auth_forbidden:
self.check_forbidden(user, self.url_expected) self.assertRedirectsToLoginOr404(user, self.url_expected)
self.check_forbidden(user, "/k-fet/accounts/NEX") self.assertRedirectsToLoginOr404(user, "/k-fet/accounts/NEX")
def check_forbidden(self, user, url): def assertRedirectsToLoginOr404(self, user, url):
client = Client() client = Client()
if user is None: if user is None:
response = client.get(url) response = client.get(url)
@ -315,15 +315,17 @@ class AccountUpdateViewTests(ViewTestCaseMixin, TestCase):
"team1": create_team("team1", "101", perms=["kfet.change_account"]), "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 # See issue #224
def test_forbidden(self): def test_forbidden(self):
for method in ["get", "post"]: for method in ["get", "post"]:
for user in self.auth_forbidden: for user in self.auth_forbidden:
self.check_forbidden(user, method, self.url_expected) self.assertRedirectsToLoginOr404(user, method, self.url_expected)
self.check_forbidden(user, method, "/k-fet/accounts/NEX/edit") self.assertRedirectsToLoginOr404(
user, method, "/k-fet/accounts/NEX/edit"
)
def check_forbidden(self, user, method, url): def assertRedirectsToLoginOr404(self, user, method, url):
client = Client() client = Client()
meth = getattr(client, method) meth = getattr(client, method)
if user is None: if user is None:
@ -595,14 +597,16 @@ class AccountStatOperationListViewTests(ViewTestCaseMixin, TestCase):
def get_users_extra(self): def get_users_extra(self):
return {"user1": create_user("user1", "001")} 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 # See issue #224
def test_forbidden(self): def test_forbidden(self):
for user in self.auth_forbidden: for user in self.auth_forbidden:
self.check_forbidden(user, self.url_expected) self.assertRedirectsToLoginOr404(user, self.url_expected)
self.check_forbidden(user, "/k-fet/accounts/NEX/stat/operations/list") self.assertRedirectsToLoginOr404(
user, "/k-fet/accounts/NEX/stat/operations/list"
)
def check_forbidden(self, user, url): def assertRedirectsToLoginOr404(self, user, url):
client = Client() client = Client()
if user is None: if user is None:
response = client.get(url) response = client.get(url)
@ -675,14 +679,16 @@ class AccountStatOperationViewTests(ViewTestCaseMixin, TestCase):
auth_user = "user1" auth_user = "user1"
auth_forbidden = [None, "user", "team"] 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 # See issue #224
def test_forbidden(self): def test_forbidden(self):
for user in self.auth_forbidden: for user in self.auth_forbidden:
self.check_forbidden(user, self.url_expected) self.assertRedirectsToLoginOr404(user, self.url_expected)
self.check_forbidden(user, "/k-fet/accounts/NEX/stat/operations") self.assertRedirectsToLoginOr404(
user, "/k-fet/accounts/NEX/stat/operations"
)
def check_forbidden(self, user, url): def assertRedirectsToLoginOr404(self, user, url):
client = Client() client = Client()
if user is None: if user is None:
response = client.get(url) response = client.get(url)
@ -710,14 +716,16 @@ class AccountStatBalanceListViewTests(ViewTestCaseMixin, TestCase):
auth_user = "user1" auth_user = "user1"
auth_forbidden = [None, "user", "team"] 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 # See issue #224
def test_forbidden(self): def test_forbidden(self):
for user in self.auth_forbidden: for user in self.auth_forbidden:
self.check_forbidden(user, self.url_expected) self.assertRedirectsToLoginOr404(user, self.url_expected)
self.check_forbidden(user, "/k-fet/accounts/NEX/stat/balance/list") self.assertRedirectsToLoginOr404(
user, "/k-fet/accounts/NEX/stat/balance/list"
)
def check_forbidden(self, user, url): def assertRedirectsToLoginOr404(self, user, url):
client = Client() client = Client()
if user is None: if user is None:
response = client.get(url) response = client.get(url)
@ -774,14 +782,14 @@ class AccountStatBalanceViewTests(ViewTestCaseMixin, TestCase):
auth_user = "user1" auth_user = "user1"
auth_forbidden = [None, "user", "team"] 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 # See issue #224
def test_forbidden(self): def test_forbidden(self):
for user in self.auth_forbidden: for user in self.auth_forbidden:
self.check_forbidden(user, self.url_expected) self.assertRedirectsToLoginOr404(user, self.url_expected)
self.check_forbidden(user, "/k-fet/accounts/NEX/stat/balance") self.assertRedirectsToLoginOr404(user, "/k-fet/accounts/NEX/stat/balance")
def check_forbidden(self, user, url): def assertRedirectsToLoginOr404(self, user, url):
client = Client() client = Client()
if user is None: if user is None:
response = client.get(url) response = client.get(url)