aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/tests
diff options
context:
space:
mode:
authorGravatar bast <[email protected]>2021-05-30 16:14:12 -0700
committerGravatar bast <[email protected]>2021-05-30 16:14:12 -0700
commit7a5a0321d8638d22d58112d8976d18fb07d7ce4e (patch)
tree8717dbd892d4f1e4693aa75b72c76bcc555aa00e /pydis_site/apps/api/tests
parentFix bot/infractions after and before filter check being inverted (diff)
Ensure bot/infractions does not accept both expires and permanent filters
Expires and permanent=false are permitted and tested for. Expires_before also filters the database for permanent=false explicitly
Diffstat (limited to 'pydis_site/apps/api/tests')
-rw-r--r--pydis_site/apps/api/tests/test_infractions.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/pydis_site/apps/api/tests/test_infractions.py b/pydis_site/apps/api/tests/test_infractions.py
index d717ab48..967698ff 100644
--- a/pydis_site/apps/api/tests/test_infractions.py
+++ b/pydis_site/apps/api/tests/test_infractions.py
@@ -204,6 +204,35 @@ class InfractionTests(APISubdomainTestCase):
self.assertIn("expires_before", errors)
self.assertIn("expires_after", errors)
+ def test_permanent_after_invalid(self):
+ url = reverse('bot:infraction-list', host='api')
+ target_time = datetime.datetime.utcnow() + datetime.timedelta(hours=5)
+ response = self.client.get(f'{url}?permanent=true&expires_after={target_time.isoformat()}')
+
+ self.assertEqual(response.status_code, 400)
+ errors = list(response.json())
+ self.assertEqual("permanent", errors[0])
+
+ def test_permanent_before_invalid(self):
+ url = reverse('bot:infraction-list', host='api')
+ target_time = datetime.datetime.utcnow() + datetime.timedelta(hours=5)
+ response = self.client.get(f'{url}?permanent=true&expires_before={target_time.isoformat()}')
+
+ self.assertEqual(response.status_code, 400)
+ errors = list(response.json())
+ self.assertEqual("permanent", errors[0])
+
+ def test_nonpermanent_before(self):
+ url = reverse('bot:infraction-list', host='api')
+ target_time = datetime.datetime.utcnow() + datetime.timedelta(hours=6)
+ response = self.client.get(
+ f'{url}?permanent=false&expires_before={target_time.isoformat()}'
+ )
+
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(len(response.json()), 1)
+ self.assertEqual(response.json()[0]["id"], self.superstar_expires_soon.id)
+
def test_filter_manytypes(self):
url = reverse('bot:infraction-list', host='api')
response = self.client.get(f'{url}?types=mute,ban')