diff options
| author | 2021-05-22 12:57:18 -0700 | |
|---|---|---|
| committer | 2021-05-22 12:57:18 -0700 | |
| commit | f53e275e42161b2cf3df49dd6171831edae1db1e (patch) | |
| tree | ac38f8ff3e922afa718b5cd25f56b5b07235833e | |
| parent | Add tests for new filters on bot/infractions endpoint (diff) | |
Add a test for ordering infractions returned from the api
As this is used in the new bot infraction rescheduler
Diffstat (limited to '')
| -rw-r--r-- | pydis_site/apps/api/tests/test_infractions.py | 30 | 
1 files changed, 25 insertions, 5 deletions
| diff --git a/pydis_site/apps/api/tests/test_infractions.py b/pydis_site/apps/api/tests/test_infractions.py index 16c4d294..fe51307d 100644 --- a/pydis_site/apps/api/tests/test_infractions.py +++ b/pydis_site/apps/api/tests/test_infractions.py @@ -81,6 +81,14 @@ class InfractionTests(APISubdomainTestCase):              active=True,              expires_at=datetime.datetime.utcnow() + datetime.timedelta(hours=5)          ) +        cls.voiceban_expires_later = Infraction.objects.create( +            user_id=cls.user.id, +            actor_id=cls.user.id, +            type='voice_ban', +            reason='Jet engine mic', +            active=True, +            expires_at=datetime.datetime.utcnow() + datetime.timedelta(days=5) +        )      def test_list_all(self):          """Tests the list-view, which should be ordered by inserted_at (newest first).""" @@ -90,11 +98,12 @@ class InfractionTests(APISubdomainTestCase):          self.assertEqual(response.status_code, 200)          infractions = response.json() -        self.assertEqual(len(infractions), 4) -        self.assertEqual(infractions[0]['id'], self.superstar_expires_soon.id) -        self.assertEqual(infractions[1]['id'], self.mute_permanent.id) -        self.assertEqual(infractions[2]['id'], self.ban_inactive.id) -        self.assertEqual(infractions[3]['id'], self.ban_hidden.id) +        self.assertEqual(len(infractions), 5) +        self.assertEqual(infractions[0]['id'], self.voiceban_expires_later.id) +        self.assertEqual(infractions[1]['id'], self.superstar_expires_soon.id) +        self.assertEqual(infractions[2]['id'], self.mute_permanent.id) +        self.assertEqual(infractions[3]['id'], self.ban_inactive.id) +        self.assertEqual(infractions[4]['id'], self.ban_hidden.id)      def test_filter_search(self):          url = reverse('bot:infraction-list', host='api') @@ -162,6 +171,17 @@ class InfractionTests(APISubdomainTestCase):          infractions = response.json()          self.assertEqual(len(infractions), 3) +    def test_sort_expiresby(self): +        url = reverse('bot:infraction-list', host='api') +        response = self.client.get(f'{url}?ordering=expires_at&permanent=false') +        self.assertEqual(response.status_code, 200) +        infractions = response.json() + +        self.assertEqual(len(infractions), 3) +        self.assertEqual(infractions[0]['id'], self.superstar_expires_soon.id) +        self.assertEqual(infractions[1]['id'], self.voiceban_expires_later.id) +        self.assertEqual(infractions[2]['id'], self.ban_hidden.id) +      def test_returns_empty_for_no_match(self):          url = reverse('bot:infraction-list', host='api')          response = self.client.get(f'{url}?type=ban&search=poop') | 
