diff options
author | 2021-06-27 16:12:07 +0800 | |
---|---|---|
committer | 2021-06-27 16:12:07 +0800 | |
commit | cc59fc79b6e4fe23b5630577e492a1fb0ef08852 (patch) | |
tree | dd1d389ba271371d6a3143dc80426b5f680407e5 /pydis_site/apps/api/tests | |
parent | Address review comments. (diff) | |
parent | Merge pull request #536 from bast0006/fix-nitro-message (diff) |
Merge branch 'main' into move-config-docs-to-contributing-guide
Diffstat (limited to 'pydis_site/apps/api/tests')
-rw-r--r-- | pydis_site/apps/api/tests/test_models.py | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/pydis_site/apps/api/tests/test_models.py b/pydis_site/apps/api/tests/test_models.py index 66052e01..5c9ddea4 100644 --- a/pydis_site/apps/api/tests/test_models.py +++ b/pydis_site/apps/api/tests/test_models.py @@ -1,6 +1,7 @@ from datetime import datetime as dt -from django.test import SimpleTestCase +from django.core.exceptions import ValidationError +from django.test import SimpleTestCase, TestCase from django.utils import timezone from pydis_site.apps.api.models import ( @@ -34,6 +35,43 @@ class ReprMixinTests(SimpleTestCase): self.assertEqual(repr(self.klass), expected) +class NitroMessageLengthTest(TestCase): + def setUp(self): + self.user = User.objects.create(id=50, name='bill', discriminator=5) + self.context = MessageDeletionContext.objects.create( + id=50, + actor=self.user, + creation=dt.utcnow() + ) + + def test_create(self): + message = DeletedMessage( + id=46, + author=self.user, + channel_id=666, + content="w"*4000, + deletion_context=self.context, + embeds=[] + ) + + try: + message.clean_fields() + except Exception as e: # pragma: no cover + self.fail(f"Creation of message of length 3950 failed with: {e}") + + def test_create_failure(self): + message = DeletedMessage( + id=47, + author=self.user, + channel_id=666, + content="w"*4001, + deletion_context=self.context, + embeds=[] + ) + + self.assertRaisesRegex(ValidationError, "content':", message.clean_fields) + + class StringDunderMethodTests(SimpleTestCase): def setUp(self): self.nomination = Nomination( |