aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Sebastiaan Zeeff <[email protected]>2019-10-19 20:18:40 +0200
committerGravatar Sebastiaan Zeeff <[email protected]>2019-10-19 20:18:40 +0200
commit9989170efe2f4afced40defc346179d046ebb9aa (patch)
treea45d27002f7f3702d6bc5c1941145e1d40f7ecb8
parentFix indentation and missing word in docstring (diff)
Make test less fragile and improve test name
The `test_returns_400_for_active_infractions_of_type_that_cannot_be_ active` test relied on the order in which the validation was done since it contained incompatible combinations of arguments. The test has been changed to make sure the data is valid except for the thing we actually want to test. I have also tried to improve the name of the test that tests the `test_unique_constraint_accepts_active_infraction_after_inactive_ infraction` test. It now includes the logic of what it does, but not the entire name of the test it's testing.
-rw-r--r--pydis_site/apps/api/tests/test_infractions.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/pydis_site/apps/api/tests/test_infractions.py b/pydis_site/apps/api/tests/test_infractions.py
index f1591b4b..7a54640e 100644
--- a/pydis_site/apps/api/tests/test_infractions.py
+++ b/pydis_site/apps/api/tests/test_infractions.py
@@ -316,18 +316,22 @@ class CreationTests(APISubdomainTestCase):
def test_returns_400_for_active_infraction_of_type_that_cannot_be_active(self):
"""Test if the API rejects active infractions for types that cannot be active."""
url = reverse('bot:infraction-list', host='api')
- restricted_types = ('note', 'warning', 'kick')
+ restricted_types = (
+ ('note', True),
+ ('warning', False),
+ ('kick', False),
+ )
- for infraction_type in restricted_types:
+ for infraction_type, hidden in restricted_types:
with self.subTest(infraction_type=infraction_type):
invalid_infraction = {
'user': self.user.id,
'actor': self.user.id,
'type': infraction_type,
'reason': 'Take me on!',
- 'hidden': True,
+ 'hidden': hidden,
'active': True,
- 'expires_at': '2019-10-04T12:52:00+00:00'
+ 'expires_at': None,
}
response = self.client.post(url, data=invalid_infraction)
self.assertEqual(response.status_code, 400)
@@ -450,7 +454,7 @@ class CreationTests(APISubdomainTestCase):
self.fail("An unexpected IntegrityError was raised.")
@patch(f"{__name__}.Infraction")
- def test_the_accepts_active_infraction_after_inactive_infractions_test(self, infraction_patch):
+ def test_if_accepts_active_infraction_test_catches_integrity_error(self, infraction_patch):
"""Does the test properly catch the IntegrityError and raise an AssertionError?"""
infraction_patch.objects.create.side_effect = IntegrityError
with self.assertRaises(AssertionError, msg="An unexpected IntegrityError was raised."):